Changes in deplete/result*.py from PullRequest Inc. review

This commit is contained in:
Paul Romano 2020-04-14 16:09:08 -05:00
parent ac8b5e574f
commit 6468a027b1
2 changed files with 33 additions and 33 deletions

View file

@ -12,7 +12,7 @@ import numpy as np
from . import comm, have_mpi, MPI
from .reaction_rates import ReactionRates
_VERSION_RESULTS = (1, 0)
VERSION_RESULTS = (1, 0)
__all__ = ["Results"]
@ -174,8 +174,8 @@ class Results:
"""
new = Results()
new.volume = {lm: self.volume[lm] for lm in local_materials}
new.mat_to_ind = dict(zip(
local_materials, range(len(local_materials))))
new.mat_to_ind = {mat: idx for (idx, mat) in enumerate(local_materials)}
# Direct transfer
direct_attrs = ("time", "k", "power", "nuc_to_ind",
"mat_to_hdf5_ind", "proc_time")
@ -228,7 +228,7 @@ class Results:
# Store concentration mat and nuclide dictionaries (along with volumes)
handle.attrs['version'] = np.array(_VERSION_RESULTS)
handle.attrs['version'] = np.array(VERSION_RESULTS)
handle.attrs['filetype'] = np.string_('depletion results')
mat_list = sorted(self.mat_to_hdf5_ind, key=int)

View file

@ -1,7 +1,7 @@
import h5py
import numpy as np
from .results import Results, _VERSION_RESULTS
from .results import Results, VERSION_RESULTS
from openmc.checkvalue import check_filetype_version, check_value
@ -30,7 +30,7 @@ class ResultsList(list):
New instance of depletion results
"""
with h5py.File(str(filename), "r") as fh:
check_filetype_version(fh, 'depletion results', _VERSION_RESULTS[0])
check_filetype_version(fh, 'depletion results', VERSION_RESULTS[0])
new = cls()
# Get number of results stored
@ -68,9 +68,9 @@ class ResultsList(list):
Returns
-------
time : numpy.ndarray
times : numpy.ndarray
Array of times in units of ``time_units``
concentration : numpy.ndarray
concentrations : numpy.ndarray
Concentration of specified nuclide in units of ``nuc_units``
"""
@ -78,30 +78,30 @@ class ResultsList(list):
check_value("nuc_units", nuc_units,
{"atoms", "atom/b-cm", "atom/cm3"})
time = np.empty_like(self, dtype=float)
concentration = np.empty_like(self, dtype=float)
times = np.empty_like(self, dtype=float)
concentrations = np.empty_like(self, dtype=float)
# Evaluate value in each region
for i, result in enumerate(self):
time[i] = result.time[0]
concentration[i] = result[0, mat, nuc]
times[i] = result.time[0]
concentrations[i] = result[0, mat, nuc]
# Unit conversions
if time_units == "d":
time /= (60 * 60 * 24)
times /= (60 * 60 * 24)
elif time_units == "h":
time /= (60 * 60)
times /= (60 * 60)
elif time_units == "min":
time /= 60
times /= 60
if nuc_units != "atoms":
# Divide by volume to get density
concentration /= self[0].volume[mat]
concentrations /= self[0].volume[mat]
if nuc_units == "atom/b-cm":
# 1 barn = 1e-24 cm^2
concentration *= 1e-24
concentrations *= 1e-24
return time, concentration
return times, concentrations
def get_reaction_rate(self, mat, nuc, rx):
"""Get reaction rate in a single material/nuclide over time
@ -125,44 +125,44 @@ class ResultsList(list):
Returns
-------
time : numpy.ndarray
times : numpy.ndarray
Array of times in [s]
rate : numpy.ndarray
rates : numpy.ndarray
Array of reaction rates
"""
time = np.empty_like(self, dtype=float)
rate = np.empty_like(self, dtype=float)
times = np.empty_like(self, dtype=float)
rates = np.empty_like(self, dtype=float)
# Evaluate value in each region
for i, result in enumerate(self):
time[i] = result.time[0]
rate[i] = result.rates[0].get(mat, nuc, rx) * result[0, mat, nuc]
times[i] = result.time[0]
rates[i] = result.rates[0].get(mat, nuc, rx) * result[0, mat, nuc]
return time, rate
return times, rates
def get_eigenvalue(self):
"""Evaluates the eigenvalue from a results list.
Returns
-------
time : numpy.ndarray
times : numpy.ndarray
Array of times in [s]
eigenvalue : numpy.ndarray
eigenvalues : numpy.ndarray
k-eigenvalue at each time. Column 0
contains the eigenvalue, while column
1 contains the associated uncertainty
"""
time = np.empty_like(self, dtype=float)
eigenvalue = np.empty((len(self), 2), dtype=float)
times = np.empty_like(self, dtype=float)
eigenvalues = np.empty((len(self), 2), dtype=float)
# Get time/eigenvalue at each point
for i, result in enumerate(self):
time[i] = result.time[0]
eigenvalue[i] = result.k[0]
times[i] = result.time[0]
eigenvalues[i] = result.k[0]
return time, eigenvalue
return times, eigenvalues
def get_depletion_time(self):
"""Return an array of the average time to deplete a material
@ -175,7 +175,7 @@ class ResultsList(list):
Returns
-------
times : :class:`numpy.ndarray`
times : numpy.ndarray
Vector of average time to deplete a single material
across all processes and materials.