added unit tests for depletion restart capability

This commit is contained in:
guillaume 2018-06-02 16:34:41 -04:00
parent 09a4475e38
commit b2c720b296
2 changed files with 213 additions and 0 deletions

View file

@ -0,0 +1,168 @@
"""Regression tests for openmc.deplete restart capability.
These tests run in two steps, a first run then a restart run, a simple test
problem described in dummy_geometry.py.
"""
from pytest import approx
import openmc.deplete
from tests import dummy_operator
def test_restart_predictor(run_in_tmpdir):
"""Integral regression test of integrator algorithm using predictor."""
op = dummy_operator.DummyOperator()
output_dir = "test_restart_predictor"
op.output_dir = output_dir
# Perform simulation using the predictor algorithm
dt = [0.75]
power = 1.0
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
op.output_dir = output_dir
# Perform restarts simulation using the predictor algorithm
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
# Mathematica solution
s1 = [2.46847546272295, 0.986431226850467]
s2 = [4.11525874568034, -0.0581692232513460]
assert y1[1] == approx(s1[0])
assert y2[1] == approx(s1[1])
assert y1[2] == approx(s2[0])
assert y2[2] == approx(s2[1])
def test_restart_cecm(run_in_tmpdir):
"""Integral regression test of integrator algorithm using CE/CM."""
op = dummy_operator.DummyOperator()
output_dir = "test_restart_cecm"
op.output_dir = output_dir
# Perform simulation using the MCNPX/MCNP6 algorithm
dt = [0.75]
power = 1.0
openmc.deplete.cecm(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
op.output_dir = output_dir
# Perform restarts simulation using the MCNPX/MCNP6 algorithm
openmc.deplete.cecm(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
# Mathematica solution
s1 = [1.86872629872102, 1.395525772416039]
s2 = [2.18097439443550, 2.69429754646747]
assert y1[1] == approx(s1[0])
assert y2[1] == approx(s1[1])
assert y1[3] == approx(s2[0])
assert y2[3] == approx(s2[1])
def test_restart_predictor_cecm(run_in_tmpdir):
"""Integral regression test of integrator algorithm using predictor
for the first run then CE/CM for the restart run."""
op = dummy_operator.DummyOperator()
output_dir = "test_restart_predictor_cecm"
op.output_dir = output_dir
# Perform simulation using the predictor algorithm
dt = [0.75]
power = 1.0
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
op.output_dir = output_dir
# Perform restarts simulation using the MCNPX/MCNP6 algorithm
openmc.deplete.cecm(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
# Test solution
s1 = [2.46847546272295, 0.986431226850467]
s2 = [3.09106948392, 0.607102912398]
assert y1[1] == approx(s1[0])
assert y2[1] == approx(s1[1])
assert y1[2] == approx(s2[0])
assert y2[2] == approx(s2[1])
def test_restart_cecm_predictor(run_in_tmpdir):
"""Integral regression test of integrator algorithm using CE/CM for the
first run then predictor for the restart run."""
op = dummy_operator.DummyOperator()
output_dir = "test_restart_cecm_predictor"
op.output_dir = output_dir
# Perform simulation using the MCNPX/MCNP6 algorithm
dt = [0.75]
power = 1.0
openmc.deplete.cecm(op, dt, power, print_out=False)
# Load the files
prev_res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
# Re-create depletion operator and load previous results
op = dummy_operator.DummyOperator(prev_res)
op.output_dir = output_dir
# Perform restarts simulation using the predictor algorithm
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
_, y1 = res.get_atoms("1", "1")
_, y2 = res.get_atoms("1", "2")
# Test solution
s1 = [1.86872629872102, 1.395525772416039]
s2 = [3.32776806576, 2.391425905]
assert y1[1] == approx(s1[0])
assert y2[1] == approx(s1[1])
assert y1[2] == approx(s2[0])
assert y2[2] == approx(s2[1])

View file

@ -0,0 +1,45 @@
"""Regression tests for openmc.deplete.Results.transfer_volumes method.
"""
from pytest import approx
import openmc.deplete
from tests import dummy_operator
def test_transfer_volumes(run_in_tmpdir):
"""Unit test of volume transfer in restart calculations."""
op = dummy_operator.DummyOperator()
op.output_dir = "test_transfer_volumes"
# Perform simulation using the predictor algorithm
dt = [0.75]
power = 1.0
openmc.deplete.predictor(op, dt, power, print_out=False)
# Load the files
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
# Create a dictionary of volumes to transfer
res[0].volume['1'] = 1.5
res[0].volume['2'] = 2.5
# Create dummy geometry
mat1 = openmc.Material(material_id=1)
mat1.depletable = True
mat2 = openmc.Material(material_id=2)
cell = openmc.Cell()
cell.fill = [mat1, mat2]
root = openmc.Universe()
root.add_cell(cell)
geometry = openmc.Geometry(root)
# Transfer volumes
res[0].transfer_volumes(geometry)
assert mat1.volume == 1.5
assert mat2.volume is None