PPM reconstruction

PPM reconstruction#

PPMpy provides modules that support a finite-volume discretization on a 1D grid and the ability to reconstruct the cell-average data as parabolas, following the procedure in the original PPM paper (Colella & Woodward 1984).

import numpy as np
import matplotlib.pyplot as plt

FVGrid provides a simple 1D finite-volume grid class. It provides the coordinates for the cells and can create a scratch array defined on the grid. It also knows how to fill ghost cells and compute the norm of the data on the grid. Finally, it includes some methods that allow us to plot the grid.

from ppmpy import FVGrid

An example grid with 4 cells + 3 ghost cells

g = FVGrid(4, 3)
gp = g.draw()
_images/9f0ad8f2439b03bce7c135b590717094a7b1a31e5ea20a1003fdecff3f570bb3.png

Let’s create data on the grid (including the ghost cells) and visualize the PPM reconstruction.

a = g.scratch_array()
a[:] = [0.3, 1.0, 0.9, 0.8, 0.25, 0.1, 0.5, 0.55, 0.25, 0.1]
a
array([0.3 , 1.  , 0.9 , 0.8 , 0.25, 0.1 , 0.5 , 0.55, 0.25, 0.1 ])

PPMInterpolant manages the PPM reconstruction of the data.

from ppmpy import PPMInterpolant
ppm = PPMInterpolant(g, a)
ppm.construct_parabola()

We can now visualize the PPM reconstruction of the data

ppm.draw_parabola(gp)
ppm.mark_cubic(gp)
gp.show_fig()
_images/f1dae246bf66da2a2225516e2e722b1931288c4866c58f50d6ad3ec80018bc20.png

For comparison, we can look at the unlimited case:

ppm = PPMInterpolant(g, a, limit=False)
ppm.construct_parabola()
gp2 = g.draw()
ppm.draw_parabola(gp2)
ppm.mark_cubic(gp2)
_images/cf58664750042d09c8dd3f62f7b6d4ca1903b106c89eca03f033760d4a26b035.png

Finally, we can also plot just a portion of the grid:

gp3 = g.draw(hi_index=4)
ppm.draw_parabola(gp3)
ppm.mark_cubic(gp3)
_images/87393eb53714e0dce82dc9dc244508ae57ee78535375346426c6a64eb8c37607.png