hydro by example


A simple python-based tutorial on computational methods for hydrodynamics

intro

design

grids

advection

compressible

multigrid

diffusion

incompressible

low Mach

 | 

analysis

 | 

download

∗ Multigrid

pyro solves elliptic problems (like Laplace's equation or Poisson's equation) through multigrid. This accelerates the convergence of simple relaxation by moving the solution down and up through a series of grids. Chapter 8 of the notes describe the basics of multigrid:

notes on computational hydro

There are three solvers:

We simply use V-cycles in our implementation, and restrict ourselves to square grids with zoning a power of 2.

The multigrid solver is not controlled through pyro.py since there is no time-dependence in pure elliptic problems. Instead, there are a few scripts in the multigrid/ subdirectory that demonstrate its use.

∗ Examples

multigrid test

A basic multigrid test is run as:

./mg_test_simple.py

The mg_test_simple.py script solves a Poisson equation with a known analytic solution. This particular example comes from the text "A Multigrid Tutorial, 2nd Ed.". The example is:

uxx + uyy = -2 [(1-6x2)y2(1-y2) + (1-6y2)x2(1-x2)]
on [0,1] × [0,1] with u = 0 on the boundary.

The solution to this is shown below.

Since this has a known analytic solution:

u(x,y) = (x2 - x4)(y4 - y2)

We can assess the convergence of our solver by running at a variety of resolutions and computing the norm of the error with respect to the analytic solution. This is shown below:

The dotted line is 2nd order convergence, which we match perfectly.

The movie below shows the smoothing at each level to realize this solution:

projection

Another example that uses multigrid to extract the divergence free part of a velocity field is run as:

./project-periodic.py

Given a vector field, U, we can decompose it into a divergence free part, Ud, and the gradient of a scalar, φ:

U = Ud + ∇ φ

We can project out the divergence free part by taking the divergence, leading to an elliptic equation:

2 φ = ∇ · U

The project-periodic.py script starts with a divergence free velocity field, adds to it the gradient of a scalar, and then projects it to recover the divergence free part. The error can found by comparing the original velocity field to the recovered field. The results are shown below:

Left is the original u velocity, middle is the modified field after adding the gradient of the scalar, and right is the recovered field.

Jupyter Notebook

A jupyter notebook showing how to use the basic solver can be found here: multigrid-examples.ipynb

∗ Exercises

Explorations

Extensions