From 57ea52a46ce9eb93d84d2bb5aff756b83f778574 Mon Sep 17 00:00:00 2001 From: liangjg Date: Wed, 9 Jan 2019 10:39:40 -0500 Subject: [PATCH] added unit tests for the new integrators --- openmc/deplete/integrator/si_celi.py | 12 ++++---- openmc/deplete/integrator/si_leqi.py | 12 ++++---- tests/unit_tests/test_deplete_cf4.py | 37 ++++++++++++++++++++++++ tests/unit_tests/test_deplete_epc_rk4.py | 37 ++++++++++++++++++++++++ tests/unit_tests/test_deplete_si_celi.py | 37 ++++++++++++++++++++++++ tests/unit_tests/test_deplete_si_leqi.py | 37 ++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 tests/unit_tests/test_deplete_cf4.py create mode 100644 tests/unit_tests/test_deplete_epc_rk4.py create mode 100644 tests/unit_tests/test_deplete_si_celi.py create mode 100644 tests/unit_tests/test_deplete_si_leqi.py diff --git a/openmc/deplete/integrator/si_celi.py b/openmc/deplete/integrator/si_celi.py index 6e2d34bac..dc9bccb70 100644 --- a/openmc/deplete/integrator/si_celi.py +++ b/openmc/deplete/integrator/si_celi.py @@ -86,14 +86,16 @@ def si_celi(operator, timesteps, power=None, power_density=None, i_res = len(operator.prev_res) # Get the concentrations and reaction rates for the first - # beginning-of-timestep (BOS) - # Compute with s (stage number) times as many neutrons for statistics - # reasons if no previous calculation results loaded + # beginning-of-timestep (BOS). Compute with m (stage number) times as + # many neutrons as later simulations for statistics reasons if no + # previous calculation results present if operator.prev_res is None: x = [copy.deepcopy(vec)] - operator.settings.particles *= m + if hasattr(operator, "settings"): + operator.settings.particles *= m op_results = [operator(x[0], power[0])] - operator.settings.particles //= m + if hasattr(operator, "settings"): + operator.settings.particles //= m else: # Get initial concentration x = [operator.prev_res[-1].data[0]] diff --git a/openmc/deplete/integrator/si_leqi.py b/openmc/deplete/integrator/si_leqi.py index d3a0ff6af..609b3f8c4 100644 --- a/openmc/deplete/integrator/si_leqi.py +++ b/openmc/deplete/integrator/si_leqi.py @@ -114,14 +114,16 @@ def si_leqi(operator, timesteps, power=None, power_density=None, i_res = len(operator.prev_res) # Get the concentrations and reaction rates for the first - # beginning-of-timestep (BOS) - # Compute with s (stage number) times as many neutrons for statistics - # reasons if no previous calculation results loaded + # beginning-of-timestep (BOS). Compute with m (stage number) times as + # many neutrons as later simulations for statistics reasons if no + # previous calculation results present if operator.prev_res is None: x = [copy.deepcopy(vec)] - operator.settings.particles *= m + if hasattr(operator, "settings"): + operator.settings.particles *= m op_results = [operator(x[0], power[0])] - operator.settings.particles //= m + if hasattr(operator, "settings"): + operator.settings.particles //= m else: # Get initial concentration x = [operator.prev_res[-1].data[0]] diff --git a/tests/unit_tests/test_deplete_cf4.py b/tests/unit_tests/test_deplete_cf4.py new file mode 100644 index 000000000..784d228be --- /dev/null +++ b/tests/unit_tests/test_deplete_cf4.py @@ -0,0 +1,37 @@ +"""Regression tests for openmc.deplete.integrator.cf4 algorithm. + +These tests integrate a simple test problem described in dummy_geometry.py. +""" + +from pytest import approx +import openmc.deplete + +from tests import dummy_operator + + +def test_cf4(run_in_tmpdir): + """Integral regression test of integrator algorithm using CF4""" + + op = dummy_operator.DummyOperator() + op.output_dir = "test_integrator_regression" + + # Perform simulation using the cf4 algorithm + dt = [0.75, 0.75] + power = 1.0 + openmc.deplete.cf4(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") + + # Reference solution + s1 = [2.06101629, 1.37783588] + s2 = [2.57241318, 2.63731630] + + assert y1[1] == approx(s1[0]) + assert y2[1] == approx(s1[1]) + + assert y1[2] == approx(s2[0]) + assert y2[2] == approx(s2[1]) diff --git a/tests/unit_tests/test_deplete_epc_rk4.py b/tests/unit_tests/test_deplete_epc_rk4.py new file mode 100644 index 000000000..dd15bf8e1 --- /dev/null +++ b/tests/unit_tests/test_deplete_epc_rk4.py @@ -0,0 +1,37 @@ +"""Regression tests for openmc.deplete.integrator.epc_rk4 algorithm. + +These tests integrate a simple test problem described in dummy_geometry.py. +""" + +from pytest import approx +import openmc.deplete + +from tests import dummy_operator + + +def test_epc_rk4(run_in_tmpdir): + """Integral regression test of integrator algorithm using epc_rk4""" + + op = dummy_operator.DummyOperator() + op.output_dir = "test_integrator_regression" + + # Perform simulation using the epc_rk4 algorithm + dt = [0.75, 0.75] + power = 1.0 + openmc.deplete.epc_rk4(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") + + # Reference solution + s1 = [2.01978516, 1.42038037] + s2 = [2.05246421, 3.06177191] + + assert y1[1] == approx(s1[0]) + assert y2[1] == approx(s1[1]) + + assert y1[2] == approx(s2[0]) + assert y2[2] == approx(s2[1]) diff --git a/tests/unit_tests/test_deplete_si_celi.py b/tests/unit_tests/test_deplete_si_celi.py new file mode 100644 index 000000000..8e84bcba8 --- /dev/null +++ b/tests/unit_tests/test_deplete_si_celi.py @@ -0,0 +1,37 @@ +"""Regression tests for openmc.deplete.integrator.si_celi algorithm. + +These tests integrate a simple test problem described in dummy_geometry.py. +""" + +from pytest import approx +import openmc.deplete + +from tests import dummy_operator + + +def test_si_celi(run_in_tmpdir): + """Integral regression test of integrator algorithm using si_celi""" + + op = dummy_operator.DummyOperator() + op.output_dir = "test_integrator_regression" + + # Perform simulation using the si_celi algorithm + dt = [0.75, 0.75] + power = 1.0 + openmc.deplete.si_celi(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") + + # Reference solution + s1 = [2.03325094, 1.16826254] + s2 = [2.69291933, 0.37907772] + + assert y1[1] == approx(s1[0]) + assert y2[1] == approx(s1[1]) + + assert y1[2] == approx(s2[0]) + assert y2[2] == approx(s2[1]) diff --git a/tests/unit_tests/test_deplete_si_leqi.py b/tests/unit_tests/test_deplete_si_leqi.py new file mode 100644 index 000000000..4814d8ab8 --- /dev/null +++ b/tests/unit_tests/test_deplete_si_leqi.py @@ -0,0 +1,37 @@ +"""Regression tests for openmc.deplete.integrator.si_leqi algorithm. + +These tests integrate a simple test problem described in dummy_geometry.py. +""" + +from pytest import approx +import openmc.deplete + +from tests import dummy_operator + + +def test_si_leqi(run_in_tmpdir): + """Integral regression test of integrator algorithm using si_leqi""" + + op = dummy_operator.DummyOperator() + op.output_dir = "test_integrator_regression" + + # Perform simulation using the si_leqi algorithm + dt = [0.75, 0.75] + power = 1.0 + openmc.deplete.si_leqi(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") + + # Reference solution + s1 = [2.03325094, 1.16826254] + s2 = [2.92711288, 0.53753236] + + assert y1[1] == approx(s1[0]) + assert y2[1] == approx(s1[1]) + + assert y1[2] == approx(s2[0]) + assert y2[2] == approx(s2[1])