Skip to content

Commit

Permalink
Fix comparison of structured arrays for surface_source test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Jan 12, 2025
1 parent b57714f commit a15dc30
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions tests/regression_tests/surface_source/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
from tests.regression_tests import config


def assert_structured_arrays_close(arr1, arr2, rtol=1e-5, atol=1e-8):
assert arr1.dtype == arr2.dtype

for field in arr1.dtype.names:
data1, data2 = arr1[field], arr2[field]
if data1.dtype.names:
assert_structured_arrays_close(data1, data2, rtol=rtol, atol=atol)
else:
np.testing.assert_allclose(data1, data2, rtol=rtol, atol=atol)


@pytest.fixture
def model(request):
openmc.reset_auto_ids()
Expand Down Expand Up @@ -76,16 +87,10 @@ def _compare_output(self):
"""Make sure the current surface_source.h5 agree with the reference."""
if self._model.settings.surf_source_write:
with h5py.File("surface_source_true.h5", 'r') as f:
source_true = f['source_bank'][()]
# Convert dtye from mixed to a float for comparison assertion
source_true.dtype = 'float64'
source_true = np.sort(f['source_bank'][()])
with h5py.File("surface_source.h5", 'r') as f:
source_test = f['source_bank'][()]
# Convert dtye from mixed to a float for comparison assertion
source_test.dtype = 'float64'
np.testing.assert_allclose(np.sort(source_true),
np.sort(source_test),
atol=1e-07)
source_test = np.sort(f['source_bank'][()])
assert_structured_arrays_close(source_true, source_test, atol=1e-07)

def execute_test(self):
"""Build input XMLs, run OpenMC, check output and results."""
Expand Down Expand Up @@ -132,4 +137,4 @@ def test_surface_source_read(model):
harness = SurfaceSourceTestHarness('statepoint.10.h5',
model,
'inputs_true_read.dat')
harness.main()
harness.main()

0 comments on commit a15dc30

Please sign in to comment.