Skip to content

Commit 702eb5b

Browse files
authored
add more tests, including HSE (#29)
1 parent 5bddcad commit 702eb5b

File tree

3 files changed

+151
-4
lines changed

3 files changed

+151
-4
lines changed

.codespell-ignore-words

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
ans
12
blocs
23
bloc
34
inout

ppmpy/tests/test_euler.py

+82-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
import numpy as np
22
from numpy.testing import assert_array_almost_equal_nulp
33

4-
from ppmpy.euler import Euler
5-
from ppmpy.initial_conditions import sod
4+
from ppmpy.euler import Euler, FluidVars
5+
from ppmpy.initial_conditions import sod, acoustic_pulse
66

77

8-
class TestGrid:
8+
class TestFluidVars:
9+
10+
@classmethod
11+
def setup_class(cls):
12+
""" this is run once for each class before any tests """
13+
14+
@classmethod
15+
def teardown_class(cls):
16+
""" this is run once for each class after all tests """
17+
18+
def setup_method(self):
19+
""" this is run before each test """
20+
21+
self.v = FluidVars()
22+
23+
def teardown_method(self):
24+
""" this is run after each test """
25+
26+
def test_indices(self):
27+
assert self.v.urho == self.v.qrho
28+
assert self.v.umx == self.v.qu
29+
assert self.v.uener == self.v.qp
30+
31+
32+
class TestEuler:
933

1034
@classmethod
1135
def setup_class(cls):
@@ -47,7 +71,7 @@ def test_cons_to_prim(self):
4771
assert q[-1, v.qu] == u_r
4872
assert q[-1, v.qp] == p_r
4973

50-
def test_properties(self):
74+
def test_estimate_dt(self):
5175

5276
# for sod, there is only a left and right state. No initial velocity
5377
# so we can just get the soundspeed
@@ -80,3 +104,57 @@ def test_result(self):
80104
0.125001080305388, 0.1250000106083176])
81105

82106
assert_array_almost_equal_nulp(self.euler.U[self.euler.grid.lo:self.euler.grid.hi+1, 0], answer, nulp=9)
107+
108+
109+
class TestEulerReconstruction:
110+
111+
@classmethod
112+
def setup_class(cls):
113+
""" this is run once for each class before any tests """
114+
115+
@classmethod
116+
def teardown_class(cls):
117+
""" this is run once for each class after all tests """
118+
119+
def setup_method(self):
120+
""" this is run before each test """
121+
122+
self.euler = Euler(16, 0.5, init_cond=acoustic_pulse)
123+
self.euler.estimate_dt()
124+
125+
def teardown_method(self):
126+
""" this is run after each test """
127+
128+
def test_construct_parabola(self):
129+
130+
self.euler.construct_parabola()
131+
132+
ans = np.array([0.0000000000000000e+00, 0.0000000000000000e+00,
133+
0.0000000000000000e+00, 0.0000000000000000e+00,
134+
0.0000000000000000e+00, -1.4925725604797435e-05,
135+
-5.5892314022898404e-04, -3.1886159900746947e-03,
136+
-1.1509891420676155e-02, -1.5395301015125540e-02,
137+
-7.3670928260867186e-03, 0.0000000000000000e+00,
138+
0.0000000000000000e+00, -7.3670928260867186e-03,
139+
-1.5395301015125540e-02, -1.1509891420676155e-02,
140+
-3.1886159900746947e-03, -5.5892314022898404e-04,
141+
-1.4925725604797435e-05, 0.0000000000000000e+00,
142+
0.0000000000000000e+00, 0.0000000000000000e+00,
143+
0.0000000000000000e+00, 0.0000000000000000e+00])
144+
145+
assert_array_almost_equal_nulp(self.euler.q_parabola[0].a6, ans)
146+
147+
ans2 = np.array([0.0000000000000000e+00, 0.0000000000000000e+00,
148+
-8.8817841970012523e-16, 0.0000000000000000e+00,
149+
-8.8817841970012523e-16, -1.4925738349269579e-05,
150+
-5.5894233322995035e-04, -3.1567942491133039e-03,
151+
-1.1552096619801056e-02, -1.5947978794340401e-02,
152+
-8.1712935823112787e-03, 0.0000000000000000e+00,
153+
0.0000000000000000e+00, -8.1712935823112787e-03,
154+
-1.5947978794340401e-02, -1.1552096619801056e-02,
155+
-3.1567942491133039e-03, -5.5894233322995035e-04,
156+
-1.4925738349269579e-05, -8.8817841970012523e-16,
157+
0.0000000000000000e+00, -8.8817841970012523e-16,
158+
0.0000000000000000e+00, 0.0000000000000000e+00])
159+
160+
assert_array_almost_equal_nulp(self.euler.q_parabola[2].a6, ans2)
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import numpy as np
2+
from numpy.testing import assert_array_almost_equal_nulp
3+
4+
from ppmpy.euler import Euler
5+
from ppmpy.gravity import constant_gravity
6+
from ppmpy.initial_conditions import hse
7+
8+
9+
class TestHSE:
10+
11+
@classmethod
12+
def setup_class(cls):
13+
""" this is run once for each class before any tests """
14+
15+
@classmethod
16+
def teardown_class(cls):
17+
""" this is run once for each class after all tests """
18+
19+
def setup_method(self):
20+
""" this is run before each test """
21+
22+
params = {"base_density": 1.0, "base_pressure": 1.0, "g_const": -1.0}
23+
24+
self.hse = Euler(16, 0.5, init_cond=hse,
25+
grav_func=constant_gravity,
26+
use_hse_reconstruction=True,
27+
bc_left_type="reflect", bc_right_type="reflect", params=params)
28+
29+
self.nohse = Euler(16, 0.5, init_cond=hse,
30+
grav_func=constant_gravity,
31+
use_hse_reconstruction=False,
32+
bc_left_type="reflect", bc_right_type="reflect", params=params)
33+
34+
def teardown_method(self):
35+
""" this is run after each test """
36+
37+
def test_hse_pressure_reconstruction(self):
38+
39+
self.hse.construct_parabola()
40+
41+
# the key here is that the left parabola state for the first interior
42+
# zone (4, starting from 0) is high -- it is the dp/dr we expect
43+
44+
ans = np.array([0.8034735033053615, 0.8553105035186105, 0.9104918263262627,
45+
0.9692332344763441, 0.9995217730537299, 0.9389446958989583,
46+
0.882038956753567, 0.8285820502836542, 0.7783649563270688,
47+
0.7311913226102768, 0.6868766969975327, 0.6452478062704096,
48+
0.6061418786176574, 0.5694060071862842, 0.5348965522052972,
49+
0.5024785793443701, 0.4720253321113781, 0.4434177362258399,
50+
0.4165439340303344, 0.3912988471194051, 0.379441306297605,
51+
0.40392139057486975, 0.42998083512808716, 0.457721534168609])
52+
53+
assert_array_almost_equal_nulp(self.hse.q_parabola[self.hse.v.qp].am, ans)
54+
55+
def test_standard_pressure_reconstruction(self):
56+
57+
self.nohse.construct_parabola()
58+
59+
ans = np.array([0.8034735033053615, 0.8553105035186105, 0.8327632963498921,
60+
0.9692332344763441, 0.9692332344763441, 0.9493560913144479,
61+
0.8823257975943671, 0.8288515068310723, 0.7786180821746437,
62+
0.7314291074973925, 0.6871000706793687, 0.6454576421533463,
63+
0.6063389971743558, 0.5695911791637885, 0.5350705016387105,
64+
0.5026419863878796, 0.472178835697705, 0.44356193656451076,
65+
0.41667939495454037, 0.379441306297605, 0.379441306297605,
66+
0.40392139057486975, 0.42998083512808716, 0.457721534168609])
67+
68+
assert_array_almost_equal_nulp(self.nohse.q_parabola[self.nohse.v.qp].am, ans)

0 commit comments

Comments
 (0)