Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make sure that continue runs with no previous results do not break
  • Loading branch information
lewisgross1296 committed Mar 4, 2025
commit f3358e4034c7b2bf99f084dc3c5e782470ce03b3
3 changes: 3 additions & 0 deletions openmc/deplete/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ def __init__(
"this uses {}".format(
self.__class__.__name__, res.data.shape[0],
self._num_stages))
else:
# if the user specifies a continue run without a previous results, set the flag to False for them
continue_timesteps = False
self.operator = operator
self.chain = operator.chain

Expand Down
45 changes: 27 additions & 18 deletions tests/unit_tests/test_deplete_continue.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,27 @@ def test_continue(run_in_tmpdir, scheme):

operator = dummy_operator.DummyOperator()

# take first step
bundle.solver(operator, [0.75], 1.0).integrate()
# initial depletion
bundle.solver(operator, [1.0, 2.0], [1.0, 2.0]).integrate()

# restart
prev_res = openmc.deplete.Results(
operator.output_dir / "depletion_results.h5")
# set up continue run
prev_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5")
operator = dummy_operator.DummyOperator(prev_res)

# if continue run happens, test passes
bundle.solver(operator, [0.75, 0.75], [1.0, 1.0], continue_timesteps=True).integrate()
bundle.solver(operator, [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0], continue_timesteps=True).integrate()

@pytest.mark.parametrize("scheme", dummy_operator.SCHEMES)
def test_continue_for_null_previous(run_in_tmpdir, scheme):
"""Test to ensure that a continue run works even if there are no previous results"""
# set up the problem

bundle = dummy_operator.SCHEMES[scheme]

operator = dummy_operator.DummyOperator()

# initial depletion
bundle.solver(operator, [1.0, 2.0], [1.0, 2.0], continue_timesteps=True).integrate()

@pytest.mark.parametrize("scheme", dummy_operator.SCHEMES)
def test_mismatched_initial_times(run_in_tmpdir, scheme):
Expand All @@ -45,21 +56,20 @@ def test_mismatched_initial_times(run_in_tmpdir, scheme):
bundle.solver(operator, [0.75, 0.75], [1.0, 1.0]).integrate()

# restart
prev_res = openmc.deplete.Results(
operator.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5")
operator = dummy_operator.DummyOperator(prev_res)

with pytest.raises(
ValueError,
match = "You are attempting to continue a run in which the previous "
"results do not have the same initial steps as those provided "
"to the Integrator. Please make sure you are using the correct "
"timesteps, powers or power densities, and previous results file.",
match="You are attempting to continue a run in which the previous timesteps "
"do not have the same initial timesteps as those provided to the "
"Integrator. Please make sure you are using the correct timesteps.",
):
bundle.solver(
operator, [0.75, 0.5, 0.75], [1.0, 1.0, 1.0], continue_timesteps=True
).integrate()


@pytest.mark.parametrize("scheme", dummy_operator.SCHEMES)
def test_mismatched_initial_source_rates(run_in_tmpdir, scheme):
"""Test to ensure that a continue run with different initial steps is properly caught"""
Expand All @@ -74,16 +84,15 @@ def test_mismatched_initial_source_rates(run_in_tmpdir, scheme):
bundle.solver(operator, [0.75, 0.75], [1.0, 1.0]).integrate()

# restart
prev_res = openmc.deplete.Results(
operator.output_dir / "depletion_results.h5")
prev_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5")
operator = dummy_operator.DummyOperator(prev_res)

with pytest.raises(
ValueError,
match = "You are attempting to continue a run in which the previous "
"results do not have the same initial steps as those provided "
"to the Integrator. Please make sure you are using the correct "
"timesteps, powers or power densities, and previous results file.",
match="You are attempting to continue a run in which the previous results "
"do not have the same initial source rates, powers, or power densities "
"as those provided to the Integrator. Please make sure you are using "
"the correct powers, power densities, or source rates and previous results file.",
):
bundle.solver(
operator, [0.75, 0.75, 0.75], [1.0, 2.0, 1.0], continue_timesteps=True
Expand Down