diff --git a/tests/regression_tests/filter_cellinstance/inputs_true.dat b/tests/regression_tests/filter_cellinstance/inputs_true.dat index 5df9926270..f9d3ca58d4 100644 --- a/tests/regression_tests/filter_cellinstance/inputs_true.dat +++ b/tests/regression_tests/filter_cellinstance/inputs_true.dat @@ -1,6 +1,6 @@ - + diff --git a/tests/regression_tests/filter_cellinstance/results_true.dat b/tests/regression_tests/filter_cellinstance/results_true.dat index 053ecf576e..c6832c6e1a 100644 --- a/tests/regression_tests/filter_cellinstance/results_true.dat +++ b/tests/regression_tests/filter_cellinstance/results_true.dat @@ -33,6 +33,14 @@ tally 1: 2.015188E+02 9.951936E+00 2.345815E+01 +1.061333E+01 +2.508486E+01 +2.767786E+01 +1.781264E+02 +2.898957E+01 +2.015188E+02 +9.951936E+00 +2.345815E+01 tally 2: 9.951936E+00 2.345815E+01 @@ -42,6 +50,14 @@ tally 2: 1.781264E+02 1.061333E+01 2.508486E+01 +9.951936E+00 +2.345815E+01 +2.898957E+01 +2.015188E+02 +2.767786E+01 +1.781264E+02 +1.061333E+01 +2.508486E+01 6.794395E-02 1.135006E-03 1.299309E-01 diff --git a/tests/regression_tests/filter_cellinstance/test.py b/tests/regression_tests/filter_cellinstance/test.py index bd708788c5..ccd547f912 100644 --- a/tests/regression_tests/filter_cellinstance/test.py +++ b/tests/regression_tests/filter_cellinstance/test.py @@ -2,8 +2,27 @@ import openmc import openmc.model import pytest +from numpy.testing import assert_array_almost_equal + from tests.testing_harness import PyAPITestHarness +class CellInstanceFilterTest(PyAPITestHarness): + + def _compare_results(self): + with openmc.StatePoint(self.statepoint_name) as sp: + # we expect the tally results for the instances of + # cells 2 and 3 to be the same as 2 is nested + # in a universe directly under 3 + t1 = sp.tallies[1] + f1 = sp.filters[1] + c2_bins = [tuple(tuple(i) for i in f1.bins if i[0] == 2)] + c2_mean = t1.get_values(filters=[openmc.CellInstanceFilter], filter_bins=c2_bins) + c3_bins = [tuple(tuple(i) for i in f1.bins if i[0] == 3)] + c3_mean = t1.get_values(filters=[openmc.CellInstanceFilter], filter_bins=c3_bins) + assert_array_almost_equal(c2_mean, c3_mean) + + return super()._compare_results() + @pytest.fixture def model(): @@ -23,23 +42,23 @@ def model(): c1 = openmc.Cell(fill=m1, region=-cyl1) c2 = openmc.Cell(fill=m2, region=+cyl1) # intermediate universe - ui = openmc.Universe(cells=[c2]) - ci = openmc.Cell(fill=ui) - u1 = openmc.Universe(cells=[c1, ci]) + u1 = openmc.Universe(cells=[c2]) + c3 = openmc.Cell(fill=u1) + u2 = openmc.Universe(cells=[c1, c3]) cyl2 = openmc.ZCylinder(r=0.5) - c3 = openmc.Cell(fill=m1, region=-cyl2) - c4 = openmc.Cell(fill=m2, region=+cyl2) - u2 = openmc.Universe(cells=[c3, c4]) + c4 = openmc.Cell(fill=m1, region=-cyl2) + c5 = openmc.Cell(fill=m2, region=+cyl2) + u3 = openmc.Universe(cells=[c4, c5]) lat = openmc.RectLattice() lat.lower_left = (-4, -4) lat.pitch = (2, 2) lat.universes = [ - [u1, u2, u2, u2], - [u2, u1, u2, u2], - [u2, u2, u1, u2], - [u2, u2, u2, u1] + [u2, u3, u3, u3], + [u3, u2, u3, u3], + [u3, u3, u2, u3], + [u3, u3, u3, u2] ] box = openmc.model.rectangular_prism(8.0, 8.0, boundary_type='reflective') main_cell = openmc.Cell(fill=lat, region=box) @@ -52,9 +71,9 @@ def model(): model.settings.particles = 1000 model.settings.source = openmc.Source(space=openmc.stats.Point()) - instances = ([(c3, i) for i in range(c3.num_instances)] + + instances = ([(c4, i) for i in range(c4.num_instances)] + [(c2, i) for i in range(c2.num_instances)] + - [(ci, i) for i in range(ci.num_instances)]) + [(c3, i) for i in range(c3.num_instances)]) f1 = openmc.CellInstanceFilter(instances) f2 = openmc.CellInstanceFilter(instances[::-1]) t1 = openmc.Tally() @@ -69,5 +88,5 @@ def model(): def test_cell_instance(model): - harness = PyAPITestHarness('statepoint.5.h5', model) + harness = CellInstanceFilterTest('statepoint.5.h5', model) harness.main() diff --git a/tests/testing_harness.py b/tests/testing_harness.py index 48f121d459..92d34ccdca 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -115,6 +115,10 @@ class TestHarness: return outstr + @property + def statepoint_name(self): + return self._sp_name + def _write_results(self, results_string): """Write the results to an ASCII file.""" with open('results_test.dat', 'w') as fh: