Mat ids reset (#3125)

Co-authored-by: azimgivron <azimgivron@gmail.com>
Co-authored-by: azim_givron <a.givron@naarea.fr>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
azimG 2024-09-27 02:31:59 +02:00 committed by GitHub
parent 8b77a8dd3b
commit 1645e3bb87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 31 additions and 33 deletions

View file

@ -244,7 +244,6 @@ class IndependentOperator(OpenMCOperator):
"""Puts nuclide list into an openmc.Materials object.
"""
openmc.reset_auto_ids()
mat = openmc.Material()
if nuc_units == 'atom/b-cm':
for nuc, conc in nuclides.items():

View file

@ -146,8 +146,6 @@ class OpenMCOperator(TransportOperator):
# Determine which nuclides have cross section data
# This nuclides variables contains every nuclides
# for which there is an entry in the micro_xs parameter
openmc.reset_auto_ids()
self.nuclides_with_data = self._get_nuclides_with_data(
self.cross_sections)
@ -396,9 +394,6 @@ class OpenMCOperator(TransportOperator):
self.number.set_density(vec)
self._update_materials()
# Prevent OpenMC from complaining about re-creating tallies
openmc.reset_auto_ids()
# Update tally nuclides data in preparation for transport solve
nuclides = self._get_reaction_nuclides()
self._rate_helper.nuclides = nuclides

View file

@ -72,12 +72,17 @@ class IDManagerMixin:
cls.used_ids.add(uid)
self._id = uid
@classmethod
def reset_ids(cls):
"""Reset counters"""
cls.used_ids.clear()
cls.next_id = 1
def reset_auto_ids():
"""Reset counters for all auto-generated IDs"""
for cls in IDManagerMixin.__subclasses__():
cls.used_ids.clear()
cls.next_id = 1
cls.reset_ids()
def reserve_ids(ids, cls=None):

View file

@ -12,6 +12,17 @@ config = {
}
def assert_same_mats(res_ref, res_test):
for mat in res_ref[0].index_mat:
assert mat in res_test[0].index_mat, f"Material {mat} not in new results."
for nuc in res_ref[0].index_nuc:
assert nuc in res_test[0].index_nuc, f"Nuclide {nuc} not in new results."
for mat in res_test[0].index_mat:
assert mat in res_ref[0].index_mat, f"Material {mat} not in old results."
for nuc in res_test[0].index_nuc:
assert nuc in res_ref[0].index_nuc, f"Nuclide {nuc} not in old results."
def assert_atoms_equal(res_ref, res_test, tol=1e-5):
for mat in res_test[0].index_mat:
for nuc in res_test[0].index_nuc:

View file

@ -10,7 +10,7 @@ import openmc.deplete
from openmc.deplete import IndependentOperator, MicroXS
from tests.regression_tests import config, assert_atoms_equal, \
assert_reaction_rates_equal
assert_reaction_rates_equal, assert_same_mats
@pytest.fixture(scope="module")
@ -101,7 +101,7 @@ def test_against_self(run_in_tmpdir,
res_ref = openmc.deplete.Results(path_reference)
# Assert same mats
_assert_same_mats(res_test, res_ref)
assert_same_mats(res_ref, res_test)
tol = 1.0e-14
assert_atoms_equal(res_ref, res_test, tol)
@ -155,7 +155,7 @@ def test_against_coupled(run_in_tmpdir,
res_ref = openmc.deplete.Results(path_reference)
# Assert same mats
_assert_same_mats(res_test, res_ref)
assert_same_mats(res_test, res_ref)
assert_atoms_equal(res_ref, res_test, atom_tol)
assert_reaction_rates_equal(res_ref, res_test, rx_tol)
@ -172,6 +172,7 @@ def _create_operator(from_nuclides,
for nuc, dens in fuel.get_nuclide_atom_densities().items():
nuclides[nuc] = dens
openmc.reset_auto_ids()
op = IndependentOperator.from_nuclides(fuel.volume,
nuclides,
flux,
@ -187,20 +188,3 @@ def _create_operator(from_nuclides,
normalization_mode=normalization_mode)
return op
def _assert_same_mats(res_ref, res_test):
for mat in res_ref[0].index_mat:
assert mat in res_test[0].index_mat, \
f"Material {mat} not in new results."
for nuc in res_ref[0].index_nuc:
assert nuc in res_test[0].index_nuc, \
f"Nuclide {nuc} not in new results."
for mat in res_test[0].index_mat:
assert mat in res_ref[0].index_mat, \
f"Material {mat} not in old results."
for nuc in res_test[0].index_nuc:
assert nuc in res_ref[0].index_nuc, \
f"Nuclide {nuc} not in old results."

View file

@ -11,11 +11,12 @@ import openmc.deplete
from openmc.deplete import CoupledOperator
from tests.regression_tests import config, assert_reaction_rates_equal, \
assert_atoms_equal
assert_atoms_equal, assert_same_mats
@pytest.fixture
def model():
openmc.reset_auto_ids()
f = openmc.Material(name="f")
f.add_element("U", 1, percent_type="ao", enrichment=4.25)
f.add_element("O", 2)
@ -66,7 +67,7 @@ def test_transfer_rates(run_in_tmpdir, model, rate, dest_mat, power, ref_result)
integrator = openmc.deplete.PredictorIntegrator(
op, [1], power, timestep_units = 'd')
integrator.add_transfer_rate('f', transfer_elements, rate,
destination_material=dest_mat)
destination_material=dest_mat)
integrator.integrate()
# Get path to test and reference results
@ -82,5 +83,6 @@ def test_transfer_rates(run_in_tmpdir, model, rate, dest_mat, power, ref_result)
res_ref = openmc.deplete.Results(path_reference)
res_test = openmc.deplete.Results(path_test)
assert_same_mats(res_ref, res_test)
assert_atoms_equal(res_ref, res_test, 1e-6)
assert_reaction_rates_equal(res_ref, res_test)

View file

@ -40,8 +40,9 @@ def test_deplete_decay_products(run_in_tmpdir):
# Get concentration of H1 and He4
results = openmc.deplete.Results('depletion_results.h5')
_, h1 = results.get_atoms("1", "H1")
_, he4 = results.get_atoms("1", "He4")
mat_id = op.materials[0].id
_, h1 = results.get_atoms(f"{mat_id}", "H1")
_, he4 = results.get_atoms(f"{mat_id}", "He4")
# Since we started with 1e24 atoms of Li5, we should have 1e24 atoms of both
# H1 and He4
@ -78,6 +79,6 @@ def test_deplete_decay_step_fissionable(run_in_tmpdir):
# Get concentration of U238. It should be unchanged since this chain has no U238 decay.
results = openmc.deplete.Results('depletion_results.h5')
_, u238 = results.get_atoms("1", "U238")
_, u238 = results.get_atoms(f"{mat.id}", "U238")
assert u238[1] == pytest.approx(original_atoms)

View file

@ -71,6 +71,7 @@ def model():
def test_get_set(model, case_name, transfer_rates):
"""Tests the get/set methods"""
openmc.reset_auto_ids()
op = CoupledOperator(model, CHAIN_PATH)
transfer = TransferRates(op, model)