This package solves the inviscit, incompressible Navier Stokes equations in 2 or 3 (or any other) dimensions.
fluid_sim_demo.mp4
In a julia terminal, run the following commands to install this package:
using Pkg
Pkg.add(url="https://github.com/Alexander-Barth/FluidSimDemo.jl")
Then run the examples/fluid_sim_demo.jl.
The evolution equation of the velocity
where
The flow is subjected to the following incompressibility constraint:
These equations are solved in this different steps:
- Apply external forces
$\mathbf g$ (in particular gravity)
Impose on boundaries
- Advection of velocity field
$\mathbf {u''}^{(n)}$ . The combined force of inertia and external forces acting from$n-1$ to$n$ are written as$\mathbf F$ :
- The pressure is computed by requiring that the divergence of velocity must remain zero:
which leads to:
Note that it is not necessary to compute
Choose pessure such that:
The pressure is solved iteratively (using Gauss-Seidel with overrelaxation) with a fixed number of iterations. In the following algorithm
The time index
Compute pressure adjustement by:
Adjust the pressure
Update the velocity accordingly
After convergence, the velocity
The inviscid 2D shallow-water equations (derived from the Navier-Stokes equations) allow to compute the surface elevation η, and the u and v velocity components:
where h(x,y) is the depth of the water column, f is the Coriolis parameter and g is the acceleration due to gravity. Currently in the continuity equation (first equation), η (often in the order of 100 m) is neglected in front of η (order of cm).
The julia code is implemented using a subset of julia that can be compiled to WebAssembly.
The 2D Navier Stokes is based on the compact implementation of Matthias Müller (which has been reimplemented in julia and extended in N-dimensions).