Merge pull request #2047 from paulromano/dep-res-timeunits

Add time_units argument to ResultsList.get_eigenvalue
This commit is contained in:
Paul Romano 2022-05-02 12:05:53 -05:00 committed by GitHub
commit 99b128c421
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 22 deletions

View file

@ -14,6 +14,17 @@ from openmc.exceptions import DataError, InvalidArgumentError
__all__ = ["ResultsList"]
def _get_time_as(seconds, units):
if units == "d":
return seconds / (60 * 60 * 24)
elif units == "h":
return seconds / (60 * 60)
elif units == "min":
return seconds / 60
else:
return seconds
class ResultsList(list):
"""A list of openmc.deplete.Results objects
@ -99,13 +110,7 @@ class ResultsList(list):
concentrations[i] = result[0, mat_id, nuc]
# Unit conversions
if time_units == "d":
times /= (60 * 60 * 24)
elif time_units == "h":
times /= (60 * 60)
elif time_units == "min":
times /= 60
times = _get_time_as(times, time_units)
if nuc_units != "atoms":
# Divide by volume to get density
concentrations /= self[0].volume[mat_id]
@ -160,19 +165,26 @@ class ResultsList(list):
return times, rates
def get_eigenvalue(self):
def get_eigenvalue(self, time_units='s'):
"""Evaluates the eigenvalue from a results list.
Parameters
----------
time_units : {"s", "d", "h", "min"}, optional
Desired units for the times array
Returns
-------
times : numpy.ndarray
Array of times in [s]
Array of times in specified units
eigenvalues : numpy.ndarray
k-eigenvalue at each time. Column 0
contains the eigenvalue, while column
1 contains the associated uncertainty
"""
cv.check_value("time_units", time_units, {"s", "d", "min", "h"})
times = np.empty_like(self, dtype=float)
eigenvalues = np.empty((len(self), 2), dtype=float)
@ -181,6 +193,8 @@ class ResultsList(list):
times[i] = result.time[0]
eigenvalues[i] = result.k[0]
# Convert time units if necessary
times = _get_time_as(times, time_units)
return times, eigenvalues
def get_depletion_time(self):
@ -230,7 +244,7 @@ class ResultsList(list):
1-D vector of time points
"""
cv.check_type("time_units", time_units, str)
cv.check_value("time_units", time_units, {"s", "d", "min", "h"})
times = np.fromiter(
(r.time[0] for r in self),
@ -238,18 +252,7 @@ class ResultsList(list):
count=len(self),
)
if time_units == "d":
times /= (60 * 60 * 24)
elif time_units == "h":
times /= (60 * 60)
elif time_units == "min":
times /= 60
elif time_units != "s":
raise ValueError(
'Unable to set "time_units" to {} since it is not '
'in ("s", "d", "min", "h")'.format(time_units)
)
return times
return _get_time_as(times, time_units)
def get_step_where(
self, time, time_units="d", atol=1e-6, rtol=1e-3

View file

@ -58,12 +58,14 @@ def test_get_reaction_rate(res):
def test_get_eigenvalue(res):
"""Tests evaluating eigenvalue."""
t, k = res.get_eigenvalue()
t_min, k = res.get_eigenvalue(time_units='min')
t_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
k_ref = [1.21409662, 1.16518654, 1.25357797, 1.22611968]
u_ref = [0.0278795195, 0.0233141097, 0.0167899218, 0.0246734716]
np.testing.assert_allclose(t, t_ref)
np.testing.assert_allclose(t_min * 60, t_ref)
np.testing.assert_allclose(k[:, 0], k_ref)
np.testing.assert_allclose(k[:, 1], u_ref)