PyMPDATA_examples

Introduction

PyMPDATA examples are bundled with PyMPDATA and located in the examples subfolder. They constitute a separate PyMPDATA_examples Python package which is also available at PyPI. The examples have additional dependencies listed in PyMPDATA_examples package setup.py file. Running the examples requires the PyMPDATA_examples package to be installed.

We recommend you look through the example gallery below to see the examples in action.

Example gallery

Unless stated otherwise the following examples solve the basic advection equation: $$ \partial_t (\psi) + \nabla \cdot (u \psi) = 0 $$

The examples are grouped by the dimensionality of the computational grid.

in 1D

tags link
advection-diffusion equation
$$ \partial_t (\psi) + \nabla \cdot (u \psi) + \mu \Delta (\psi) = 0 $$
PyMPDATA_examples.advection_diffusion_1d*
Black-Scholes equation, option pricing
$$ \frac{\partial f}{\partial t} + rS \frac{\partial f}{\partial S} + \frac{\sigma^2}{2} S^2 \frac{\partial^2 f}{\partial S^2} - rf = 0$$
PyMPDATA_examples.Arabas_and_Farhat_2020*
advection equation, homogeneous, several algorithm variants comparison: infinite-gauge, flux-corrected,.. PyMPDATA_examples.Smolarkiewicz_2006_Figs_3_4_10_11_12
Size-spectral advection, particle population condensational growth, coordinate transformation
$$ \partial_t (G \psi) + \nabla \cdot (Gu \psi) = 0 $$
PyMPDATA_examples.Olesik_et_al_2022*
advection equation, double-pass donor-cell option PyMPDATA_examples.DPDC

in 2D

tags link
advection-diffusion equation
$$ \partial_t (\psi) + \nabla \cdot (u \psi) + \mu \Delta (\psi) = 0 $$
PyMPDATA_examples.advection_diffusion_2d*
adv-diff
Spectral-spatial advection, particle population condensational growth in a vertical column of air, time dependent flow PyMPDATA_examples.Shipway_and_Hill_2012
spectral-spatial
shallow-water equations
$$\begin{eqnarray} \partial_t h + \partial_x (uh) + \partial_y (vh) &=& 0~ \\ \partial_t (uh) + \partial_x ( uuh) + \partial_y (vuh) &=& - h \partial_x h~ \\ \partial_t (vh) + \partial_x ( uvh) + \partial_y (vvh) &=& - h \partial_y h~ \end{eqnarray}$$
PyMPDATA_examples.Jarecka_et_al_2015*
advection equation, solid body rotation PyMPDATA_examples.Molenkamp_test_as_in_Jaruga_et_al_2015_Fig_12*
advection equation, coordinate transformation, spherical coordinates, see also examples in PyMPDATA-MPI $$ \partial_t (G \psi) + \nabla \cdot (Gu \psi) = 0 $$ PyMPDATA_examples.Williamson_and_Rasch_1989_as_in_Jaruga_et_al_2015_Fig_14
mpi-gif
advection equation, comparison against DG solution using Trixi.jl PyMPDATA_examples.trixi_comparison

in 3D

tags link
homogeneous advection equation PyMPDATA_examples.Smolarkiewicz_1984
homogeneous advection equation, performance comparison against libmpdata++, scalability analysis in respect to threads PyMPDATA_examples.Bartman_et_al_2022

* - with comparison against analytic solution

Installation

Since the examples package includes Jupyter notebooks (and their execution requires write access), the suggested install and launch steps are:

git clone https://github.com/open-atmos/PyMPDATA-examples.git
cd PyMPDATA-examples
pip install -e .
jupyter-notebook

Alternatively, one can also install the examples package from pypi.org by using

pip install PyMPDATA-examples.
 1"""
 2.. include:: ../docs/pympdata_examples_landing.md
 3"""
 4
 5from importlib.metadata import PackageNotFoundError, version
 6
 7try:
 8    __version__ = version(__name__)
 9except PackageNotFoundError:
10    # package is not installed
11    pass