Skip to content

Commit 7e7dd5c

Browse files
authored
remove gamma from the initial conditions argument list (#38)
1 parent 926e60f commit 7e7dd5c

4 files changed

Lines changed: 47 additions & 54 deletions

File tree

examples/euler.ipynb

Lines changed: 16 additions & 19 deletions
Large diffs are not rendered by default.

examples/hse.ipynb

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 16,
23+
"execution_count": 1,
2424
"id": "e9274186-dea7-4254-a5e1-1c10e4ede36c",
2525
"metadata": {},
2626
"outputs": [],
@@ -43,7 +43,7 @@
4343
},
4444
{
4545
"cell_type": "code",
46-
"execution_count": 10,
46+
"execution_count": 2,
4747
"id": "80932eef-a2f0-4c5b-b267-06255b543d56",
4848
"metadata": {},
4949
"outputs": [],
@@ -53,7 +53,7 @@
5353
},
5454
{
5555
"cell_type": "code",
56-
"execution_count": 11,
56+
"execution_count": 3,
5757
"id": "898eb0ed-1bec-41f0-9431-45b2ad4c5787",
5858
"metadata": {},
5959
"outputs": [],
@@ -79,7 +79,7 @@
7979
},
8080
{
8181
"cell_type": "code",
82-
"execution_count": 12,
82+
"execution_count": 4,
8383
"id": "313edca0-aa4c-4dac-ab14-7a6cff0455bd",
8484
"metadata": {},
8585
"outputs": [],
@@ -90,7 +90,7 @@
9090
},
9191
{
9292
"cell_type": "code",
93-
"execution_count": 13,
93+
"execution_count": 5,
9494
"id": "6935138d-852d-4d56-ac43-4960cd4f4b6b",
9595
"metadata": {},
9696
"outputs": [
@@ -122,7 +122,7 @@
122122
},
123123
{
124124
"cell_type": "code",
125-
"execution_count": 14,
125+
"execution_count": 7,
126126
"id": "66950c33-44e4-4975-9e96-c569396b8f5c",
127127
"metadata": {},
128128
"outputs": [
@@ -141,7 +141,7 @@
141141
"source": [
142142
"for s in simulations:\n",
143143
" init = s.grid.scratch_array(nc=3)\n",
144-
" hse(s.grid, s.v, s.gamma, init, params)\n",
144+
" hse(s.grid, s.v, init, s.params)\n",
145145
" print(f\"{s.grid.nx:3d} : {s.grid.norm(init[:, ivar] - s.U[:, ivar]) }\")"
146146
]
147147
},
@@ -155,17 +155,17 @@
155155
},
156156
{
157157
"cell_type": "code",
158-
"execution_count": 15,
158+
"execution_count": 10,
159159
"id": "d4e9df43-d976-4e00-b99b-213f52b60839",
160160
"metadata": {},
161161
"outputs": [
162162
{
163163
"data": {
164164
"text/plain": [
165-
"[<matplotlib.lines.Line2D at 0x7fb4bd4cf050>]"
165+
"[<matplotlib.lines.Line2D at 0x7ff5d0149880>]"
166166
]
167167
},
168-
"execution_count": 15,
168+
"execution_count": 10,
169169
"metadata": {},
170170
"output_type": "execute_result"
171171
},
@@ -183,20 +183,12 @@
183183
"source": [
184184
"s = simulations[0]\n",
185185
"init = s.grid.scratch_array(nc=3)\n",
186-
"hse(s.grid, s.v, s.gamma, init, params)\n",
186+
"hse(s.grid, s.v, init, s.params)\n",
187187
"\n",
188188
"fig, ax = plt.subplots()\n",
189189
"ax.plot(s.grid.x[s.grid.lo:s.grid.hi+1], init[s.grid.lo:s.grid.hi+1, ivar], marker=\"o\")\n",
190190
"ax.plot(s.grid.x[s.grid.lo:s.grid.hi+1], s.U[s.grid.lo:s.grid.hi+1, ivar], marker=\"x\")"
191191
]
192-
},
193-
{
194-
"cell_type": "code",
195-
"execution_count": null,
196-
"id": "5dd5d3aa-f1a1-4e55-b8a3-fa07cce6bf89",
197-
"metadata": {},
198-
"outputs": [],
199-
"source": []
200192
}
201193
],
202194
"metadata": {

ppmpy/euler.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class Euler:
5454
bc_left_type : str
5555
boundary condition type at the right edge. Allowed values
5656
are: "reflect", "outflow", "periodic"
57-
gamma : float
58-
the ratio of specific heats
5957
init_cond : function
6058
the function to call to initialize the conserved state.
6159
This has the signature `init_cond(grid, v, gamma, U, params)`
@@ -69,7 +67,8 @@ class Euler:
6967
is a `dict` of option parameters needed to interpret gravity.
7068
params : dict, optional
7169
a dictionary of parameters that is passed to the initial condition
72-
and gravity functions.
70+
and gravity functions. The ratio specific heats can be set
71+
here as "gamma".
7372
use_hse_reconstruction : bool, optional
7473
do we subtract off HSE from pressure before doing the parabolic
7574
reconstruction?
@@ -92,7 +91,6 @@ def __init__(self, nx, C, *,
9291
self.v = FluidVars()
9392

9493
self.C = C
95-
self.gamma = gamma
9694
self.fixed_dt = fixed_dt
9795

9896
self.grav_func = grav_func
@@ -105,6 +103,11 @@ def __init__(self, nx, C, *,
105103
else:
106104
self.params = params
107105

106+
self.gamma = self.params.get("gamma", 1.4)
107+
108+
if "gamma" not in self.params:
109+
self.params["gamma"] = gamma
110+
108111
# setup the BCs -- we need the flexibiility to have different
109112
# types for each state variable. In particular, we want
110113
# odd reflection for velocity
@@ -127,7 +130,7 @@ def __init__(self, nx, C, *,
127130
self.g_parabola = None
128131

129132
# initialize
130-
init_cond(self.grid, self.v, self.gamma, self.U, self.params)
133+
init_cond(self.grid, self.v, self.U, self.params)
131134
for n in range(self.v.nvar):
132135
self.grid.ghost_fill(self.U[:, n],
133136
bc_left_type=self.bcs_left[n],

ppmpy/initial_conditions.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55

66

7-
def sod(g, v, gamma, U, params): # pylint: disable=W0613
7+
def sod(g, v, U, params): # pylint: disable=W0613
88
"""Initial conditions for the classic Sod shock tube problem
99
1010
Parameters
@@ -13,18 +13,19 @@ def sod(g, v, gamma, U, params): # pylint: disable=W0613
1313
the grid object
1414
v : FluidVars
1515
the fluid variables object
16-
gamma : float
17-
the ratio of specific heats
1816
U : ndarray
1917
the conserved state array
2018
params : dict
21-
a dictionary of parameters (not used)
19+
a dictionary of parameters.
20+
We expect gamma to be provided here
2221
2322
Returns
2423
-------
2524
None
2625
"""
2726

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

4748

48-
def acoustic_pulse(g, v, gamma, U, params): # pylint: disable=W0613
49+
def acoustic_pulse(g, v, U, params): # pylint: disable=W0613
4950
"""The acoustic pulse problem from McCorquodale & Colella 2011
5051
5152
Parameters
@@ -54,18 +55,19 @@ def acoustic_pulse(g, v, gamma, U, params): # pylint: disable=W0613
5455
the grid object
5556
v : FluidVars
5657
the fluid variables object
57-
gamma : float
58-
the ratio of specific heats
5958
U : ndarray
6059
the conserved state array
6160
params : dict
6261
a dictionary of parameters (not used)
62+
We expect gamma to be provided here
6363
6464
Returns
6565
-------
6666
None
6767
"""
6868

69+
gamma = params["gamma"]
70+
6971
xcenter = 0.5 * (g.xmin + g.xmax)
7072

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

8486

85-
def hse(grid, v, gamma, U, params):
87+
def hse(grid, v, U, params):
8688
"""An isothermal hydrostatic atmosphere.
87-
8889
Parameters
8990
----------
9091
grid : FVGrid
9192
the grid object
9293
v : FluidVars
9394
the fluid variables object
94-
gamma : float
95-
the ratio of specific heats
9695
U : ndarray
9796
the conserved state array
9897
params : dict
@@ -101,6 +100,7 @@ def hse(grid, v, gamma, U, params):
101100
* `base_density` : the density at the lower boundary
102101
* `base_pressure` : the pressure at the lower boundary
103102
* `g_const` : the gravitational acceleration
103+
* `gamma` : the ratio of specific heats
104104
105105
Returns
106106
-------
@@ -110,6 +110,7 @@ def hse(grid, v, gamma, U, params):
110110
rho_base = params["base_density"]
111111
pres_base = params["base_pressure"]
112112
g = params["g_const"]
113+
gamma = params["gamma"]
113114

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

0 commit comments

Comments
 (0)