Assignment 3

Table of Contents

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:

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 A is discretized using sampling points (particles) j as:

A(x)=jAjmjρjW(xxj,h)

Where m is mass, ρ is density, and W is the kernel function. For density itself, the equation simplifies to:

ρ(x)=jmjW(xxj,h)

You can use this cubic spline kernel:

W(r,h)=407πh2{6(q3q2)+1for 0q<122(1q)3for 12q<10otherwise

These equations match what you implemented in problem set 3.

2.2 Pressure Computation

In WCSPH, pressure for particle i is directly computed from density:

pi=B((ρiρ0)γ1)

, where ρ0 is the default density, γ and B are constants. When γ=1, it is actually the pressure for ideal gas. To simulate fluids with high resistance to compresssion (like water), we use γ = 7 in our assignment.

2.3 Acceleration Computation

From the Navier-Stokes equations for a fluid without viscosity:

DuDt+1ρp=g

To calculate acceleration and update velocity, we need the pressure gradient. For particle i, this is:

pi=ρijmj(piρi2+pjρj2)iWi,j

, where iWi,j=W(xixj,h)xi. (You might notice that the gradient of pressure here is different from A in problem set 3. See here if you want to know more.)

Substituting back into the N-S equation gives the acceleration:

d2xidt2=jmj(piρi2+pjρj2)iWi,j+g

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 ρ0 and pressure 0. These particles contribute to pressure and density calculations for fluid particles, pushing them away from boundaries. Three layers of boundary particles ensure that the full kernel support will be covered near boundaries.

2.5 Artificial Viscosity

To improve numerical stability, we add artificial viscosity:

aviscosityi={jmjΠi,jiWi,jvi,jTxi,j<00vi,jTxi,j0

Where v=dxdt is velcocity, vi,j=vivj, xi,j=xixj, and Πi,j is given as:

Πi,j=2αhcsρi+ρjvi,jTxi,jxi,j2+ϵh

, where α is the viscosity constant (we use 0.8 in our code). ϵ=0.01 is introduced to avoid singularity when xi,j is too small.

The final acceleration for particle i is:

d2xidt2=jmj(piρi2+pjρj2)iWi,j+g+aviscosity

3 Interactive Controls

4 Debugging Tips

5 Submission

You need to include the following in your submission:

  1. 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.
  2. A demo video demonstrating the functionality of your simulation.

6 References