Skip to content

Commit

Permalink
Remove initial dilute nuclides in depletion (#2568)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano authored Jun 21, 2023
1 parent 2536cae commit 8ce5c73
Show file tree
Hide file tree
Showing 25 changed files with 708 additions and 813 deletions.
7 changes: 0 additions & 7 deletions docs/source/io_formats/depletion_results.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,3 @@ The current version of the depletion results file format is 1.1.
**/reactions/<name>/**

:Attributes: - **index** (*int*) -- Index user in results for this reaction

.. note::

The reaction rates for some isotopes not originally present may
be non-zero, but should be negligible compared to other atoms.
This can be controlled by changing the
:class:`openmc.deplete.Operator` ``dilute_initial`` attribute.
24 changes: 1 addition & 23 deletions openmc/deplete/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,11 @@ class TransportOperator(ABC):
fission_q : dict, optional
Dictionary of nuclides and their fission Q values [eV]. If not given,
values will be pulled from the ``chain_file``.
dilute_initial : float, optional
Initial atom density [atoms/cm^3] to add for nuclides that are zero
in initial condition to ensure they exist in the decay chain.
Only done for nuclides with reaction rates.
Defaults to 1.0e3.
prev_results : Results, optional
Results from a previous depletion calculation.
Attributes
----------
dilute_initial : float
Initial atom density [atoms/cm^3] to add for nuclides that are zero
in initial condition to ensure they exist in the decay chain.
Only done for nuclides with reaction rates.
output_dir : pathlib.Path
Path to output directory to save results.
prev_res : Results or None
Expand All @@ -116,9 +107,7 @@ class TransportOperator(ABC):
The depletion chain information necessary to form matrices and tallies.
"""
def __init__(self, chain_file, fission_q=None, dilute_initial=1.0e3,
prev_results=None):
self.dilute_initial = dilute_initial
def __init__(self, chain_file, fission_q=None, prev_results=None):
self.output_dir = '.'

# Read depletion chain
Expand All @@ -129,17 +118,6 @@ def __init__(self, chain_file, fission_q=None, dilute_initial=1.0e3,
check_type("previous results", prev_results, Results)
self.prev_res = prev_results

@property
def dilute_initial(self):
"""Initial atom density for nuclides with zero initial concentration"""
return self._dilute_initial

@dilute_initial.setter
def dilute_initial(self, value):
check_type("dilute_initial", value, Real)
check_greater_than("dilute_initial", value, 0.0, equality=True)
self._dilute_initial = value

@abstractmethod
def __call__(self, vec, source_rate):
"""Runs a simulation.
Expand Down
11 changes: 1 addition & 10 deletions openmc/deplete/coupled_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ class CoupledOperator(OpenMCOperator):
Dictionary of nuclides and their fission Q values [eV]. If not given,
values will be pulled from the ``chain_file``. Only applicable
if ``"normalization_mode" == "fission-q"``
dilute_initial : float, optional
Initial atom density [atoms/cm^3] to add for nuclides that are zero
in initial condition to ensure they exist in the decay chain.
Only done for nuclides with reaction rates.
fission_yield_mode : {"constant", "cutoff", "average"}
Key indicating what fission product yield scheme to use. The
key determines what fission energy helper is used:
Expand Down Expand Up @@ -177,10 +173,6 @@ class CoupledOperator(OpenMCOperator):
OpenMC geometry object
settings : openmc.Settings
OpenMC settings object
dilute_initial : float
Initial atom density [atoms/cm^3] to add for nuclides that
are zero in initial condition to ensure they exist in the decay
chain. Only done for nuclides with reaction rates.
output_dir : pathlib.Path
Path to output directory to save results.
round_number : bool
Expand Down Expand Up @@ -215,7 +207,7 @@ class CoupledOperator(OpenMCOperator):

def __init__(self, model, chain_file=None, prev_results=None,
diff_burnable_mats=False, normalization_mode="fission-q",
fission_q=None, dilute_initial=1.0e3,
fission_q=None,
fission_yield_mode="constant", fission_yield_opts=None,
reaction_rate_mode="direct", reaction_rate_opts=None,
reduce_chain=False, reduce_chain_level=None):
Expand Down Expand Up @@ -271,7 +263,6 @@ def __init__(self, model, chain_file=None, prev_results=None,
prev_results,
diff_burnable_mats,
fission_q,
dilute_initial,
helper_kwargs,
reduce_chain,
reduce_chain_level)
Expand Down
16 changes: 0 additions & 16 deletions openmc/deplete/independent_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ class IndependentOperator(OpenMCOperator):
Dictionary of nuclides and their fission Q values [eV]. If not given,
values will be pulled from the ``chain_file``. Only applicable
if ``"normalization_mode" == "fission-q"``.
dilute_initial : float, optional
Initial atom density [atoms/cm^3] to add for nuclides that are zero
in initial condition to ensure they exist in the decay chain.
Only done for nuclides with reaction rates.
reduce_chain : bool, optional
If True, use :meth:`openmc.deplete.Chain.reduce` to reduce the
depletion chain up to ``reduce_chain_level``.
Expand All @@ -86,10 +82,6 @@ class IndependentOperator(OpenMCOperator):
All materials present in the model
cross_sections : MicroXS
Object containing one-group cross-sections in [cm^2].
dilute_initial : float
Initial atom density [atoms/cm^3] to add for nuclides that
are zero in initial condition to ensure they exist in the decay
chain. Only done for nuclides with reaction rates.
output_dir : pathlib.Path
Path to output directory to save results.
round_number : bool
Expand Down Expand Up @@ -122,7 +114,6 @@ def __init__(self,
keff=None,
normalization_mode='fission-q',
fission_q=None,
dilute_initial=1.0e3,
prev_results=None,
reduce_chain=False,
reduce_chain_level=None,
Expand All @@ -148,7 +139,6 @@ def __init__(self,
chain_file,
prev_results,
fission_q=fission_q,
dilute_initial=dilute_initial,
helper_kwargs=helper_kwargs,
reduce_chain=reduce_chain,
reduce_chain_level=reduce_chain_level)
Expand All @@ -161,7 +151,6 @@ def from_nuclides(cls, volume, nuclides,
keff=None,
normalization_mode='fission-q',
fission_q=None,
dilute_initial=1.0e3,
prev_results=None,
reduce_chain=False,
reduce_chain_level=None,
Expand Down Expand Up @@ -196,10 +185,6 @@ def from_nuclides(cls, volume, nuclides,
Dictionary of nuclides and their fission Q values [eV]. If not
given, values will be pulled from the ``chain_file``. Only
applicable if ``"normalization_mode" == "fission-q"``.
dilute_initial : float
Initial atom density [atoms/cm^3] to add for nuclides that
are zero in initial condition to ensure they exist in the decay
chain. Only done for nuclides with reaction rates.
prev_results : Results, optional
Results from a previous depletion calculation.
reduce_chain : bool, optional
Expand All @@ -224,7 +209,6 @@ def from_nuclides(cls, volume, nuclides,
keff=keff,
normalization_mode=normalization_mode,
fission_q=fission_q,
dilute_initial=dilute_initial,
prev_results=prev_results,
reduce_chain=reduce_chain,
reduce_chain_level=reduce_chain_level,
Expand Down
19 changes: 2 additions & 17 deletions openmc/deplete/openmc_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ class OpenMCOperator(TransportOperator):
Volumes are divided equally from the original material volume.
fission_q : dict, optional
Dictionary of nuclides and their fission Q values [eV].
dilute_initial : float, optional
Initial atom density [atoms/cm^3] to add for nuclides that are zero
in initial condition to ensure they exist in the decay chain.
Only done for nuclides with reaction rates.
helper_kwargs : dict
Keyword arguments for helper classes
reduce_chain : bool, optional
Expand All @@ -68,10 +64,6 @@ class OpenMCOperator(TransportOperator):
cross_sections : str or MicroXS
Path to continuous energy cross section library, or object
containing one-group cross-sections.
dilute_initial : float
Initial atom density [atoms/cm^3] to add for nuclides that
are zero in initial condition to ensure they exist in the decay
chain. Only done for nuclides with reaction rates.
output_dir : pathlib.Path
Path to output directory to save results.
round_number : bool
Expand Down Expand Up @@ -105,7 +97,6 @@ def __init__(
prev_results=None,
diff_burnable_mats=False,
fission_q=None,
dilute_initial=0.0,
helper_kwargs=None,
reduce_chain=False,
reduce_chain_level=None):
Expand All @@ -119,7 +110,7 @@ def __init__(
"chain in openmc.config['chain_file']"
)

super().__init__(chain_file, fission_q, dilute_initial, prev_results)
super().__init__(chain_file, fission_q, prev_results)
self.round_number = False
self.materials = materials
self.cross_sections = cross_sections
Expand Down Expand Up @@ -265,11 +256,6 @@ def _extract_number(self, local_mats, volume, all_nuclides, prev_res=None):
"""
self.number = AtomNumber(local_mats, all_nuclides, volume, len(self.chain))

if self.dilute_initial != 0.0:
for nuc in self._burnable_nucs:
self.number.set_atom_density(
np.s_[:], nuc, self.dilute_initial)

# Now extract and store the number densities
# From the geometry if no previous depletion results
if prev_res is None:
Expand Down Expand Up @@ -433,8 +419,7 @@ def _get_reaction_nuclides(self):
# for burning in which the number density is greater than zero.
for nuc in self.number.nuclides:
if nuc in self.nuclides_with_data:
if np.sum(self.number[:, nuc]) > 0.0:
nuc_set.add(nuc)
nuc_set.add(nuc)

# Communicate which nuclides have nonzeros to rank 0
if comm.rank == 0:
Expand Down
15 changes: 0 additions & 15 deletions openmc/deplete/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ def get_atoms(
) -> Tuple[np.ndarray, np.ndarray]:
"""Get number of nuclides over time from a single material
.. note::
Initial values for some isotopes that do not appear in
initial concentrations may be non-zero, depending on the
value of the :attr:`openmc.deplete.CoupledOperator.dilute_initial`
attribute. The :class:`openmc.deplete.CoupledOperator` class adds
isotopes according to this setting, which can be set to zero.
Parameters
----------
mat : openmc.Material, str
Expand Down Expand Up @@ -172,14 +165,6 @@ def get_reaction_rate(
) -> Tuple[np.ndarray, np.ndarray]:
"""Get reaction rate in a single material/nuclide over time
.. note::
Initial values for some isotopes that do not appear in
initial concentrations may be non-zero, depending on the
value of :class:`openmc.deplete.CoupledOperator` ``dilute_initial``
The :class:`openmc.deplete.CoupledOperator` adds isotopes according
to this setting, which can be set to zero.
Parameters
----------
mat : openmc.Material, str
Expand Down
9 changes: 6 additions & 3 deletions src/tallies/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,10 +1258,13 @@ extern "C" int openmc_tally_set_nuclides(
} else {
auto search = data::nuclide_map.find(word);
if (search == data::nuclide_map.end()) {
set_errmsg("Nuclide \"" + word + "\" has not been loaded yet");
return OPENMC_E_DATA;
int err = openmc_load_nuclide(word.c_str(), nullptr, 0);
if (err < 0) {
set_errmsg(openmc_err_msg);
return OPENMC_E_DATA;
}
}
nucs.push_back(search->second);
nucs.push_back(data::nuclide_map.at(word));
}
}

Expand Down
24 changes: 24 additions & 0 deletions tests/regression_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

# Test configuration options for regression tests
config = {
'event' : False,
Expand All @@ -8,3 +10,25 @@
'update': False,
'build_inputs': False
}


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:
_, y_test = res_test.get_atoms(mat, nuc)
_, y_ref = res_ref.get_atoms(mat, nuc)
assert y_test == pytest.approx(y_ref, rel=tol), \
f'Atoms not equal for material {mat}, nuclide {nuc}\n' \
f'y_ref={y_ref}\ny_test={y_test}'


def assert_reaction_rates_equal(res_ref, res_test, tol=1e-5):
for reactions in res_test[0].rates:
for mat in reactions.index_mat:
for nuc in reactions.index_nuc:
for rx in reactions.index_rx:
y_test = res_test.get_reaction_rate(mat, nuc, rx)[1]
y_ref = res_ref.get_reaction_rate(mat, nuc, rx)[1]
assert y_test == pytest.approx(y_ref, rel=tol), \
f'Reaction rate not equal for material {mat}, nuclide '\
f'{nuc}, {rx}\ny_ref={y_ref}\ny_test={y_test}'
Loading

0 comments on commit 8ce5c73

Please sign in to comment.