mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Introduce ResultsList class to replace scattered functions
This commit is contained in:
parent
7ef5174274
commit
92697ec06e
15 changed files with 220 additions and 262 deletions
|
|
@ -5,8 +5,6 @@ These tests integrate a simple test problem described in dummy_geometry.py.
|
|||
|
||||
from pytest import approx
|
||||
import openmc.deplete
|
||||
from openmc.deplete import results
|
||||
from openmc.deplete import utilities
|
||||
|
||||
from tests import dummy_operator
|
||||
|
||||
|
|
@ -23,10 +21,10 @@ def test_cecm(run_in_tmpdir):
|
|||
openmc.deplete.cecm(op, dt, power, print_out=False)
|
||||
|
||||
# Load the files
|
||||
res = results.read_results(op.output_dir / "depletion_results.h5")
|
||||
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
|
||||
|
||||
_, y1 = utilities.evaluate_single_nuclide(res, "1", "1")
|
||||
_, y2 = utilities.evaluate_single_nuclide(res, "1", "2")
|
||||
_, y1 = res.get_atoms("1", "1")
|
||||
_, y2 = res.get_atoms("1", "2")
|
||||
|
||||
# Mathematica solution
|
||||
s1 = [1.86872629872102, 1.395525772416039]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
"""Tests for integrator.py
|
||||
"""Tests for saving results
|
||||
|
||||
It is worth noting that openmc.deplete.integrate is extremely complex, to the
|
||||
point I am unsure if it can be reasonably unit-tested. For the time being, it
|
||||
|
|
@ -11,11 +11,11 @@ import os
|
|||
from unittest.mock import MagicMock
|
||||
|
||||
import numpy as np
|
||||
from openmc.deplete import (integrator, ReactionRates, results, comm,
|
||||
from openmc.deplete import (ReactionRates, Results, ResultsList, comm,
|
||||
OperatorResult)
|
||||
|
||||
|
||||
def test_save_results(run_in_tmpdir):
|
||||
def test_results_save(run_in_tmpdir):
|
||||
"""Test data save module"""
|
||||
|
||||
stages = 3
|
||||
|
|
@ -72,11 +72,11 @@ def test_save_results(run_in_tmpdir):
|
|||
|
||||
op_result1 = [OperatorResult(k, rates) for k, rates in zip(eigvl1, rate1)]
|
||||
op_result2 = [OperatorResult(k, rates) for k, rates in zip(eigvl2, rate2)]
|
||||
integrator.save_results(op, x1, op_result1, t1, 0)
|
||||
integrator.save_results(op, x2, op_result2, t2, 1)
|
||||
Results.save(op, x1, op_result1, t1, 0)
|
||||
Results.save(op, x2, op_result2, t2, 1)
|
||||
|
||||
# Load the files
|
||||
res = results.read_results("depletion_results.h5")
|
||||
res = ResultsList("depletion_results.h5")
|
||||
|
||||
for i in range(stages):
|
||||
for mat_i, mat in enumerate(burn_list):
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ These tests integrate a simple test problem described in dummy_geometry.py.
|
|||
|
||||
from pytest import approx
|
||||
import openmc.deplete
|
||||
from openmc.deplete import results
|
||||
from openmc.deplete import utilities
|
||||
|
||||
from tests import dummy_operator
|
||||
|
||||
|
|
@ -23,10 +21,10 @@ def test_predictor(run_in_tmpdir):
|
|||
openmc.deplete.predictor(op, dt, power, print_out=False)
|
||||
|
||||
# Load the files
|
||||
res = results.read_results(op.output_dir / "depletion_results.h5")
|
||||
res = openmc.deplete.ResultsList(op.output_dir / "depletion_results.h5")
|
||||
|
||||
_, y1 = utilities.evaluate_single_nuclide(res, "1", "1")
|
||||
_, y2 = utilities.evaluate_single_nuclide(res, "1", "2")
|
||||
_, y1 = res.get_atoms("1", "1")
|
||||
_, y2 = res.get_atoms("1", "2")
|
||||
|
||||
# Mathematica solution
|
||||
s1 = [2.46847546272295, 0.986431226850467]
|
||||
|
|
|
|||
51
tests/unit_tests/test_deplete_resultslist.py
Normal file
51
tests/unit_tests/test_deplete_resultslist.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"""Tests the ResultsList class"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
import openmc.deplete
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def res():
|
||||
"""Load the reference results"""
|
||||
filename = Path(__file__).parents[1] / 'regression_tests' / 'test_reference.h5'
|
||||
return openmc.deplete.ResultsList(filename)
|
||||
|
||||
|
||||
def test_get_atoms(res):
|
||||
"""Tests evaluating single nuclide concentration."""
|
||||
t, n = res.get_atoms("1", "Xe135")
|
||||
|
||||
t_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
|
||||
n_ref = [6.6747328233649218e+08, 3.5421791038348462e+14,
|
||||
3.6208592242443462e+14, 3.3799758969347038e+14]
|
||||
|
||||
np.testing.assert_array_equal(t, t_ref)
|
||||
np.testing.assert_array_equal(n, n_ref)
|
||||
|
||||
def test_get_reaction_rate(res):
|
||||
"""Tests evaluating reaction rate."""
|
||||
t, r = res.get_reaction_rate("1", "Xe135", "(n,gamma)")
|
||||
|
||||
t_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
|
||||
n_ref = np.array([6.6747328233649218e+08, 3.5421791038348462e+14,
|
||||
3.6208592242443462e+14, 3.3799758969347038e+14])
|
||||
xs_ref = np.array([4.0594392323131994e-05, 3.9249546927524987e-05,
|
||||
3.8394587728581798e-05, 4.1521845978371697e-05])
|
||||
|
||||
np.testing.assert_array_equal(t, t_ref)
|
||||
np.testing.assert_array_equal(r, n_ref * xs_ref)
|
||||
|
||||
|
||||
def test_get_eigenvalue(res):
|
||||
"""Tests evaluating eigenvalue."""
|
||||
t, k = res.get_eigenvalue()
|
||||
|
||||
t_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
|
||||
k_ref = [1.181281798790367, 1.1798750921988739, 1.1965943696058159,
|
||||
1.2207119847790813]
|
||||
|
||||
np.testing.assert_array_equal(t, t_ref)
|
||||
np.testing.assert_array_equal(k, k_ref)
|
||||
Loading…
Add table
Add a link
Reference in a new issue