Computational Fluid Dynamics in Python


Using NumPy to solve the equations of fluid mechanics  ??? together with Finite Differences, explicit time stepping and Chorin's Projection methods.

You can find more details in the corresponding video which you can also use to code along ?‍?. More scripts like this can be found in this GitHub Repo.

How to use

Make sure you have the relevant packages installed. These pip commands should be sufficient

pip install numpy matplotlib tqdm

Then you can either execute


for a simulation which runs all the way through and in the end plots a contour plot of the (pseudo) pressure with a vector field layed on top. Or you can execute


to get a simulation that plots throughout time. By this you can see how the Lid Driven cavity is reaching its steady-state.


In the beginning of both files, directly after the explaining docstring, you find Python constants to adapt the scenario and the numerics.

Details on the methods

The method is based on the operator splitting due to Chorin. Also see this Wikipedia page for some details.

Big parts of the of the code, including the approach to solve the pressure-poisson equation using Jacobi Smoothing, are inspired by the 11th lesson of Lorena Barba's 12 steps to Navier Stokes.

Also check out the docstring in the beginning of the file for some more details.

GitHub - Ceyron/lid-driven-cavity-python at
Solving the Navier-Stokes Equations in Python ? simply using NumPy. - GitHub - Ceyron/lid-driven-cavity-python at