Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add continue feature for depletion #3272

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 23 additions & 1 deletion openmc/deplete/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ def __init__(
power_density: Optional[Union[float, Sequence[float]]] = None,
source_rates: Optional[Sequence[float]] = None,
timestep_units: str = 's',
solver: str = "cram48"
solver: str = "cram48",
continue_timesteps: bool = False,
):
# Check number of stages previously used
if operator.prev_res is not None:
Expand Down Expand Up @@ -629,6 +630,27 @@ def __init__(
else:
raise ValueError(f"Invalid timestep unit '{unit}'")

# validate existing depletion steps are consistent with those passed to operator
if continue_timesteps:
completed_timesteps = operator.prev_res.get_times()
completed_source_rates = operator.prev_res.get_source_rates()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm realizing now that I don't think openmc.deplete.Results has a get_source_rates() function. It seems like individual operators have a source_rates member, but I'm wondering if a method in openmc.deplete.Results parallel to get_times() would be useful for others. I noticed openmc.deplete.abc.Integrator has an __iter__() method but it doesn't return all the source rates, just the source rate and time (for a given iteration?)

It seems like maybe the appropriate line should be

completed_source_rates = operator.source_rates

though I'm wondering if the length of get_times() and operator.source_rates might have different lengths.

Tests were passing because I never added a test that hits this code, I will push up a test very soon (and likely it will fail)

num_previous_steps_run = len(completed_timesteps)
for step in len(completed_timesteps):
if (
timesteps[step] == completed_timesteps[step]
and source_rates[step] == completed_source_rates[step]
):
continue
else:
raise ValueError(
"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."
)
seconds = seconds[num_previous_steps_run:]
source_rates = source_rates[num_previous_steps_run:]

self.timesteps = np.asarray(seconds)
self.source_rates = np.asarray(source_rates)

Expand Down
53 changes: 53 additions & 0 deletions tests/unit_tests/test_deplete_continue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Unit tests for openmc.deplete continue run capability.

These tests run in two steps: first a normal run and then a continue run based on the prev_results
"""

import pytest

import openmc.deplete

from tests import dummy_operator

# test that the continue timesteps works when the second integrate call contains all previous timesteps
@pytest.mark.parametrize("scheme", dummy_operator.SCHEMES)
def test_continue(run_in_tmpdir, scheme):
# set up the problem

bundle = dummy_operator.SCHEMES[scheme]

operator = dummy_operator.DummyOperator()

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

# restart
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()

@pytest.mark.parametrize("scheme", dummy_operator.SCHEMES)
def test_mismatched_initial_steps(run_in_tmpdir, scheme):
"""Test to ensure that a continue run with different initial steps is properly caught"""

# set up the problem

bundle = dummy_operator.SCHEMES[scheme]

operator = dummy_operator.DummyOperator()

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

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

# continue run with different previous step should cause a ValueError
# note the first step matches but the second does not while the third is a new step
with pytest.raises(ValueError):
bundle.solver(operator, [0.75, 0.5, 0.75], [1.0, 2.0, 1.0], continue_timesteps = True).integrate()
Loading