Updates to object lifecycle for WeightWindows and WeightWindowGenerators (#2582)

This commit is contained in:
Patrick Shriwise 2023-06-30 22:29:47 -05:00 committed by GitHub
parent 36f229eb01
commit 382bcb2e8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 275 additions and 211 deletions

View file

@ -28,13 +28,20 @@ def test_ww_generator(run_in_tmpdir):
energy_bounds = np.linspace(0.0, 1e6, 70)
particle = 'neutron'
# include another tally to make sure user-specified tallies and those automaticaly
# created by weight window generators can coexist
tally = openmc.Tally()
ef = openmc.EnergyFilter(energy_bounds)
tally.filters = [ef]
tally.scores = ['flux']
model.tallies = [tally]
wwg = openmc.WeightWindowGenerator(mesh, energy_bounds, particle)
wwg.update_parameters = {'ratio' : 5.0, 'threshold': 0.8, 'value' : 'mean'}
wwg.update_parameters = {'ratio': 5.0, 'threshold': 0.8, 'value': 'mean'}
model.settings.weight_window_generators = wwg
model.export_to_xml()
model.run()
# we test the effectiveness of the update method elsewhere, so
# just test that the generation happens successfully here
assert os.path.exists('weight_windows.h5')

View file

@ -241,7 +241,21 @@ def test_roundtrip(run_in_tmpdir, model, wws):
assert(ww_out == ww_in)
def test_ww_attrs(run_in_tmpdir, model):
def test_ww_attrs_python(model):
mesh = openmc.RegularMesh.from_domain(model.geometry)
lower_bounds = np.ones(mesh.dimension)
# ensure that creation of weight window objects with default arg values
# is successful
wws = openmc.WeightWindows(mesh, lower_bounds, upper_bound_ratio=10.0)
assert wws.energy_bounds == None
wwg = openmc.WeightWindowGenerator(mesh)
assert wwg.energy_bounds == None
def test_ww_attrs_capi(run_in_tmpdir, model):
model.export_to_xml()
openmc.lib.init()