mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Allow normal instantiation of ResultsList (instead of from_hdf5)
This commit is contained in:
parent
fe230168fb
commit
0b77cc7edc
12 changed files with 48 additions and 34 deletions
|
|
@ -53,7 +53,7 @@ The coupled transport-depletion problem is executed, and once it is done a
|
|||
easy retrieval of k-effective, nuclide concentrations, and reaction rates over
|
||||
time::
|
||||
|
||||
results = openmc.deplete.ResultsList.from_hdf5("depletion_results.h5")
|
||||
results = openmc.deplete.ResultsList("depletion_results.h5")
|
||||
time, keff = results.get_keff()
|
||||
|
||||
Note that the coupling between the transport solver and the transmutation solver
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ with openmc.StatePoint(statepoint) as sp:
|
|||
geometry = sp.summary.geometry
|
||||
|
||||
# Load previous depletion results
|
||||
previous_results = openmc.deplete.ResultsList.from_hdf5("depletion_results.h5")
|
||||
previous_results = openmc.deplete.ResultsList("depletion_results.h5")
|
||||
|
||||
###############################################################################
|
||||
# Transport calculation settings
|
||||
|
|
@ -56,7 +56,7 @@ integrator.integrate()
|
|||
###############################################################################
|
||||
|
||||
# Open results file
|
||||
results = openmc.deplete.ResultsList.from_hdf5("depletion_results.h5")
|
||||
results = openmc.deplete.ResultsList("depletion_results.h5")
|
||||
|
||||
# Obtain K_eff as a function of time
|
||||
time, keff = results.get_keff(time_units='d')
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ integrator.integrate()
|
|||
###############################################################################
|
||||
|
||||
# Open results file
|
||||
results = openmc.deplete.ResultsList.from_hdf5("depletion_results.h5")
|
||||
results = openmc.deplete.ResultsList("depletion_results.h5")
|
||||
|
||||
# Obtain K_eff as a function of time
|
||||
time, keff = results.get_keff(time_units='d')
|
||||
|
|
|
|||
|
|
@ -842,7 +842,7 @@ class Integrator(ABC):
|
|||
k = ufloat(res.k[0, 0], res.k[0, 1])
|
||||
|
||||
# Scale reaction rates by ratio of source rates
|
||||
rates *= source_rate / res.source_rate[0]
|
||||
rates *= source_rate / res.source_rate
|
||||
return bos_conc, OperatorResult(k, rates)
|
||||
|
||||
def _get_start_data(self):
|
||||
|
|
|
|||
|
|
@ -69,6 +69,11 @@ class Results:
|
|||
|
||||
self.data = None
|
||||
|
||||
def __repr__(self):
|
||||
t = self.time[0]
|
||||
dt = self.time[1] - self.time[0]
|
||||
return f"<Results: t={t}, dt={dt}, source={self.source_rate}>"
|
||||
|
||||
def __getitem__(self, pos):
|
||||
"""Retrieves an item from results.
|
||||
|
||||
|
|
@ -406,7 +411,7 @@ class Results:
|
|||
results.data = number_dset[step, :, :, :]
|
||||
results.k = eigenvalues_dset[step, :]
|
||||
results.time = time_dset[step, :]
|
||||
results.source_rate = source_rate_dset[step, :]
|
||||
results.source_rate = source_rate_dset[step, 0]
|
||||
|
||||
if "depletion time" in handle:
|
||||
proc_time_dset = handle["/depletion time"]
|
||||
|
|
|
|||
|
|
@ -29,9 +29,24 @@ def _get_time_as(seconds, units):
|
|||
class ResultsList(list):
|
||||
"""A list of openmc.deplete.Results objects
|
||||
|
||||
It is recommended to use :meth:`from_hdf5` over
|
||||
direct creation.
|
||||
Parameters
|
||||
----------
|
||||
filename : str
|
||||
Path to depletion result file
|
||||
|
||||
"""
|
||||
def __init__(self, filename):
|
||||
with h5py.File(str(filename), "r") as fh:
|
||||
cv.check_filetype_version(fh, 'depletion results', VERSION_RESULTS[0])
|
||||
data = []
|
||||
|
||||
# Get number of results stored
|
||||
n = fh["number"][...].shape[0]
|
||||
|
||||
for i in range(n):
|
||||
data.append(Results.from_hdf5(fh, i))
|
||||
super().__init__(data)
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_hdf5(cls, filename):
|
||||
|
|
@ -46,17 +61,14 @@ class ResultsList(list):
|
|||
-------
|
||||
new : ResultsList
|
||||
New instance of depletion results
|
||||
|
||||
"""
|
||||
with h5py.File(str(filename), "r") as fh:
|
||||
cv.check_filetype_version(fh, 'depletion results', VERSION_RESULTS[0])
|
||||
new = cls()
|
||||
|
||||
# Get number of results stored
|
||||
n = fh["number"][...].shape[0]
|
||||
|
||||
for i in range(n):
|
||||
new.append(Results.from_hdf5(fh, i))
|
||||
return new
|
||||
warn(
|
||||
"The from_hdf5(...) method is no longer necessary and will be removed "
|
||||
"in a future version of OpenMC. Use ResultsList(...) instead.",
|
||||
FutureWarning
|
||||
)
|
||||
return cls(filename)
|
||||
|
||||
def get_atoms(self, mat, nuc, nuc_units="atoms", time_units="s"):
|
||||
"""Get number of nuclides over time from a single material
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ def test_full(run_in_tmpdir, problem, multiproc):
|
|||
return
|
||||
|
||||
# Load the reference/test results
|
||||
res_test = openmc.deplete.ResultsList.from_hdf5(path_test)
|
||||
res_ref = openmc.deplete.ResultsList.from_hdf5(path_reference)
|
||||
res_test = openmc.deplete.ResultsList(path_test)
|
||||
res_ref = openmc.deplete.ResultsList(path_reference)
|
||||
|
||||
# Assert same mats
|
||||
for mat in res_ref[0].mat_to_ind:
|
||||
|
|
@ -139,7 +139,7 @@ def test_depletion_results_to_material(run_in_tmpdir, problem):
|
|||
"""Checks openmc.Materials objects can be created from depletion results"""
|
||||
# Load the reference/test results
|
||||
path_reference = Path(__file__).with_name('test_reference.h5')
|
||||
res_ref = openmc.deplete.ResultsList.from_hdf5(path_reference)
|
||||
res_ref = openmc.deplete.ResultsList(path_reference)
|
||||
|
||||
# Firstly need to export materials.xml file for the initial simulation state
|
||||
geometry, lower_left, upper_right = problem
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ def test_activation(run_in_tmpdir, model, reaction_rate_mode, reaction_rate_opts
|
|||
integrator.integrate()
|
||||
|
||||
# Get resulting number of atoms
|
||||
results = openmc.deplete.ResultsList.from_hdf5('depletion_results.h5')
|
||||
results = openmc.deplete.ResultsList('depletion_results.h5')
|
||||
_, atoms = results.get_atoms(w, "W186")
|
||||
|
||||
assert atoms[0] == pytest.approx(n0)
|
||||
|
|
@ -155,7 +155,7 @@ def test_decay(run_in_tmpdir):
|
|||
integrator.integrate()
|
||||
|
||||
# Get resulting number of atoms
|
||||
results = openmc.deplete.ResultsList.from_hdf5('depletion_results.h5')
|
||||
results = openmc.deplete.ResultsList('depletion_results.h5')
|
||||
_, atoms = results.get_atoms(mat, "Sr89")
|
||||
|
||||
# Ensure density goes down by a factor of 2 after each half-life
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ def test_results_save(run_in_tmpdir):
|
|||
Results.save(op, x2, op_result2, t2, 0, 1)
|
||||
|
||||
# Load the files
|
||||
res = ResultsList.from_hdf5("depletion_results.h5")
|
||||
res = ResultsList("depletion_results.h5")
|
||||
|
||||
for i in range(stages):
|
||||
for mat_i, mat in enumerate(burn_list):
|
||||
|
|
@ -176,8 +176,7 @@ def test_integrator(run_in_tmpdir, scheme):
|
|||
|
||||
# get expected results
|
||||
|
||||
res = ResultsList.from_hdf5(
|
||||
operator.output_dir / "depletion_results.h5")
|
||||
res = ResultsList(operator.output_dir / "depletion_results.h5")
|
||||
|
||||
t1, y1 = res.get_atoms("1", "1")
|
||||
t2, y2 = res.get_atoms("1", "2")
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@ def test_restart_predictor_cecm(run_in_tmpdir):
|
|||
openmc.deplete.PredictorIntegrator(op, dt, power).integrate()
|
||||
|
||||
# Load the files
|
||||
prev_res = openmc.deplete.ResultsList.from_hdf5(
|
||||
op.output_dir / "depletion_results.h5")
|
||||
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
|
||||
|
||||
# Re-create depletion operator and load previous results
|
||||
op = dummy_operator.DummyOperator(prev_res)
|
||||
|
|
@ -51,8 +50,7 @@ def test_restart_cecm_predictor(run_in_tmpdir):
|
|||
cecm.integrate()
|
||||
|
||||
# Load the files
|
||||
prev_res = openmc.deplete.ResultsList.from_hdf5(
|
||||
op.output_dir / "depletion_results.h5")
|
||||
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
|
||||
|
||||
# Re-create depletion operator and load previous results
|
||||
op = dummy_operator.DummyOperator(prev_res)
|
||||
|
|
@ -75,7 +73,7 @@ def test_restart(run_in_tmpdir, scheme):
|
|||
bundle.solver(operator, [0.75], 1.0).integrate()
|
||||
|
||||
# restart
|
||||
prev_res = openmc.deplete.ResultsList.from_hdf5(
|
||||
prev_res = openmc.deplete.ResultsList(
|
||||
operator.output_dir / "depletion_results.h5")
|
||||
operator = dummy_operator.DummyOperator(prev_res)
|
||||
|
||||
|
|
@ -84,7 +82,7 @@ def test_restart(run_in_tmpdir, scheme):
|
|||
|
||||
# compare results
|
||||
|
||||
results = openmc.deplete.ResultsList.from_hdf5(
|
||||
results = openmc.deplete.ResultsList(
|
||||
operator.output_dir / "depletion_results.h5")
|
||||
|
||||
_t, y1 = results.get_atoms("1", "1")
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ def res():
|
|||
"""Load the reference results"""
|
||||
filename = (Path(__file__).parents[1] / 'regression_tests' / 'deplete'
|
||||
/ 'test_reference.h5')
|
||||
return openmc.deplete.ResultsList.from_hdf5(filename)
|
||||
return openmc.deplete.ResultsList(filename)
|
||||
|
||||
|
||||
def test_get_atoms(res):
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ def test_transfer_volumes(run_in_tmpdir):
|
|||
PredictorIntegrator(op, dt, power).integrate()
|
||||
|
||||
# Load the files
|
||||
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
|
||||
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
|
||||
|
||||
# Create a dictionary of volumes to transfer
|
||||
res[0].volume['1'] = 1.5
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue