Skip to main content

A CFD python package for the shallow water equations

Project description


A CFD python package for the shallow water equations.

MattFlow simulates the surface of the water after any initial conditions, such as drops or stones falling on.

requirements os
python 3 GNU/Linux
numpy >= 1.16.4 Windows
matplotlib >= 3.1.1
jpblib >= 0.13.2
ffmpeg (optional)

How to install & run MattFlow

  1. anaconda environment (recommended)
$ conda create --name mattflow python=3 matplotlib
$ conda activate mattflow
$ pip install mattflow
$ mattflow
  1. venv (python>=3.3)
$ python3 -m venv mattflow_env
$ source mattflow_env/bin/activate
$ pip install mattflow
$ mattflow
  1. pip
$ pip install --user mattflow joblib
$ mattflow

Swallow Water Equations

SWE is a simpified CFD problem which models the surface of the water, with the assumption that the horizontal length scale is much greater than the vertical length scale.

SWE is a coupled system of 3 hyperbolic partial differential equations, that derive from the conservation of mass and the conservation of linear momentum (Navier-Stokes) equations, in case of a horizontal stream bed, with no Coriolis, frictional or viscours forces (wiki).

{\displaystyle {\begin{aligned}{\frac {\partial (\rho \eta )}{\partial t}}&+{\frac {\partial (\rho \eta u)}{\partial x}}+{\frac {\partial (\rho \eta v)}{\partial y}}=0,\\[3pt]{\frac {\partial (\rho \eta u)}{\partial t}}&+{\frac {\partial }{\partial x}}\left(\rho \eta u^{2}+{\frac {1}{2}}\rho g\eta ^{2}\right)+{\frac {\partial (\rho \eta uv)}{\partial y}}=0,\\[3pt]{\frac {\partial (\rho \eta v)}{\partial t}}&+{\frac {\partial (\rho \eta uv)}{\partial x}}+{\frac {\partial }{\partial y}}\left(\rho \eta v^{2}+{\frac {1}{2}}\rho g\eta ^{2}\right)=0.\end{aligned}}}

where: η : height u : velocity along the x axis υ : velocity along the y axis ρ : density g : gravity acceleration

MattFlow structure

More details at this jupyter notebook

  1. configuration of the simulation via a config file
  2. pre-process structured/cartesian mesh
  3. solution supported solvers:
    • Lax-Friedrichs Riemann    | O(Δt, Δx2, Δy2)
    • 2-stage Runge-Kutta         | O(Δt2, Δx2, Δy2)  | default
    • MacCormack           | O(Δt2, Δx2, Δy2)  | experimental
  4. post-processing matplotlib animation

Additional configurations

  • mesh sizing
  • domain sizing
  • initial conditions (single drop, multiple drops, rain)
  • boundary conditions (currently: reflective)
  • solver
  • multiprocessing
  • plotting style
  • animation options

Currently, you can configure the simulation at the config module


  1. coverage hooks
  2. API
  3. Numba
  4. Higher order schemes
  5. Addition of source terms
  6. Addition of viscous models
  7. Algorithm that converts every computational second to a real-time second, playing with the fps at the post-processing timelapse, because each iteration uses different time-step (CFL condition)
  8. Moving core to C++ or Cython?
  9. Moving objects inside the domain
  10. Unstructured mesh
  11. Extent to 3D CFD

Start the flow!

(C) 2019, Thanasis Mattas

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mattflow, version 1.1.1
Filename, size File type Python version Upload date Hashes
Filename, size mattflow-1.1.1-py3-none-any.whl (36.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size mattflow-1.1.1.tar.gz (19.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page