Code Monkey home page Code Monkey logo

simplenssolver's Introduction

Simple Navier-Stokes Solver

License LastCommit

CI DOC

https://github.com/NaokiHori/SimpleNSSolver/blob/main/docs/source/thumbnail.gif

https://github.com/NaokiHori/SimpleNSSolver/blob/main/docs/source/snapshot3d.png

Overview

This library numerically solves the incompressible Navier-Stokes equations (coupled with a temperature field) in two- and three-dimensional Cartesian domains using the finite-difference method.

The main objective is to develop a library where the implementation and the background knowledge are closely linked via a documentation and various examples, so that users can understand how and why things are treated.

Features

  • An energy-consistent treatment of advective, pressure-gradient, and diffusive terms, correctly replicating properties of the conservation laws.
  • MPI parallelisation.
  • Efficient FFT-based direct Poisson solver.
  • Explicit / implicit treatments of diffusive terms in all spatial directions.

Please refer to the documentation for details.

Dependency

Ubuntu

It should be convenient to use a proper package manager, e.g.:

sudo apt-get -y update
sudo apt-get -y install gcc libopenmpi-dev libfftw3-dev make

Also install Python3.

MacOS

Installation of the Command Line Tools for Xcode is usually required, which is followed by

brew install gcc open-mpi fftw make

Also install Python3.

Windows

Not supported. Please consider to use Windows Subsystem for Linux for instance.

Quick start

Pre-processing

  1. Prepare workplace

    mkdir -p /path/to/your/directory
    cd       /path/to/your/directory
  2. Get source

    git clone --recurse-submodules https://github.com/NaokiHori/SimpleNSSolver
    cd SimpleNSSolver
  3. Set initial condition

    Here Python3 is used to initialise the flow fields conveniently. One can give NPY files in different way under initial_condition/output/.

    cd initial_condition
    make output
    bash exec.sh
    cd ..
  4. Build NS solver

    make output
    make all

Main

bash exec.sh

launches the simulator and integrate the equations in time, giving e.g.

DOMAIN
   glsizes[0]: 128
   glsizes[1]: 256
   lengths[0]:  1.0000000e+00
   lengths[1]:  2.0000000e+00
FLUID
   Ra:  1.0000000e+08
   Pr:  1.0000000e+01
   Momentum    diffusivity:  3.1622777e-04
   Temperature diffusivity:  3.1622777e-05
   diffusive treatment in x: implicit
   diffusive treatment in y: explicit
LOGGING
   next:  5.000e-01
   rate:  5.000e-01
SAVE
   dest: output/save/step
   next:  2.000e+01
   rate:  2.000e+01
STATISTICS
   dest: output/stat/step
   next:  1.000e+02
   rate:  1.000e-01
step: 0, time:  0.0000000e+00
timemax:  2.0000000e+02, wtimemax:  6.0000000e+02
coefs: (adv)  9.500e-01, (dif)  9.500e-01
DFT-based solver is used
step   11, time   0.5, dt 4.58e-02, elapsed  2.1 [sec]
step   22, time   1.0, dt 4.58e-02, elapsed  2.2 [sec]
step   33, time   1.5, dt 4.58e-02, elapsed  2.3 [sec]
step   44, time   2.0, dt 4.58e-02, elapsed  2.4 [sec]
step   55, time   2.5, dt 4.58e-02, elapsed  2.4 [sec]
...
step 8193, time 197.5, dt 3.06e-02, elapsed 91.9 [sec]
step 8210, time 198.0, dt 2.79e-02, elapsed 92.2 [sec]
step 8228, time 198.5, dt 2.79e-02, elapsed 92.5 [sec]
step 8246, time 199.0, dt 2.90e-02, elapsed 93.0 [sec]
step 8263, time 199.5, dt 3.07e-02, elapsed 93.2 [sec]

You see that the solver (e.g. DOMAIN and FLUID) is initialised and parameters are loaded from the NPY files prepared in the previous step, which is followed by the integration of the equations in time.

Post-processing

Several log files, snapshots of the flow fields (which are used to restart the simulation and to process the flow fields later), and collected statistics are stored in output directory:

output
├── log
│  ├── xxxxx.dat
│  ├── yyyyy.dat
...
│  └── zzzzz.dat
├── save
│  ├── step00000xxxxx
│  ├── step00000yyyyy
...
│  └── step00000zzzzz
└── stat
   └── step00000zzzzz

Log files (files under output/log directory) are written in ASCII format, which are to monitor the progress.

For example, since I adopt the FFT-based Poisson solver in this project, local divergence of the flow field should be small enough, which is written in output/log/max_divergence.dat:

https://raw.githubusercontent.com/NaokiHori/SimpleNSSolver/artifacts/artifacts/typical-2d/divergence.png

Energy injections and dissipations are also monitored, from which the Nusselt number (computed based on several different definitions) can be extracted:

https://raw.githubusercontent.com/NaokiHori/SimpleNSSolver/artifacts/artifacts/typical-2d/nusselt_time.png

Flow fields and statistical data are stored in NPY format using SimpleNpyIO. When Python3 with NumPy and Matplotlib is installed, one can easily visualise the flow fields:

https://raw.githubusercontent.com/NaokiHori/SimpleNSSolver/artifacts/artifacts/typical-2d/snapshot.png

or statistics (e.g., mean advective and diffusive heat transfer):

https://raw.githubusercontent.com/NaokiHori/SimpleNSSolver/artifacts/artifacts/typical-2d/nusselt_x.png

Note that all the results shown here are automatically updated to maintain / improve the code quality, and all scripts to produce the above figures are available in the examples. See the documentation for more details.

3D simulation

By default, this project simulates two-dimensional cases because they are easy to test and thus can be a good starting point. When a three-dimensional version is needed, checkout 3d branch. Note that the main branch contains both dimensions, which is to maintain both cases at the same time (mainly for personal use).

Please refer to the examples, where several small-scale 3D simulations are attempted as a part of the continuous integration.

https://raw.githubusercontent.com/NaokiHori/SimpleNSSolver/artifacts/artifacts/typical-3d/snapshot.png

Contributing

Feel free to ask questions, report bugs, suggest new features, polish documentation at issues.

Acknowledgements

The development of this CFD solver is largely motivated by CaNS and AFiD.

I would like to thank Dr. Pedro Costa, Dr. Marco Rosti and Dr. Chris Howland, among others, for fruitful discussions during my time at KTH Royal Institute of Technology in Stockholm, the University of Tokyo and University of Twente.

simplenssolver's People

Contributors

naokihori avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.