created regression test for FluxDepleteOperator

- new data file: tests/micro_xs_simple.csv
- created regression test based on pincell example
- moved old depletion regression test to new folder:
  tests/regression_tests/deplete/transport_deplete
This commit is contained in:
yardasol 2022-07-07 15:12:38 -05:00
parent 516c117533
commit 5963593398
6 changed files with 114 additions and 14 deletions

View file

@ -1,13 +1,7 @@
,fission,"(n,gamma)"
U234,0.1,0.0
U235,0.1,0.0
U238,0.9,0.0
U236,0.4,0.0
O16,0.0,0.0
O17,0.0,0.0
I135,0.0,0.1
Xe135,0.0,0.9
Xe136,0.0,0.0
Cs135,0.0,0.0
Gd157,0.0,0.1
Gd156,0.0,0.1
nuclide,"(n,gamma)",fission
U234,23.518634203050645,0.49531930067650976
U235,10.621118186344665,49.10955932965905
U238,0.8652742788116043,0.10579281644765708
U236,9.095623870006154,0.32315392339237936
O16,0.0029535689693132015,0.0
O17,0.05980775766572907,0.0

1 nuclide (n,gamma) fission
2 U234 U234 0.0 23.518634203050645 0.1 0.49531930067650976
3 U235 U235 0.0 10.621118186344665 0.1 49.10955932965905
4 U238 U238 0.0 0.8652742788116043 0.9 0.10579281644765708
5 U236 U236 0.0 9.095623870006154 0.4 0.32315392339237936
6 O16 O16 0.0 0.0029535689693132015 0.0
7 O17 O17 0.0 0.05980775766572907 0.0
I135 0.1 0.0
Xe135 0.9 0.0
Xe136 0.0 0.0
Cs135 0.0 0.0
Gd157 0.1 0.0
Gd156 0.1 0.0

View file

@ -0,0 +1,106 @@
""" Full system test suite. """
from math import floor
import shutil
from pathlib import Path
from difflib import unified_diff
import numpy as np
import pytest
import openmc
from openmc.data import JOULE_PER_EV
import openmc.deplete
from openmc.deplete import FluxDepletionOperator
from tests.regression_tests import config
@pytest.fixture(scope="module")
def vol_nuc():
fuel = openmc.Material(name="uo2")
fuel.add_element("U", 1, percent_type="ao", enrichment=4.25)
fuel.add_element("O", 2)
fuel.set_density("g/cc", 10.4)
fuel.volume = np.pi * 0.42 ** 2
nuclides = {}
for nuc, t in fuel.get_nuclide_atom_densities().items():
nuclides[nuc] = t[1] * 1e24
# Load geometry from example
return (fuel.volume, nuclides)
@pytest.mark.parametrize("multiproc", [True, False])
def test_full(run_in_tmpdir, vol_nuc, multiproc):
"""Full system test suite.
Runs an OpenMC depletion calculation and verifies
that the outputs match a reference file. Sensitive to changes in
OpenMC.
"""
# Create operator
micro_xs_file = Path(__file__).parents[3] / 'micro_xs_simple.csv'
micro_xs = FluxDepletionOperator.create_micro_xs_from_csv(micro_xs_file)
chain_file = Path(__file__).parents[3] / 'chain_simple.xml'
flux = 1164719970082145.0 # flux from pincell example
op = FluxDepletionOperator(vol_nuc[0], vol_nuc[1], micro_xs, flux, chain_file, dilute_initial=0.0)
# Power and timesteps
dt = [30] # single step
power = 174 # W/cm
# Perform simulation using the predictor algorithm
openmc.deplete.pool.USE_MULTIPROCESSING = multiproc
openmc.deplete.PredictorIntegrator(op, dt, power, timestep_units='d').integrate()
# Get path to test and reference results
path_test = op.output_dir / 'depletion_results.h5'
path_reference = Path(__file__).with_name('test_reference.h5')
# If updating results, do so and return
if config['update']:
shutil.copyfile(str(path_test), str(path_reference))
return
# Load the reference/test results
res_test = openmc.deplete.Results(path_test)
res_ref = openmc.deplete.Results(path_reference)
# Assert same mats
for mat in res_ref[0].mat_to_ind:
assert mat in res_test[0].mat_to_ind, \
"Material {} not in new results.".format(mat)
for nuc in res_ref[0].nuc_to_ind:
assert nuc in res_test[0].nuc_to_ind, \
"Nuclide {} not in new results.".format(nuc)
for mat in res_test[0].mat_to_ind:
assert mat in res_ref[0].mat_to_ind, \
"Material {} not in old results.".format(mat)
for nuc in res_test[0].nuc_to_ind:
assert nuc in res_ref[0].nuc_to_ind, \
"Nuclide {} not in old results.".format(nuc)
tol = 1.0e-6
for mat in res_test[0].mat_to_ind:
for nuc in res_test[0].nuc_to_ind:
_, y_test = res_test.get_atoms(mat, nuc)
_, y_old = res_ref.get_atoms(mat, nuc)
# Test each point
correct = True
for i, ref in enumerate(y_old):
if ref != y_test[i]:
if ref != 0.0:
correct = np.abs(y_test[i] - ref) / ref <= tol
else:
correct = False
assert correct, "Discrepancy in mat {} and nuc {}\n{}\n{}".format(
mat, nuc, y_old, y_test)

View file

@ -52,7 +52,7 @@ def test_full(run_in_tmpdir, problem, multiproc):
model = openmc.Model(geometry=geometry, settings=settings)
# Create operator
chain_file = Path(__file__).parents[2] / 'chain_simple.xml'
chain_file = Path(__file__).parents[3] / 'chain_simple.xml'
op = openmc.deplete.Operator(model, chain_file)
op.round_number = True