Create ResultsList from file using from_hdf5

The new class method ResultsList.from_hdf5 should be
used to load in results data, rather than passing
the file name into the __init__ method. __init__
passes directly to list.__init__ now.

The motivation for this is to resolve the depletion
restart with MPI bug #1275. To do this, each Operator
will create it's own ResultsList and distribute reaction
rates and densities according to what materials are burned
on this process. Rather than use a normal list, this Operator
expects the various accessor methods like get_atoms to be
present on self.prev_res
This commit is contained in:
Andrew Johnson 2019-08-05 16:08:11 -05:00
parent d6cbacf4b3
commit 0fdef55d42
No known key found for this signature in database
GPG key ID: 253418E91B7F6FEB
14 changed files with 54 additions and 42 deletions

View file

@ -8,22 +8,34 @@ from openmc.checkvalue import check_filetype_version
class ResultsList(list):
"""A list of openmc.deplete.Results objects
Parameters
----------
filename : str
The filename to read from.
It is recommended to use :meth:`from_hdf5` over
direct creation.
"""
def __init__(self, filename):
super().__init__()
@classmethod
def from_hdf5(cls, filename):
"""Load in depletion results from a previous file
Parameters
----------
filename : str
Path to depletion result file
Returns
-------
new : ResultsList
New instance of depletion results
"""
with h5py.File(str(filename), "r") as fh:
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):
self.append(Results.from_hdf5(fh, i))
new.append(Results.from_hdf5(fh, i))
return new
def get_atoms(self, mat, nuc):
"""Get number of nuclides over time from a single material

View file

@ -66,8 +66,8 @@ def test_full(run_in_tmpdir):
return
# Load the reference/test results
res_test = openmc.deplete.ResultsList(path_test)
res_ref = openmc.deplete.ResultsList(path_reference)
res_test = openmc.deplete.ResultsList.from_hdf5(path_test)
res_ref = openmc.deplete.ResultsList.from_hdf5(path_reference)
# Assert same mats
for mat in res_ref[0].mat_to_ind:

View file

@ -21,7 +21,7 @@ def test_cecm(run_in_tmpdir):
openmc.deplete.cecm(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")

View file

@ -21,7 +21,7 @@ def test_celi(run_in_tmpdir):
openmc.deplete.celi(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")

View file

@ -21,7 +21,7 @@ def test_cf4(run_in_tmpdir):
openmc.deplete.cf4(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")

View file

@ -21,7 +21,7 @@ def test_epc_rk4(run_in_tmpdir):
openmc.deplete.epc_rk4(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")

View file

@ -80,7 +80,7 @@ def test_results_save(run_in_tmpdir):
Results.save(op, x2, op_result2, t2, 0, 1)
# Load the files
res = ResultsList("depletion_results.h5")
res = ResultsList.from_hdf5("depletion_results.h5")
for i in range(stages):
for mat_i, mat in enumerate(burn_list):

View file

@ -21,7 +21,7 @@ def test_leqi(run_in_tmpdir):
openmc.deplete.leqi(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")

View file

@ -21,7 +21,7 @@ def test_predictor(run_in_tmpdir):
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")

View file

@ -23,7 +23,7 @@ def test_restart_predictor(run_in_tmpdir):
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -33,7 +33,7 @@ def test_restart_predictor(run_in_tmpdir):
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
@ -62,7 +62,7 @@ def test_restart_cecm(run_in_tmpdir):
openmc.deplete.cecm(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -72,7 +72,7 @@ def test_restart_cecm(run_in_tmpdir):
openmc.deplete.cecm(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
@ -102,7 +102,7 @@ def test_restart_predictor_cecm(run_in_tmpdir):
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -112,7 +112,7 @@ def test_restart_predictor_cecm(run_in_tmpdir):
openmc.deplete.cecm(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
@ -142,7 +142,7 @@ def test_restart_cecm_predictor(run_in_tmpdir):
openmc.deplete.cecm(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -152,7 +152,7 @@ def test_restart_cecm_predictor(run_in_tmpdir):
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
@ -181,7 +181,7 @@ def test_restart_cf4(run_in_tmpdir):
openmc.deplete.cf4(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -191,7 +191,7 @@ def test_restart_cf4(run_in_tmpdir):
openmc.deplete.cf4(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
@ -220,7 +220,7 @@ def test_restart_epc_rk4(run_in_tmpdir):
openmc.deplete.epc_rk4(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -230,7 +230,7 @@ def test_restart_epc_rk4(run_in_tmpdir):
openmc.deplete.epc_rk4(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
@ -259,7 +259,7 @@ def test_restart_celi(run_in_tmpdir):
openmc.deplete.celi(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -269,7 +269,7 @@ def test_restart_celi(run_in_tmpdir):
openmc.deplete.celi(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
@ -298,7 +298,7 @@ def test_restart_leqi(run_in_tmpdir):
openmc.deplete.leqi(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -308,7 +308,7 @@ def test_restart_leqi(run_in_tmpdir):
openmc.deplete.leqi(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
@ -336,7 +336,7 @@ def test_restart_si_celi(run_in_tmpdir):
openmc.deplete.si_celi(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -346,7 +346,7 @@ def test_restart_si_celi(run_in_tmpdir):
openmc.deplete.si_celi(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
@ -375,7 +375,7 @@ def test_restart_si_leqi(run_in_tmpdir):
openmc.deplete.si_leqi(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
@ -385,7 +385,7 @@ def test_restart_si_leqi(run_in_tmpdir):
openmc.deplete.si_leqi(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")

View file

@ -12,7 +12,7 @@ def res():
"""Load the reference results"""
filename = (Path(__file__).parents[1] / 'regression_tests' / 'deplete'
/ 'test_reference.h5')
return openmc.deplete.ResultsList(filename)
return openmc.deplete.ResultsList.from_hdf5(filename)
def test_get_atoms(res):

View file

@ -21,7 +21,7 @@ def test_si_celi(run_in_tmpdir):
openmc.deplete.si_celi(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")

View file

@ -21,7 +21,7 @@ def test_si_leqi(run_in_tmpdir):
openmc.deplete.si_leqi(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")

View file

@ -21,10 +21,10 @@ def test_transfer_volumes(run_in_tmpdir):
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
res = openmc.deplete.ResultsList.from_hdf5(op.output_dir / "depletion_results.h5")
# Create a dictionary of volumes to transfer
res[0].volume['1'] = 1.5
res[0].volume['1'] = 1.5
res[0].volume['2'] = 2.5
# Create dummy geometry