diff --git a/openmc/deplete/results_list.py b/openmc/deplete/results_list.py index 0ce5b01584..8a0efcdbf1 100644 --- a/openmc/deplete/results_list.py +++ b/openmc/deplete/results_list.py @@ -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 diff --git a/tests/regression_tests/deplete/test.py b/tests/regression_tests/deplete/test.py index 059a44ea35..d81bf607b9 100644 --- a/tests/regression_tests/deplete/test.py +++ b/tests/regression_tests/deplete/test.py @@ -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: diff --git a/tests/unit_tests/test_deplete_cecm.py b/tests/unit_tests/test_deplete_cecm.py index dd8b769fe6..f979e0b4d9 100644 --- a/tests/unit_tests/test_deplete_cecm.py +++ b/tests/unit_tests/test_deplete_cecm.py @@ -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") diff --git a/tests/unit_tests/test_deplete_celi.py b/tests/unit_tests/test_deplete_celi.py index 47d3319fdb..ffa5c304c3 100644 --- a/tests/unit_tests/test_deplete_celi.py +++ b/tests/unit_tests/test_deplete_celi.py @@ -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") diff --git a/tests/unit_tests/test_deplete_cf4.py b/tests/unit_tests/test_deplete_cf4.py index 0c6199c3e5..aee373b406 100644 --- a/tests/unit_tests/test_deplete_cf4.py +++ b/tests/unit_tests/test_deplete_cf4.py @@ -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") diff --git a/tests/unit_tests/test_deplete_epc_rk4.py b/tests/unit_tests/test_deplete_epc_rk4.py index ea687bfd5d..1b0af0365a 100644 --- a/tests/unit_tests/test_deplete_epc_rk4.py +++ b/tests/unit_tests/test_deplete_epc_rk4.py @@ -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") diff --git a/tests/unit_tests/test_deplete_integrator.py b/tests/unit_tests/test_deplete_integrator.py index 40090264ae..b8429392ff 100644 --- a/tests/unit_tests/test_deplete_integrator.py +++ b/tests/unit_tests/test_deplete_integrator.py @@ -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): diff --git a/tests/unit_tests/test_deplete_leqi.py b/tests/unit_tests/test_deplete_leqi.py index a26329cf4a..ac477a36ec 100644 --- a/tests/unit_tests/test_deplete_leqi.py +++ b/tests/unit_tests/test_deplete_leqi.py @@ -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") diff --git a/tests/unit_tests/test_deplete_predictor.py b/tests/unit_tests/test_deplete_predictor.py index 6af6f8bca4..092ebbc35e 100644 --- a/tests/unit_tests/test_deplete_predictor.py +++ b/tests/unit_tests/test_deplete_predictor.py @@ -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") diff --git a/tests/unit_tests/test_deplete_restart.py b/tests/unit_tests/test_deplete_restart.py index ec62064a4e..4c0c68a2e3 100644 --- a/tests/unit_tests/test_deplete_restart.py +++ b/tests/unit_tests/test_deplete_restart.py @@ -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") diff --git a/tests/unit_tests/test_deplete_resultslist.py b/tests/unit_tests/test_deplete_resultslist.py index c4b7aceba5..c3ceda5d56 100644 --- a/tests/unit_tests/test_deplete_resultslist.py +++ b/tests/unit_tests/test_deplete_resultslist.py @@ -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): diff --git a/tests/unit_tests/test_deplete_si_celi.py b/tests/unit_tests/test_deplete_si_celi.py index 71679439c5..e4ea4f6acf 100644 --- a/tests/unit_tests/test_deplete_si_celi.py +++ b/tests/unit_tests/test_deplete_si_celi.py @@ -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") diff --git a/tests/unit_tests/test_deplete_si_leqi.py b/tests/unit_tests/test_deplete_si_leqi.py index 1396065c0f..cef64fbe88 100644 --- a/tests/unit_tests/test_deplete_si_leqi.py +++ b/tests/unit_tests/test_deplete_si_leqi.py @@ -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") diff --git a/tests/unit_tests/test_transfer_volumes.py b/tests/unit_tests/test_transfer_volumes.py index 9128ed9694..38520ea1e3 100644 --- a/tests/unit_tests/test_transfer_volumes.py +++ b/tests/unit_tests/test_transfer_volumes.py @@ -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