Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 16 additions & 19 deletions examples/euler.ipynb

Large diffs are not rendered by default.

30 changes: 11 additions & 19 deletions examples/hse.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 1,
"id": "e9274186-dea7-4254-a5e1-1c10e4ede36c",
"metadata": {},
"outputs": [],
Expand All @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 2,
"id": "80932eef-a2f0-4c5b-b267-06255b543d56",
"metadata": {},
"outputs": [],
Expand All @@ -53,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 3,
"id": "898eb0ed-1bec-41f0-9431-45b2ad4c5787",
"metadata": {},
"outputs": [],
Expand All @@ -79,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 4,
"id": "313edca0-aa4c-4dac-ab14-7a6cff0455bd",
"metadata": {},
"outputs": [],
Expand All @@ -90,7 +90,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 5,
"id": "6935138d-852d-4d56-ac43-4960cd4f4b6b",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -122,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 7,
"id": "66950c33-44e4-4975-9e96-c569396b8f5c",
"metadata": {},
"outputs": [
Expand All @@ -141,7 +141,7 @@
"source": [
"for s in simulations:\n",
" init = s.grid.scratch_array(nc=3)\n",
" hse(s.grid, s.v, s.gamma, init, params)\n",
" hse(s.grid, s.v, init, s.params)\n",
" print(f\"{s.grid.nx:3d} : {s.grid.norm(init[:, ivar] - s.U[:, ivar]) }\")"
]
},
Expand All @@ -155,17 +155,17 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 10,
"id": "d4e9df43-d976-4e00-b99b-213f52b60839",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7fb4bd4cf050>]"
"[<matplotlib.lines.Line2D at 0x7ff5d0149880>]"
]
},
"execution_count": 15,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
},
Expand All @@ -183,20 +183,12 @@
"source": [
"s = simulations[0]\n",
"init = s.grid.scratch_array(nc=3)\n",
"hse(s.grid, s.v, s.gamma, init, params)\n",
"hse(s.grid, s.v, init, s.params)\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.plot(s.grid.x[s.grid.lo:s.grid.hi+1], init[s.grid.lo:s.grid.hi+1, ivar], marker=\"o\")\n",
"ax.plot(s.grid.x[s.grid.lo:s.grid.hi+1], s.U[s.grid.lo:s.grid.hi+1, ivar], marker=\"x\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5dd5d3aa-f1a1-4e55-b8a3-fa07cce6bf89",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
13 changes: 8 additions & 5 deletions ppmpy/euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class Euler:
bc_left_type : str
boundary condition type at the right edge. Allowed values
are: "reflect", "outflow", "periodic"
gamma : float
the ratio of specific heats
init_cond : function
the function to call to initialize the conserved state.
This has the signature `init_cond(grid, v, gamma, U, params)`
Expand All @@ -69,7 +67,8 @@ class Euler:
is a `dict` of option parameters needed to interpret gravity.
params : dict, optional
a dictionary of parameters that is passed to the initial condition
and gravity functions.
and gravity functions. The ratio specific heats can be set
here as "gamma".
use_hse_reconstruction : bool, optional
do we subtract off HSE from pressure before doing the parabolic
reconstruction?
Expand All @@ -92,7 +91,6 @@ def __init__(self, nx, C, *,
self.v = FluidVars()

self.C = C
self.gamma = gamma
self.fixed_dt = fixed_dt

self.grav_func = grav_func
Expand All @@ -105,6 +103,11 @@ def __init__(self, nx, C, *,
else:
self.params = params

self.gamma = self.params.get("gamma", 1.4)

if "gamma" not in self.params:
self.params["gamma"] = gamma

# setup the BCs -- we need the flexibiility to have different
# types for each state variable. In particular, we want
# odd reflection for velocity
Expand All @@ -127,7 +130,7 @@ def __init__(self, nx, C, *,
self.g_parabola = None

# initialize
init_cond(self.grid, self.v, self.gamma, self.U, self.params)
init_cond(self.grid, self.v, self.U, self.params)
for n in range(self.v.nvar):
self.grid.ghost_fill(self.U[:, n],
bc_left_type=self.bcs_left[n],
Expand Down
23 changes: 12 additions & 11 deletions ppmpy/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np


def sod(g, v, gamma, U, params): # pylint: disable=W0613
def sod(g, v, U, params): # pylint: disable=W0613
"""Initial conditions for the classic Sod shock tube problem

Parameters
Expand All @@ -13,18 +13,19 @@ def sod(g, v, gamma, U, params): # pylint: disable=W0613
the grid object
v : FluidVars
the fluid variables object
gamma : float
the ratio of specific heats
U : ndarray
the conserved state array
params : dict
a dictionary of parameters (not used)
a dictionary of parameters.
We expect gamma to be provided here

Returns
-------
None
"""

gamma = params["gamma"]

# setup initial conditions -- this is Sod's problem
rho_l = 1.0
u_l = 0.0
Expand All @@ -45,7 +46,7 @@ def sod(g, v, gamma, U, params): # pylint: disable=W0613
U[idx_r, v.uener] = p_r/(gamma - 1.0) + 0.5 * rho_r * u_r**2


def acoustic_pulse(g, v, gamma, U, params): # pylint: disable=W0613
def acoustic_pulse(g, v, U, params): # pylint: disable=W0613
"""The acoustic pulse problem from McCorquodale & Colella 2011

Parameters
Expand All @@ -54,18 +55,19 @@ def acoustic_pulse(g, v, gamma, U, params): # pylint: disable=W0613
the grid object
v : FluidVars
the fluid variables object
gamma : float
the ratio of specific heats
U : ndarray
the conserved state array
params : dict
a dictionary of parameters (not used)
We expect gamma to be provided here

Returns
-------
None
"""

gamma = params["gamma"]

xcenter = 0.5 * (g.xmin + g.xmax)

rho0 = 1.4
Expand All @@ -82,17 +84,14 @@ def acoustic_pulse(g, v, gamma, U, params): # pylint: disable=W0613
U[:, v.uener] = p / (gamma - 1.0) + 0.5 * rho * u**2


def hse(grid, v, gamma, U, params):
def hse(grid, v, U, params):
"""An isothermal hydrostatic atmosphere.

Parameters
----------
grid : FVGrid
the grid object
v : FluidVars
the fluid variables object
gamma : float
the ratio of specific heats
U : ndarray
the conserved state array
params : dict
Expand All @@ -101,6 +100,7 @@ def hse(grid, v, gamma, U, params):
* `base_density` : the density at the lower boundary
* `base_pressure` : the pressure at the lower boundary
* `g_const` : the gravitational acceleration
* `gamma` : the ratio of specific heats

Returns
-------
Expand All @@ -110,6 +110,7 @@ def hse(grid, v, gamma, U, params):
rho_base = params["base_density"]
pres_base = params["base_pressure"]
g = params["g_const"]
gamma = params["gamma"]

verbose = params.get("verbose", False)

Expand Down