From a86c3481d682743cb6d78735a56b6cffd46385c0 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sat, 21 Mar 2020 10:15:32 -0400 Subject: [PATCH] ResultList.get_atoms supports atom densities, days Two new optional arguments to ResultsList.get_atoms are introduced that control the units on the return values. Time can be returned in second or in days if time_units is "s" or "d", respectively. Concentrations can be returned in atoms/cm^3 or atoms/b/cm if nuc_units is one of those values. The default is to return time in seconds and number of atoms, retaining back compatibility. --- openmc/deplete/results_list.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/openmc/deplete/results_list.py b/openmc/deplete/results_list.py index 1b5b81ac4c..9e7cd9ffb9 100644 --- a/openmc/deplete/results_list.py +++ b/openmc/deplete/results_list.py @@ -2,7 +2,7 @@ import h5py import numpy as np from .results import Results, _VERSION_RESULTS -from openmc.checkvalue import check_filetype_version +from openmc.checkvalue import check_filetype_version, check_value __all__ = ["ResultsList"] @@ -40,7 +40,7 @@ class ResultsList(list): new.append(Results.from_hdf5(fh, i)) return new - def get_atoms(self, mat, nuc): + def get_atoms(self, mat, nuc, nuc_units="atoms", time_units="s"): """Get number of nuclides over time from a single material .. note:: @@ -57,15 +57,24 @@ class ResultsList(list): Material name to evaluate nuc : str Nuclide name to evaluate + nuc_units : {"atoms", "atoms/b/cm", "atoms/cm^3"}, optional + Units for the returned concentration. Default is ``"atoms"`` + time_units : {"s", "d"}, optional + Units for the returned time array. Default is ``"s"`` to + return the value in seconds Returns ------- time : numpy.ndarray - Array of times in [s] + Array of times in units of ``time_units`` concentration : numpy.ndarray - Total number of atoms for specified nuclide + Concentration of specified nuclide in units of ``nuc_units`` """ + check_value("time_units", time_units, {"s", "d"}) + check_value("nuc_units", nuc_units, + {"atoms", "atoms/b/cm", "atoms/cm^3"}) + time = np.empty_like(self, dtype=float) concentration = np.empty_like(self, dtype=float) @@ -74,6 +83,17 @@ class ResultsList(list): time[i] = result.time[0] concentration[i] = result[0, mat, nuc] + # Unit conversions + if time_units == "d": + time /= (60 * 60 * 24) + + if nuc_units != "atoms": + # Divide by volume to get density + concentration /= self[0].volume[mat] + if nuc_units == "atoms/b/cm": + # 1 barn = 1e-24 cm^2 + concentration *= 1e-24 + return time, concentration def get_reaction_rate(self, mat, nuc, rx):