Assignment 3
Table of Contents
- 1 Getting Started
- 2 Implementation Details
- 3 Interactive Controls
- 4 Debugging Tips
- 5 Submission
- 6 References
In this assignment, you will implement a 2D fluid simulation using the Weakly Compressible Smoothed Particle Hydrodynamics (WCSPH) method, using the EUROGRAPHICS 2019 course notes by Koschier et al. as a reference for the details.
1 Getting Started
Pull the latest A3 starter code from: https://github.coecis.cornell.edu/cs5643/assignments-sp25.
Running python3 main.py
will display a GUI with initial
particles.
The framework consists of four files:
main.py
: Simulation loop and GUIscene.py
: Particle position initializationutils.py
: SPH constantstodo.py
: Your implementation code goes here
To record a simulation video, use
python3 main.py --video
. Recording stops when you press the
ESC key, generating both MP4 and GIF files. Here
is the reference video. Note that this video is only for reference, and
your results don’t need to be exactly the same.
2 Implementation Details
2.1 Density Computation
In SPH, a field
Where
You can use this cubic spline kernel:
These equations match what you implemented in problem set 3.
2.2 Pressure Computation
In WCSPH, pressure for particle
, where
2.3 Acceleration Computation
From the Navier-Stokes equations for a fluid without viscosity:
To calculate acceleration and update velocity, we need the pressure
gradient. For particle
, where
Substituting back into the N-S equation gives the acceleration:
2.4 Boundary Conditions
Boundary conditions are always one of the most annoying
interesting parts of fluid simulation. We implement boundaries using
fixed boundary particles with density
2.5 Artificial Viscosity
To improve numerical stability, we add artificial viscosity:
Where
, where
The final acceleration for particle
3 Interactive Controls
- W, A, S, D: Control gravity direction
- E, Q: Rotate barrier particles clockwise/counter-clockwise
4 Debugging Tips
- Make sure density and pressure are computed correctly. Density at
each particle should be close to
, and pressure should not be too large. - Particles are very energetic without viscosity (as shown here).
If you want to see some results or debug before implementing viscosity,
consider use a smaller constant
in pressure computation. (a too small might cause boundary penetration, though) - If particles stick to boundaries or deform in the first few frames,
try setting
5 Submission
You need to include the following in your submission:
- A PDF file including a link to the chosen commit for your
submission. If you submit a link just to your repository, we will assume
that you would like us to look at the latest commit on the
main
branch. - A demo video demonstrating the functionality of your simulation.