Updating cell instance regression test to include a higher level cell tally.

This commit is contained in:
Patrick Shriwise 2021-07-30 10:33:19 -05:00
parent f5651337e1
commit 82719c0fde
4 changed files with 53 additions and 14 deletions

View file

@ -1,6 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<geometry>
<cell id="1" material="1" region="-1" universe="1" />
<cell id="1" material="1" region="-1" universe="2" />
<cell id="2" material="2" region="1" universe="1" />
<cell fill="1" id="3" universe="2" />
<cell id="4" material="1" region="-2" universe="3" />

View file

@ -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

View file

@ -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()

View file

@ -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: