Skip to content

[WIP] Setting the PPM advection problem #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bb948fb
setting ppm interface reconstruction
aisclark91 Mar 4, 2023
cb1d11b
solving typos
aisclark91 Mar 7, 2023
1e6e661
adding advection_ppm setup
aisclark91 Mar 7, 2023
4d9921c
fixing bugs and lake8 issues
aisclark91 Mar 9, 2023
d595455
adding fluxes
aisclark91 Mar 11, 2023
6e573a7
now ppm is running
aisclark91 Mar 15, 2023
b6b361b
Merge branch 'main' of github.com:python-hydro/pyro2 into ppm
aisclark91 Mar 23, 2023
0fea5aa
solving ppm bugs
aisclark91 Mar 31, 2023
9487f4e
Merge branch 'main' of github.com:python-hydro/pyro2 into ppm
aisclark91 Mar 31, 2023
b0dadaa
init.py
aisclark91 Mar 31, 2023
0a140c1
flake8 issues
aisclark91 Mar 31, 2023
c0c8e33
isort fix
aisclark91 Mar 31, 2023
a1589b2
fixing upwind bugs
aisclark91 Mar 31, 2023
cffeee4
adding changes in the main driver
aisclark91 Mar 31, 2023
cd8a15e
flake8 issues
aisclark91 Mar 31, 2023
7b76afa
reverting changes for solver_test.ipynb
aisclark91 Mar 31, 2023
642c443
isort issue
aisclark91 Mar 31, 2023
cd02206
isort issue
aisclark91 Mar 31, 2023
25714fe
isort again
aisclark91 Mar 31, 2023
d569bc3
Evolving the simulation class from advection.Simulation
aisclark91 Mar 31, 2023
64f84e7
Merge branch 'main' of github.com:python-hydro/pyro2 into ppm
aisclark91 Mar 31, 2023
87f6160
adding solver-test.ipnyb modifications
aisclark91 Mar 31, 2023
615228a
modifying test.py
aisclark91 Apr 1, 2023
7234277
solving pytest issues
aisclark91 Apr 1, 2023
211f8cf
adding metadata
aisclark91 Apr 2, 2023
8b56a93
timing the ppm solver
aisclark91 Apr 7, 2023
fc76036
adding convergence test results
aisclark91 Apr 14, 2023
dd7341d
adding ppm test
aisclark91 Apr 14, 2023
ab7b923
adding compare file
aisclark91 Apr 14, 2023
4d239bb
fixing flake8
aisclark91 Apr 14, 2023
7ff629b
more flake8
aisclark91 Apr 14, 2023
f0b879e
fixing pylint
aisclark91 Apr 14, 2023
5d146b1
Merge branch 'main' into ppm
aisclark91 Apr 14, 2023
8860884
more pylint
aisclark91 Apr 14, 2023
05c0b20
dealing with isort
aisclark91 Apr 14, 2023
3fbc2c3
more isort
aisclark91 Apr 14, 2023
e0735da
Adding docs
aisclark91 Apr 14, 2023
f645ad7
solving docs issues
aisclark91 Apr 14, 2023
0b65e75
more cleaning
aisclark91 Apr 17, 2023
4745a9f
adding soft links
aisclark91 Apr 17, 2023
03638ea
adding description
aisclark91 Apr 17, 2023
b1852ba
flake8
aisclark91 Apr 17, 2023
4f52483
more cleaning
aisclark91 Apr 17, 2023
651e919
cleaning
aisclark91 Apr 17, 2023
609d59a
Merge branch 'main' into pr-134
aisclark91 Apr 17, 2023
7b2654d
Merge branch 'main' into pr-134
aisclark91 Apr 19, 2023
cf85356
Merge branch 'main' into pr-134
aisclark91 Apr 20, 2023
24417d0
Merge branch 'main' of github.com:python-hydro/pyro2 into pr-134
aisclark91 Apr 20, 2023
8f9f795
adding new softlinks
aisclark91 Apr 20, 2023
f6652c2
Merge branch 'pr-134' of github.com:aisclark91/pyro2 into pr-134
aisclark91 Apr 20, 2023
8d87e5e
creating an interface module to the advection problem
aisclark91 Apr 20, 2023
1452316
creating an interface module to the advection_ppm problem
aisclark91 Apr 20, 2023
6d82ee1
erasing redundant module
aisclark91 Apr 20, 2023
a70f49a
Merge branch 'main' into pr-134
zingale May 3, 2023
08e9199
Merge branch 'main' into pr-134
aisclark91 May 3, 2023
107e5e0
Merge branch 'main' into pr-134
aisclark91 Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions docs/source/advection_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with different spatial and temporal integration schemes.
:py:mod:`pyro.advection` implements the directionally unsplit corner
transport upwind algorithm :cite:`colella:1990` with piecewise linear reconstruction.
This is an overall second-order accurate method, with timesteps restricted
by
by

.. math::

Expand All @@ -29,6 +29,23 @@ The parameters for this solver are:

.. include:: advection_defaults.inc

``advection_ppm`` solver
------------------------

:py:mod:`pyro.advection_ppm` applies a piecewise parabolic reconstruction (PPM) in the directionally
unsplit corner transport upwind algorithm (CTU) :cite:`colella:1984`. This reconstruction is an extension
of a higher-order Gudunov's method, designed to capture steeper representation of discontinuities, with
emphasis on contact discontinuities.

This is an overall second-order accurate method, with timesteps restricted by:

.. math::

\Delta t < \min \left \{ \frac{\Delta x}{|u|}, \frac{\Delta y}{|v|} \right \}

The parameters for this solver are:

.. include:: advection_ppm_defaults.inc

``advection_fv4`` solver
------------------------
Expand All @@ -39,8 +56,8 @@ method with RK4 time integration, following the ideas in
method-of-lines integration, and as such has a slightly more restrictive
timestep:

.. math::
.. math::

\Delta t \lesssim \left [ \frac{|u|}{\Delta x} + \frac{|v|}{\Delta y} \right ]^{-1}

The main complexity comes from needing to average the flux over the
Expand Down
27 changes: 27 additions & 0 deletions docs/source/advection_ppm_defaults.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
* section: [advection]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| u | ``1.0`` | advective velocity in x-direction |
+----------------------------------+----------------+----------------------------------------------------+
| v | ``1.0`` | advective velocity in y-direction |
+----------------------------------+----------------+----------------------------------------------------+

* section: [driver]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| cfl | ``0.8`` | advective CFL number |
+----------------------------------+----------------+----------------------------------------------------+

* section: [particles]

+----------------------------------+----------------+----------------------------------------------------+
| option | value | description |
+==================================+================+====================================================+
| do_particles | ``0`` | |
+----------------------------------+----------------+----------------------------------------------------+
| particle_generator | ``grid`` | |
+----------------------------------+----------------+----------------------------------------------------+
13 changes: 13 additions & 0 deletions docs/source/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ @ARTICLE{colella:1990
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

@ARTICLE{colella:1984,
title = {The Piecewise Parabolic Method (PPM) for gas-dynamical simulations},
journal = {Journal of Computational Physics},
volume = {54},
number = {1},
pages = {174-201},
year = {1984},
issn = {0021-9991},
doi = {https://doi.org/10.1016/0021-9991(84)90143-8},
url = {https://www.sciencedirect.com/science/article/pii/0021999184901438},
author = {Phillip Colella and Paul R Woodward},
}

@ARTICLE{mccorquodalecolella,
author = {{McCorquodale}, P. and {Colella}, P.},
title = "{A high-order finite-volume method for conservation laws on
Expand Down
10 changes: 10 additions & 0 deletions pyro/advection_ppm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
The Piecewise Parabolic reconstruction Method (PPM) + CTU unsplit dimensional implementation. This problem is a second-order
advection solver, based on the Colella & Woodward (1984), Colella (1990), Colella & Miller (2002) and Colella & Sekora (2002)
papers descriptions. The advantage of choosing the PPM parabolic reconstruction instead of the Piecewise Linear Reconstruction
(PLR), is the increased resolution of interfaces at contact discontinuities.

"""

__all__ = ['simulation']
from .simulation import Simulation
14 changes: 14 additions & 0 deletions pyro/advection_ppm/_defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[driver]
cfl = 0.8 ; advective CFL number


[advection]
u = 1.0 ; advective velocity in x-direction
v = 1.0 ; advective velocity in y-direction

limiter = 1 ; limiter (0 = none, 1 = 2nd order, 2 = 4th order)


[particles]
do_particles = 0
particle_generator = grid
59 changes: 59 additions & 0 deletions pyro/advection_ppm/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from pyro.mesh.reconstruction import ppm_reconstruction


def ppm_interface(a, myg, rp, dt):

# get the advection velocities
u = rp.get_param("advection.u")
v = rp.get_param("advection.v")

limiter = rp.get_param("advection.limiter")

cx = u*dt/myg.dx
cy = v*dt/myg.dy

# --------------------------------------------------------------------------
# monotonized central differences
# --------------------------------------------------------------------------

delta_ax = myg.scratch_array()
a6x = myg.scratch_array()
delta_ay = myg.scratch_array()
a6y = myg.scratch_array()

# upwind
a_x = myg.scratch_array()

ar, al = ppm_reconstruction(a, myg, idir=1, limiter=limiter)
delta_ax.v(buf=1)[:, :] = al.v(buf=1) - ar.v(buf=1)
a6x.v(buf=1)[:, :] = 6.0 * (a.v(buf=1) - 0.5*(ar.v(buf=1) + al.v(buf=1)))

if u < 0:
cx = -cx
# a_x[i,j] = a[i,j] - 0.5*(1.0 + cx)*ldelta_a[i,j]
a_x.v(buf=1)[:, :] = ar.v(buf=1) + 0.5 * cx * (delta_ax.v(buf=1) +
(1 - 2.0 * cx / 3.0) * a6x.v(buf=1))
else:
# a_x[i,j] = a[i-1,j] + 0.5*(1.0 - cx)*ldelta_a[i-1,j]
a_x.v(buf=1)[:, :] = al.ip(-1, buf=1) - 0.5 * cx * (delta_ax.ip(-1, buf=1) -
(1 - 2.0 * cx / 3.0) * a6x.ip(-1, buf=1))

# y-direction
a_y = myg.scratch_array()

ar, al = ppm_reconstruction(a, myg, idir=2, limiter=limiter)
delta_ay.v(buf=1)[:, :] = al.v(buf=1) - ar.v(buf=1)
a6y.v(buf=1)[:, :] = 6.0 * (a.v(buf=1) - 0.5*(ar.v(buf=1) + al.v(buf=1)))

# upwind
if v < 0:
cy = -cy
# a_y[i,j] = a[i,j] - 0.5*(1.0 + cy)*ldelta_a[i,j]
a_y.v(buf=1)[:, :] = ar.v(buf=1) + 0.5 * cy * (delta_ay.v(buf=1) +
(1 - 2.0 * cy / 3.0) * a6y.v(buf=1))
else:
# a_y[i,j] = a[i,j-1] + 0.5*(1.0 - cy)*ldelta_a[i,j-1]
a_y.v(buf=1)[:, :] = al.jp(-1, buf=1) - 0.5 * cy * (delta_ay.jp(-1, buf=1) -
(1 - 2.0 * cy / 3.0) * a6y.jp(-1, buf=1))

return u, v, a_x, a_y
1 change: 1 addition & 0 deletions pyro/advection_ppm/problems/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__all__ = ['smooth', 'tophat']
1 change: 1 addition & 0 deletions pyro/advection_ppm/problems/inputs.smooth
1 change: 1 addition & 0 deletions pyro/advection_ppm/problems/inputs.tophat
1 change: 1 addition & 0 deletions pyro/advection_ppm/problems/smooth.py
1 change: 1 addition & 0 deletions pyro/advection_ppm/problems/tophat.py
42 changes: 42 additions & 0 deletions pyro/advection_ppm/simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pyro.advection.advective_fluxes as flx
from pyro import advection
from pyro.advection_ppm.interface import ppm_interface


class Simulation(advection.Simulation):

def evolve(self):
"""
Evolve the linear advection equation through one timestep. We only
consider the "density" variable in the CellCenterData2d object that
is part of the Simulation.
"""

tm_evolve = self.tc.timer("evolve")
tm_evolve.begin()

dtdx = self.dt/self.cc_data.grid.dx
dtdy = self.dt/self.cc_data.grid.dy

Fx, Fy = flx.unsplit_fluxes(self.cc_data, self.rp, self.dt, "density", ppm_interface)

dens = self.cc_data.get_var("density")

dens.v()[:, :] = dens.v() + dtdx*(Fx.v() - Fx.ip(1)) + \
dtdy*(Fy.v() - Fy.jp(1))

if self.particles is not None:
myg = self.cc_data.grid
u = self.rp.get_param("advection.u")
v = self.rp.get_param("advection.v")

u2d = myg.scratch_array() + u
v2d = myg.scratch_array() + v

self.particles.update_particles(self.dt, u2d, v2d)

# increment the time
self.cc_data.t += self.dt
self.n += 1

tm_evolve.end()
Binary file added pyro/advection_ppm/tests/smooth_0040.h5
Binary file not shown.
37 changes: 37 additions & 0 deletions pyro/advection_ppm/tests/test_advection_ppm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pyro.advection_nonuniform.simulation as sn
from pyro.util import runparams


class TestSimulation:
@classmethod
def setup_class(cls):
""" this is run once for each class before any tests """

@classmethod
def teardown_class(cls):
""" this is run once for each class after all tests """

def setup_method(self):
""" this is run before each test """
self.rp = runparams.RuntimeParameters()

self.rp.params["mesh.nx"] = 8
self.rp.params["mesh.ny"] = 8
self.rp.params["particles.do_particles"] = 0

self.sim = sn.Simulation("advection_ppm", "test", self.rp)
self.sim.initialize()

def teardown_method(self):
""" this is run after each test """
self.rp = None
self.sim = None

def test_initializationst(self):
dens = self.sim.cc_data.get_var("density")
u = self.sim.cc_data.get_var("x-velocity")
v = self.sim.cc_data.get_var("y-velocity")

assert dens.min() == 1.0 and dens.max() == 1.0
assert u.min() == 1.0 and u.max() == 1.0
assert v.min() == 1.0 and v.max() == 1.0
Loading