Repository navigation
add continue feature for depletion #3272
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
Changes from 16 commits
1730c21
5ed5a59
48f8478
136289c
46ab8b4
4fdf333
3f96f1a
f3358e4
09df7c1
020aff2
00e575d
220f1a9
1915e6d
384e99c
471e5b6
b27c9df
e2d0ad1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,11 @@ | |
|
|
||
| __all__ = ["Results", "ResultsList"] | ||
|
|
||
| _SECONDS_PER_MINUTE = 60 | ||
| _SECONDS_PER_HOUR = 60*60 | ||
| _SECONDS_PER_DAY = 24*60*60 | ||
| _SECONDS_PER_JULIAN_YEAR = 365.25*24*60*60 # 365.25 due to the leap year | ||
|
|
||
|
|
||
| def _get_time_as(seconds: float, units: str) -> float: | ||
| """Converts the time in seconds to time in different units | ||
|
|
@@ -31,13 +36,13 @@ def _get_time_as(seconds: float, units: str) -> float: | |
|
|
||
| """ | ||
| if units == "a": | ||
| return seconds / (60 * 60 * 24 * 365.25) # 365.25 due to the leap year | ||
| return seconds / _SECONDS_PER_JULIAN_YEAR | ||
| if units == "d": | ||
| return seconds / (60 * 60 * 24) | ||
| return seconds / _SECONDS_PER_DAY | ||
| elif units == "h": | ||
| return seconds / (60 * 60) | ||
| return seconds / _SECONDS_PER_HOUR | ||
| elif units == "min": | ||
| return seconds / 60 | ||
| return seconds / _SECONDS_PER_MINUTE | ||
| else: | ||
| return seconds | ||
|
|
||
|
|
@@ -71,7 +76,6 @@ def __init__(self, filename='depletion_results.h5'): | |
| data.append(StepResult.from_hdf5(fh, i)) | ||
| super().__init__(data) | ||
|
|
||
|
|
||
| @classmethod | ||
| def from_hdf5(cls, filename: PathLike): | ||
| """Load in depletion results from a previous file | ||
|
|
@@ -460,6 +464,26 @@ def get_times(self, time_units: str = "d") -> np.ndarray: | |
|
|
||
| return _get_time_as(times, time_units) | ||
|
|
||
| def get_source_rates(self) -> np.ndarray: | ||
| """ | ||
| .. versionadded:: 0.15.1 | ||
|
|
||
| Returns | ||
| ------- | ||
| numpy.ndarray | ||
| 1-D vector of source rates at each point in the depletion simulation | ||
| with the units originally defined by the user. | ||
|
|
||
| """ | ||
| # Results duplicate the final source rate at the final simulation time | ||
| source_rates = np.fromiter( | ||
| (r.source_rate for r in self), | ||
| dtype=self[0].source_rate.dtype, | ||
| count=len(self)-1, | ||
| ) | ||
|
|
||
| return source_rates | ||
|
Comment on lines
+466
to
+485
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like when I print out the result of this function, it duplicates the final source rate (no matter the integrator chosen). When I change to Thinking about this more, it kind of makes sense since Not sure if this is intended, but the final simulation "time" duplicates the system final source rate. |
||
|
|
||
| def get_step_where( | ||
| self, time, time_units: str = "d", atol: float = 1e-6, rtol: float = 1e-3 | ||
| ) -> int: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Unit tests for openmc.deplete continue run capability. | ||
|
|
||
| These tests run in two steps: first a normal run and then a continue run using the previous results | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| import openmc.deplete | ||
|
|
||
| from tests import dummy_operator | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("scheme", dummy_operator.SCHEMES) | ||
| def test_continue(run_in_tmpdir, scheme): | ||
| """Test to ensure that a properly defined continue run works""" | ||
| # 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]).integrate() | ||
|
|
||
| # 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, [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): | ||
| """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() | ||
|
|
||
| # perform initial steps | ||
| 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) | ||
|
|
||
| with pytest.raises( | ||
| ValueError, | ||
| 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""" | ||
| # set up the problem | ||
| bundle = dummy_operator.SCHEMES[scheme] | ||
| operator = dummy_operator.DummyOperator() | ||
|
|
||
| # perform initial steps | ||
| 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) | ||
|
|
||
| with pytest.raises( | ||
| ValueError, | ||
| 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 | ||
| ).integrate() |
Uh oh!
There was an error while loading. Please reload this page.