Fix a few warnings, rename add_to_tallies_file (#3639)

This commit is contained in:
Paul Romano 2025-11-18 17:57:12 -06:00 committed by GitHub
parent 7815d3a680
commit 5c63e0df21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 54 additions and 56 deletions

View file

@ -765,7 +765,7 @@ energy decomposition::
# Create a "tallies.xml" file for the MGXS Library
tallies = openmc.Tallies()
mgxs_lib.add_to_tallies_file(tallies, merge=True)
mgxs_lib.add_to_tallies(tallies, merge=True)
# Export
tallies.export_to_xml()

View file

@ -630,7 +630,7 @@ class Chain:
n = len(self)
# we accumulate indices and value entries for everything and create the matrix
# we accumulate indices and value entries for everything and create the matrix
# in one step at the end to avoid expensive index checks scipy otherwise does.
rows, cols, vals = [], [], []
def setval(i, j, val):
@ -716,14 +716,17 @@ class Chain:
return sp.csc_matrix((vals, (rows, cols)), shape=(n, n))
def add_redox_term(self, matrix, buffer, oxidation_states):
"""Adds a redox term to the depletion matrix from data contained in
r"""Adds a redox term to the depletion matrix from data contained in
the matrix itself and a few user-inputs.
The redox term to add to the buffer nuclide :math:`N_j` can be written
as: :math:`\frac{dN_j(t)}{dt} =
\cdots - \frac{1}{OS_j}\sum_i N_i a_{ij} \cdot OS_i `
as:
where :math:`OS` is the oxidation states vector and `a_{ij}` the
.. math::
\frac{dN_j(t)}{dt} = \cdots - \frac{1}{OS_j}\sum_i N_i a_{ij}
\cdot OS_i
where :math:`OS` is the oxidation states vector and :math:`a_{ij}` the
corresponding term in the Bateman matrix.
Parameters

View file

@ -556,14 +556,14 @@ class Library:
self.all_mgxs[domain.id][mgxs_type] = mgxs
def add_to_tallies_file(self, tallies_file, merge=True):
"""Add all tallies from all MGXS objects to a tallies file.
def add_to_tallies(self, tallies, merge=True):
"""Add tallies from all MGXS objects to a tallies object.
NOTE: This assumes that :meth:`Library.build_library` has been called
Parameters
----------
tallies_file : openmc.Tallies
tallies : openmc.Tallies
A Tallies collection to add each MGXS' tallies to generate a
'tallies.xml' input file for OpenMC
merge : bool
@ -572,7 +572,7 @@ class Library:
"""
cv.check_type('tallies_file', tallies_file, openmc.Tallies)
cv.check_type('tallies', tallies, openmc.Tallies)
# Add tallies from each MGXS for each domain and mgxs type
for domain in self.domains:
@ -587,7 +587,15 @@ class Library:
= list(range(1, self.num_delayed_groups + 1))
for tally in mgxs.tallies.values():
tallies_file.append(tally, merge=merge)
tallies.append(tally, merge=merge)
def add_to_tallies_file(self, tallies_file, merge=True):
warn(
"The Library.add_to_tallies_file(...) method has been renamed to"
"add_to_tallies(...) and will be removed in a future version of "
"OpenMC.", FutureWarning
)
self.add_to_tallies(tallies_file, merge=merge)
def load_from_statepoint(self, statepoint):
"""Extracts tallies in an OpenMC StatePoint with the data needed to

View file

@ -2127,8 +2127,8 @@ class MGXS:
df['std. dev.'] /= np.tile(densities, tile_factor)
# Replace NaNs by zeros (happens if nuclide density is zero)
df['mean'].replace(np.nan, 0.0, inplace=True)
df['std. dev.'].replace(np.nan, 0.0, inplace=True)
df['mean'] = df['mean'].replace(np.nan, 0.0)
df['std. dev.'] = df['std. dev.'].replace(np.nan, 0.0)
# Sort the dataframe by domain type id (e.g., distribcell id) and
# energy groups such that data is from fast to thermal

View file

@ -1791,7 +1791,7 @@ class Model:
mgxs_lib.build_library()
# Create a "tallies.xml" file for the MGXS Library
mgxs_lib.add_to_tallies_file(model.tallies, merge=True)
mgxs_lib.add_to_tallies(model.tallies, merge=True)
# Run
statepoint_filename = model.run(cwd=directory)
@ -1980,7 +1980,7 @@ class Model:
mgxs_lib.build_library()
# Create a "tallies.xml" file for the MGXS Library
mgxs_lib.add_to_tallies_file(model.tallies, merge=True)
mgxs_lib.add_to_tallies(model.tallies, merge=True)
# Run
statepoint_filename = model.run(cwd=directory)
@ -2075,7 +2075,7 @@ class Model:
mgxs_lib.build_library()
# Create a "tallies.xml" file for the MGXS Library
mgxs_lib.add_to_tallies_file(model.tallies, merge=True)
mgxs_lib.add_to_tallies(model.tallies, merge=True)
# Run
statepoint_filename = model.run(cwd=directory)

View file

@ -738,13 +738,9 @@ class Tally(IDManagerMixin):
Notes
-----
This test is based on D'Agostino and Pearson's test [1]_. The test
requires at least 8 realizations to produce valid results.
References
----------
.. [1] D'Agostino, R. B. (1971), "An omnibus test of normality for
moderate and large sample size", Biometrika, 58, 341-348
This test is based on `D'Agostino and Pearson's test
<https://doi.org/10.1093/biomet/60.3.613>`_. The test requires at least
8 realizations to produce valid results.
"""
n = self.num_realizations
@ -788,8 +784,8 @@ class Tally(IDManagerMixin):
Parameters
----------
alternative : {'two-sided', 'less', 'greater'}, optional
Defines the alternative hypothesis. Default is 'two-sided'.
The following options are available:
Defines the alternative hypothesis. Default is 'two-sided'. The
following options are available:
* 'two-sided': the kurtosis of the distribution is different from
that of the normal distribution
@ -813,14 +809,9 @@ class Tally(IDManagerMixin):
Notes
-----
This test is based on D'Agostino and Pearson's test [1]_. The test
is typically recommended for at least 20 realizations to produce
valid results.
References
----------
.. [1] D'Agostino, R. B. (1971), "An omnibus test of normality for
moderate and large sample size", Biometrika, 58, 341-348
This test is based on `D'Agostino and Pearson's test
<https://doi.org/10.1093/biomet/60.3.613>`_. The test is typically
recommended for at least 20 realizations to produce valid results.
"""
n = self.num_realizations
@ -855,9 +846,9 @@ class Tally(IDManagerMixin):
def normaltest(self, alternative: str = "two-sided"):
"""Perform D'Agostino and Pearson's omnibus test for normality.
This method tests the null hypothesis that a sample comes from a
normal distribution. It combines skewness and kurtosis to produce an
omnibus test of normality.
This method tests the null hypothesis that a sample comes from a normal
distribution. It combines skewness and kurtosis to produce an omnibus
test of normality.
Parameters
----------
@ -886,23 +877,19 @@ class Tally(IDManagerMixin):
Notes
-----
This test combines a test for skewness and a test for kurtosis to
produce an omnibus test [1]_. The test statistic is:
produce an `omnibus test <https://doi.org/10.1093/biomet/60.3.613>`_.
The test statistic is:
.. math::
K^2 = Z_1^2 + Z_2^2
where :math:`Z_1` is the z-score from the skewness test and
:math:`Z_2` is the z-score from the kurtosis test. This statistic
follows a chi-square distribution with 2 degrees of freedom.
where :math:`Z_1` is the z-score from the skewness test and :math:`Z_2`
is the z-score from the kurtosis test. This statistic follows a
chi-square distribution with 2 degrees of freedom.
The test requires at least 20 realizations to produce valid results.
References
----------
.. [1] D'Agostino, R. B. and Pearson, E. S. (1973), "Tests for
departure from normality", Biometrika, 60, 613-622
"""
n = self.num_realizations
if n < 20:

View file

@ -28,7 +28,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Initialize a tallies file
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=False)
def _run_openmc(self):
# Initial run

View file

@ -28,7 +28,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Initialize a tallies file
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=False)
def _run_openmc(self):
# Initial run

View file

@ -36,7 +36,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Add tallies
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=False)
def _get_results(self, hash_output=False):
"""Digest info in the statepoint and return as a string."""

View file

@ -29,7 +29,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Add tallies
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=False)
def _get_results(self, hash_output=False):
"""Digest info in the statepoint and return as a string."""

View file

@ -36,7 +36,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Add tallies
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=False)
self._model.tallies.export_to_xml()
def _get_results(self, hash_output=False):

View file

@ -40,7 +40,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Add tallies
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=False)
def _get_results(self, hash_output=False):
"""Digest info in the statepoint and return as a string."""

View file

@ -30,7 +30,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Add tallies
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=False)
def _get_results(self, hash_output=False):
"""Digest info in the statepoint and return as a string."""

View file

@ -57,7 +57,7 @@ def model():
model.mgxs_lib.build_library()
# Add tallies
model.mgxs_lib.add_to_tallies_file(model.tallies, merge=False)
model.mgxs_lib.add_to_tallies(model.tallies, merge=False)
return model

View file

@ -39,7 +39,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Add tallies
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=False)
def _get_results(self, hash_output=False):
"""Digest info in the statepoint and return as a string."""

View file

@ -36,7 +36,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Add tallies
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=False)
def _get_results(self, hash_output=True):
"""Digest info in the statepoint and return as a string."""

View file

@ -37,7 +37,7 @@ class MGXSTestHarness(PyAPITestHarness):
self.mgxs_lib.build_library()
# Add tallies
self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=True)
self.mgxs_lib.add_to_tallies(self._model.tallies, merge=True)
def _get_results(self, hash_output=True):
"""Digest info in the statepoint and return as a string."""