Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
25 changes: 24 additions & 1 deletion openmc/deplete/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,32 @@ def _get_bos_data_from_restart(self, source_rate, bos_conc):
return bos_conc, OperatorResult(k, rates)

def _get_start_data(self):
"""
This function fetches the starting state of a depletion simulation
in terms of the simulation physical time at which to start and the
index at which the depletion simulation should start. When no
previous results exist, the time and index are both zero. When
previous results do exist, it returns the time corresponding to
beginning the previous results last timestep and the index as
N-1 where N is the number of previous StepResults found in
the previous Results (as expected from 0-based indexing).

Note that the openmc.deplete.Results.time object is a list of float with
[t,t+dt] where t is the beginning of timestep time and t+dt is the end of
timestep time. If the previous results correspond to a simulation that
finished to completeion, it will contain a results in the form of [t,t],
but if a simulation doesn't finish all the given timesteps, it is the t
that is the desired start time, not t+dt. Thus, it is always safe to take
time[0].

Returns
_______
start_time : float
index: int
"""
Comment thread
lewisgross1296 marked this conversation as resolved.
if self.operator.prev_res is None:
return 0.0, 0
return (self.operator.prev_res[-1].time[-1],
return (self.operator.prev_res[-1].time[0],
len(self.operator.prev_res) - 1)

def integrate(
Expand Down
Binary file not shown.
34 changes: 34 additions & 0 deletions tests/unit_tests/kill_continue/continue_model.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version='1.0' encoding='utf-8'?>
<model>
<materials>
<material depletable="true" id="1" name="fuel" volume="3.14159265">
<density units="g/cm3" value="10.744"/>
<nuclide ao="0.068794" name="U235"/>
<nuclide ao="0.27604" name="U238"/>
<nuclide ao="0.13793" name="C0"/>
<nuclide ao="5.1724" name="O16"/>
</material>
</materials>
<geometry>
<cell id="1" material="1" region="-3 1 -2" universe="1"/>
<surface boundary="reflective" coeffs="0.0" id="1" type="z-plane"/>
<surface boundary="reflective" coeffs="1.0" id="2" type="z-plane"/>
<surface boundary="reflective" coeffs="0.0 0.0 1.0" id="3" type="z-cylinder"/>
</geometry>
<settings>
<run_mode>eigenvalue</run_mode>
<particles>250</particles>
<batches>45</batches>
<inactive>15</inactive>
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-0.5 -0.5 0.0 1.0 1.0 1.0</parameters>
</space>
</source>
<output>
<summary>false</summary>
<tallies>false</tallies>
</output>
<temperature_default>294</temperature_default>
</settings>
</model>
66 changes: 66 additions & 0 deletions tests/unit_tests/test_deplete_continue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"""

import pytest
import numpy as np
import openmc.deplete
from pathlib import Path

from tests import dummy_operator

Expand All @@ -26,6 +28,70 @@ def test_continue(run_in_tmpdir):
bundle.solver(operator, [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0],
continue_timesteps=True).integrate()

final_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5")

assert np.array_equal(np.diff(final_res.get_times(time_units="s")),[1.0, 2.0, 3.0, 4.0])


def test_continue_continue(run_in_tmpdir):
"""Test to ensure that a continue run can be continued"""
# set up the problem
bundle = dummy_operator.SCHEMES['predictor']
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)

# first continue run
bundle.solver(operator, [1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0],
continue_timesteps=True).integrate()

prev_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5")
# second continue run
bundle.solver(operator, [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
continue_timesteps=True).integrate()

final_res = openmc.deplete.Results(operator.output_dir / "depletion_results.h5")

assert np.array_equal(np.diff(final_res.get_times(time_units="s")),[1.0, 2.0, 3.0, 4.0, 5.0, 6.0])

def test_killed_and_continue(run_in_tmpdir):
"""
Attempt to continue from a simulation that was killed mid state.
The previous state is provided in the form of a few local files:

continue_model.xml contains the necessary XML information
chain_simple.xml contians a simplified version of the CASL chain

continue_depletion_results.h5 contains the results output by
an OpenMC (v0.15.2) depletion simulation that was killed in
the middle of the third step
"""
base_path = Path(__file__).parents[0]
chain_path = Path(__file__).parents[1]/'chain_simple.xml'
model = openmc.Model.from_model_xml(f"{base_path}/kill_continue/continue_model.xml")
power = 35000 # W

time_steps = [1.0,2.0,3.0,4.0] # days
prev_results = openmc.deplete.Results(f"{base_path}/kill_continue/continue_depletion_results.h5")
operator = openmc.deplete.CoupledOperator(
model, prev_results=prev_results, chain_file=chain_path
)
integrator = openmc.deplete.CECMIntegrator(
operator,
time_steps,
power=power,
timestep_units="d",
continue_timesteps=True,
)
integrator.integrate(path=f"{base_path}/kill_continue/continue_depletion_results.h5")
final_res = openmc.deplete.Results(f"{base_path}/kill_continue/continue_depletion_results.h5")

assert np.array_equal(np.diff(final_res.get_times(time_units="d")),[1.0, 2.0, 3.0, 4.0])

def test_mismatched_initial_times(run_in_tmpdir):
"""Test to ensure that a continue run with different initial steps is properly caught"""
Expand Down