This library numerically solves the incompressible Navier-Stokes equations with a scalar field in two- and three-dimensional Cartesian domains using the spectral method. It was developed as a self-study project to explore the differences between finite-difference methods and spectral methods.
- Fourier-Galerkin method
- Orszag–Patterson algorithm
- 2/3 de-aliasing
- Pencil-based MPI parallelization for scaling up to 10⁴ processes
- Fourth-order Runge-Kutta method (for nonlinear terms) combined with the integrating-factor technique (for linear terms) for temporal integration
Refer to the documentation for details (currently under construction).
To easily initialize the flow field, it is recommended to use:
-
Set up your workspace
mkdir -p /path/to/your/directory cd /path/to/your/directory
-
Clone the repository
git clone --recurse-submodules https://github.com/NaokiHori/SpectralNSSolver1 cd SpectralNSSolver1
-
Set the initial condition
The velocity field must be solenoidal, while the scalar field can be arbitrary.
main.py
provides several example initial conditions.cd initial_condition python3 main.py 0 cd ..
-
Build the solver
make clean make output make all
-
Run the simulation
Execution parameters are defined in
exec.sh
.bash exec.sh
The runtime depends on your system specifications.
-
Output and Visualization
The flow fields are stored in
output/save/
as NPY files. These velocities are in the spectral domain, so an inverse Fourier transform (with normalization) is needed to obtain physical velocities.If the necessary Python libraries are installed, you can visualize the results with:
python3 visualise/2d.py
To run a 3D simulation, switch to the 3d
branch and recompile all source files. You will also need to regenerate the initial flow field.
- Canuto et al., Spectral Methods - Fundamentals in Single Domains, Springer
- Canuto et al., Spectral Methods - Evolution to Complex Geometries and Applications to Fluid Dynamics, Springer
I would like to thank Dr. Chris Howland for valuable discussions.