hydro by example

A simple python-based tutorial on computational methods for hydrodynamics









low Mach





∗ Finite-volume discretization

All solvers are based on a finite-volume/cell-centered discretization. The basic theory of such methods is discussed in Chapter 2 of the notes:

notes on computational hydro

mesh.patch implementation and use

We import the basic mesh functionality as:

import mesh.patch as patch
import mesh.boundary as bnd
import mesh.array_indexer as ai

There are 4 main objects in the patch class that we interact with:

The procedure for setting up a grid and the data that lives on it is as follows:
myg = patch.Grid2d(16,32, xmax=1.0, ymax=2.0)
This creates the 2-d grid object myg with 16 zones in the x-direction and 32 zones in the y-direction. It also specifies the physical coordinate of the rightmost edge in x and y.
mydata = patch.CellCenterData2d(myg)

bc = bnd.BC(xlb="periodic", xrb="periodic", ylb="reflect-even", yrb="outflow")

mydata.register_var("a", bc)
This creates the cell-centered data object, mydata that lives on the grid we just built above. Next we create a boundary condition object, specifying the type of boundary conditions for each edge of the domain, and finally use this to register a variable, "a" that lives on the grid. Once we call the create() method, the storage for the variables is allocated and we can no longer add variables to the grid.

Note that each variable needs to specify a BC—this allows us to do different actions for each variable (for example, some may do even reflection while others may do odd reflection).

print mydata
This prints out some basic info about the data stored in the mydata object. The output is below:
cc data: nx = 16, ny = 32, ng = 1
         nvars = 1
                     a: min:    0.0000000000    max:    0.0000000000
                        BCs: -x: periodic     +x: periodic     -y: reflect-even +y: outflow     

Jupyter Notebook

A jupyter notebook that illustrates some of the basics of working with the grid can be found here: mesh-examples.ipynb. This will demonstrate, for example, how to use the ArrayIndexer methods to construct differences.


The actual filling of the boundary conditions is done by the fill_BC() method. The script bc_demo.py tests the various types of boundary conditions by initializing a small grid with sequential data, filling the BCs, and printing out the results.


To see a short description of all the methods and functions provided by patch just type "help(patch)" at the python prompt.