Disclosure: The material in this repository has not been reviewed, endorsed, or approved of by the Rust Foundation. For more information see the Rust Foundation Trademark Policy 2023.
A small demo project to learn Rust by implementing an Eulerian fluid simulation. This project has been inspired by TenMinutesPhysics. The basics are easy to understand, but as always "the dog is buried in the details" as we phrase it in German. Its probably a fact in the field of scientific simulation that most boilerplate code is there to deal with the beautiful (😨) boundaries of your simulation domain, data structures etc.
The simulation is implemented with the same procedure as as in fluid.sim with some additional data structures and better encapsulation to support the computation.
The CLI simulator is in src/main.rs which sets up the scene with a grid and hands it over to the timestepper which is responsible to integrate the grid. Disclaimer: This design is not yet perfect but it was more to play around with the different concepts in Rust.
You can start the simulation with
cargo run --release --bin rsfluid -- -e 10.0 -t "$timestep" --incompress-iters 100 --dim "400,200"
or
just run --release --bin rsfluid -- -e 10.0 -t "$timestep" --incompress-iters 100 --dim "400,200"
To install cargo
use
this help here.
To create the video with 30
frames use:
./tools/create-video.sh 30
or
just video 30
To implement the parallel version of
solve_incompressibility
I needed to split
grid.cells
successively into parts with an iterator chain until ending up with
an iterator which produces stencils in the form
PosStencilMut<Cell>
. This iterator can be
converted to a parallel iterator by replacing the iterator chain with the
parallel functions from rayon
.
The following picture illustrates the topology:
The parallel version with ./create-video.sh 30 --parallel
is currently much
slower than the serial one. The parallelization is probably to fine grained to
be efficient and the Cell
driven layout is probably not that good for cache
friendliness.