← All projects
Numerical analysis class project · Spring 2024 · Duke

Using Gauss-Seidel for a Basic CFD

Dadmehr Ghasemfar and Derrick Roseman

Computational Fluid Dynamics (CFD) is widely applied in industries such as aerospace, automotive, energy, and environmental engineering to optimize designs, predict performance, and understand complex flow phenomena without the need for physical prototypes. However, CFD simulations can be very computationally expensive and time-consuming. This is where the Fast Fluid Dynamics (FFD) algorithm comes in. We derive the fundamental equations for fluid mechanics, explain the working principle of the FFD algorithm, and then demonstrate it in a simple program. To simplify the task, we only model incompressible and inviscid flow.

The final result at different times. The simulation captures vortex shedding behind a cylinder.
The final result at different times. The simulation captures vortex shedding behind a cylinder.

Mathematical Background

There are two fundamental ways to mathematically model fluids. The Eulerian perspective examines a fixed region in space and looks at the fluid entering and leaving. The Lagrangian perspective examines a volume of fluid, tracking it as it moves in space. In simulation, a Lagrangian method corresponds to a particle based simulation while an Eulerian method corresponds to an FEA-style cell-by-cell simulation. We focus on the Eulerian perspective.

Traditional partial time derivatives do not accurately model vector field changes with respect to time, because the vector field itself also moves along the flow. This process is called advection, and to account for it the partial derivative is extended to the material derivative. From there, conservation of mass and momentum give the Navier-Stokes equations.

Irrotational and incompressible flow fields
An irrotational flow field and an incompressible flow field.

Fast Fluid Dynamics Algorithm

Our implementation of the FFD algorithm was created by Jos Stam in his publication titled Stable Fluids. His background is in computer graphics, and his task was to accelerate simple flow CFD for use in animation and video games. His algorithm takes a vector field at time t and returns the updated vector field at time t+1.

First, all of the external forces are added to the fluid. In our simulation, the only force is gravity. Second, all fluid elements are advected forward one time step, using the velocity of the element that currently ends up at each point and linear interpolation between grid points. The third step captures viscosity, and since we assume inviscid flow, it is ignored. The fourth step, projection, is the most important for this project. It forces incompressibility by removing the divergence of the vector field, which turns into a classic Poisson equation.

Implementation and Gauss-Seidel

We solve the projection step with Gauss-Seidel. Over-relaxation is implemented by adding a constant term in front of the calculated divergence. If this constant is chosen between one and two, convergence is sped up significantly, and in our code values of 1.7 to 1.8 work best. All boundary and obstacle velocities are forced to zero, which is called the no-slip and no-penetration boundary condition.

Gauss-Seidel update equations for the projection step
The projection update, where d is the divergence at (i, j) and s counts the neighboring fluid elements.

Results

After implementing the algorithm, we first got results that were clearly not correct, due to indexing bugs from using a collocated grid and a staggered grid, as well as incorrect physical and temporal resolutions. After lots of troubleshooting, we finally got a result that makes sense. The complex phenomenon known as vortex shedding is captured, where alternating vortices form in the wake of a cylinder.

Screenshots of a failed test
A failed test.

Although the simulation captured vortex shedding, it did not accurately represent the fluid boundary layer. Since the boundary layer is extremely thin, it does not affect the accuracy of the rest of the simulation. Lastly, the simulation was fast. Compared to typical CFD software that can take days, weeks, or even months, this FFD simulation took mere seconds to run.

Conclusion

This FFD algorithm has the necessary accuracy and speed to be more useful than standard CFD software in applications where speed is required. Further work can account for viscous and compressibility effects, extend the domain to three dimensions, and apply the algorithm to other shapes such as airfoils.