Skip to content

Commit f5f5077

Browse files
committed
first stab at introducing answer-test script for Zeldovich Pancake.
1 parent c52ae9f commit f5f5077

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/answer_tests/test_cosmo.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,76 @@ def test_cosmo_dd_multispecies(self):
4747
continue
4848
data[key] = ad.quantities.weighted_standard_deviation(field, wfield)
4949
return data
50+
51+
52+
def _load_zeldovich_pancake_test_data(dirname, axis = 'x'):
53+
# helper function to assist with analyzing Zel'dovich pancake test problem
54+
#
55+
# This is currently very crude:
56+
# - we effectively only track a 1D problem that we run multiple times in
57+
# parallel (Each one is run along the x-axis, but at a different y,z
58+
# position).
59+
# - at the moment, we are just taking one of these 1D problems. But, maybe
60+
# we should look at the mean and standard-deviations of this problem?
61+
62+
if axis == 'x':
63+
idx = (slice(0,None), 0, 0)
64+
elif axis == 'y':
65+
idx = (0, slice(0,None), 0)
66+
elif axis == 'z':
67+
idx = (0, 0, slice(0,None))
68+
else:
69+
raise RuntimeError("problem with call to helper function")
70+
71+
ds = yt.load(f'./{dirname}/{dirname}.block_list')
72+
grid = ds.covering_grid(0, ds.domain_left_edge, ds.domain_dimensions)
73+
74+
# SANITY CHECK ABOUT FINAL REDSHIFT:
75+
if ds.current_redshift > 0.001:
76+
raise RuntimeError(
77+
"Something is wrong! Redshift should be 0, not "
78+
f"{ds.current_redshift}"
79+
)
80+
81+
return {
82+
'current_time' : ds.current_time,
83+
('enzoe', 'density') : grid['enzoe','density'][idx],
84+
('enzoe', 'velocity_x') : grid['enzoe','velocity_x'][idx],
85+
('enzoe', 'internal_energy') : grid['enzoe','internal_energy'][idx],
86+
('enzoe', 'total_energy') : grid['enzoe','total_energy'][idx],
87+
}
88+
89+
90+
class TestZeldovichPancakeVL(EnzoETest):
91+
# it would be nice to make this test a little more rigorous
92+
# - see _load_zeldovich_pancake_test_data for some ideas
93+
# - we currently only test a problem along the x-axis. What if we run it
94+
# along the y-axis or z-axis?
95+
96+
parameter_file = "Cosmology/ZeldovichPancake/vl-HD-x-aligned.in"
97+
98+
max_runtime = 20
99+
ncpus = 1
100+
101+
@ytdataset_test(assert_array_rel_equal, decimals=decimals)
102+
def test_x_zeldovich_pancake_vl(self):
103+
return _load_zeldovich_pancake_test_data(
104+
'method-vl-HD_x-aligned-pancake_7.860e+01', axis = 'x'
105+
)
106+
107+
class TestZeldovichPancakePPM(EnzoETest):
108+
# it would be nice to make this test a little more rigorous
109+
# - see _load_zeldovich_pancake_test_data for some ideas
110+
# - we currently only test a problem along the x-axis. What if we run it
111+
# along the y-axis or z-axis?
112+
113+
parameter_file = "Cosmology/ZeldovichPancake/ppm-HD-x-aligned.in"
114+
115+
max_runtime = 20
116+
ncpus = 1
117+
118+
@ytdataset_test(assert_array_rel_equal, decimals=decimals)
119+
def test_x_zeldovich_pancake_ppm(self):
120+
return _load_zeldovich_pancake_test_data(
121+
'method-ppm-HD_x-aligned-pancake_7.860e+01', axis = 'x'
122+
)

0 commit comments

Comments
 (0)