minimal changes to allow mat objects not id strings

This commit is contained in:
Jonathan Shimwell 2022-03-03 18:14:17 +00:00
parent 0424631b4f
commit 51b6d59105
6 changed files with 33 additions and 18 deletions

View file

@ -86,6 +86,8 @@ class Results:
"""
stage, mat, nuc = pos
if isinstance(mat, openmc.Material):
mat = str(mat.id)
if isinstance(mat, str):
mat = self.mat_to_ind[mat]
if isinstance(nuc, str):

View file

@ -58,8 +58,8 @@ class ResultsList(list):
Parameters
----------
mat : str
Material name to evaluate
mat : openmc.Material
Material object to evaluate
nuc : str
Nuclide name to evaluate
nuc_units : {"atoms", "atom/b-cm", "atom/cm3"}, optional
@ -84,13 +84,14 @@ class ResultsList(list):
cv.check_value("nuc_units", nuc_units,
{"atoms", "atom/b-cm", "atom/cm3"})
mat_id = str(mat.id)
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):
times[i] = result.time[0]
concentrations[i] = result[0, mat, nuc]
concentrations[i] = result[0, mat_id, nuc]
# Unit conversions
if time_units == "d":
@ -102,7 +103,7 @@ class ResultsList(list):
if nuc_units != "atoms":
# Divide by volume to get density
concentrations /= self[0].volume[mat]
concentrations /= self[0].volume[mat_id]
if nuc_units == "atom/b-cm":
# 1 barn = 1e-24 cm^2
concentrations *= 1e-24
@ -122,8 +123,8 @@ class ResultsList(list):
Parameters
----------
mat : str
Material name to evaluate
mat : openmc.Material
Material object to evaluate
nuc : str
Nuclide name to evaluate
rx : str
@ -143,7 +144,7 @@ class ResultsList(list):
# Evaluate value in each region
for i, result in enumerate(self):
times[i] = result.time[0]
rates[i] = result.rates[0].get(mat, nuc, rx) * result[0, mat, nuc]
rates[i] = result.rates[0].get(str(mat.id), nuc, rx) * result[0, mat, nuc]
return times, rates

View file

@ -108,7 +108,7 @@ def test_activation(run_in_tmpdir, model, reaction_rate_mode, reaction_rate_opts
# Get resulting number of atoms
results = openmc.deplete.ResultsList.from_hdf5('depletion_results.h5')
_, atoms = results.get_atoms(str(w.id), "W186")
_, atoms = results.get_atoms(w.id, "W186")
assert atoms[0] == pytest.approx(n0)
assert atoms[1] / atoms[0] == pytest.approx(0.5, rel=tolerance)
@ -156,7 +156,7 @@ def test_decay(run_in_tmpdir):
# Get resulting number of atoms
results = openmc.deplete.ResultsList.from_hdf5('depletion_results.h5')
_, atoms = results.get_atoms(str(mat.id), "Sr89")
_, atoms = results.get_atoms(mat, "Sr89")
# Ensure density goes down by a factor of 2 after each half-life
assert atoms[1] / atoms[0] == pytest.approx(0.5)

View file

@ -14,6 +14,7 @@ import numpy as np
from uncertainties import ufloat
import pytest
from openmc import Material
from openmc.mpi import comm
from openmc.deplete import (
ReactionRates, Results, ResultsList, OperatorResult, PredictorIntegrator,
@ -179,8 +180,11 @@ def test_integrator(run_in_tmpdir, scheme):
res = ResultsList.from_hdf5(
operator.output_dir / "depletion_results.h5")
t1, y1 = res.get_atoms("1", "1")
t2, y2 = res.get_atoms("1", "2")
mat = Material()
mat.id = 1
t1, y1 = res.get_atoms(mat, "1")
t2, y2 = res.get_atoms(mat, "2")
assert (t1 == [0.0, 0.75, 1.5]).all()
assert y1 == pytest.approx(bundle.atoms_1)

View file

@ -87,8 +87,11 @@ def test_restart(run_in_tmpdir, scheme):
results = openmc.deplete.ResultsList.from_hdf5(
operator.output_dir / "depletion_results.h5")
_t, y1 = results.get_atoms("1", "1")
_t, y2 = results.get_atoms("1", "2")
mat = openmc.Material()
mat.id = 1
_t, y1 = results.get_atoms(mat, "1")
_t, y2 = results.get_atoms(mat, "2")
assert y1 == pytest.approx(bundle.atoms_1)
assert y2 == pytest.approx(bundle.atoms_2)

View file

@ -18,7 +18,10 @@ def res():
def test_get_atoms(res):
"""Tests evaluating single nuclide concentration."""
t, n = res.get_atoms("1", "Xe135")
mat = openmc.Material()
mat.id = 1
t, n = res.get_atoms(mat, "Xe135")
t_ref = np.array([0.0, 1296000.0, 2592000.0, 3888000.0])
n_ref = np.array(
@ -30,22 +33,24 @@ def test_get_atoms(res):
# Check alternate units
volume = res[0].volume["1"]
t_days, n_cm3 = res.get_atoms("1", "Xe135", nuc_units="atom/cm3", time_units="d")
t_days, n_cm3 = res.get_atoms(mat, "Xe135", nuc_units="atom/cm3", time_units="d")
assert t_days == pytest.approx(t_ref / (60 * 60 * 24))
assert n_cm3 == pytest.approx(n_ref / volume)
t_min, n_bcm = res.get_atoms("1", "Xe135", nuc_units="atom/b-cm", time_units="min")
t_min, n_bcm = res.get_atoms(mat, "Xe135", nuc_units="atom/b-cm", time_units="min")
assert n_bcm == pytest.approx(n_cm3 * 1e-24)
assert t_min == pytest.approx(t_ref / 60)
t_hour, _n = res.get_atoms("1", "Xe135", time_units="h")
t_hour, _n = res.get_atoms(mat, "Xe135", time_units="h")
assert t_hour == pytest.approx(t_ref / (60 * 60))
def test_get_reaction_rate(res):
"""Tests evaluating reaction rate."""
t, r = res.get_reaction_rate("1", "Xe135", "(n,gamma)")
mat = openmc.Material()
mat.id = 1
t, r = res.get_reaction_rate(mat, "Xe135", "(n,gamma)")
t_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
n_ref = [6.67473282e+08, 3.72442707e+14, 3.61129692e+14, 4.01920099e+14]