From e702b5186c0aa0303f7422bb3ce56d3faad8f2ab Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 13 Jun 2019 19:35:15 -0400 Subject: [PATCH] Add test for working with depletion_chains in DataLibrary Load the system default cross section file, register a depletion chain, and inspect the results. Should have one additional library, with an empty list of materials. Export and create a new library from this exported xml. Examine the contents of the new depletion chain library --- tests/unit_tests/test_data_misc.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/unit_tests/test_data_misc.py b/tests/unit_tests/test_data_misc.py index ea20ba53c8..2585e9315f 100644 --- a/tests/unit_tests/test_data_misc.py +++ b/tests/unit_tests/test_data_misc.py @@ -2,6 +2,7 @@ from collections.abc import Mapping import os +from pathlib import Path import numpy as np import pytest @@ -33,6 +34,30 @@ def test_data_library(tmpdir): assert new_lib.libraries[-1]['type'] == 'thermal' +def test_depletion_chain_data_library(run_in_tmpdir): + dep_lib = openmc.data.DataLibrary.from_xml() + prev_len = len(dep_lib.libraries) + chain_path = Path(__file__).parents[1] / "chain_simple.xml" + dep_lib.register_file(chain_path) + assert len(dep_lib.libraries) == prev_len + 1 + # Inspect + dep_dict = dep_lib.libraries[-1] + assert dep_dict['materials'] == [] + assert dep_dict['type'] == 'depletion_chain' + assert dep_dict['path'] == str(chain_path) + + out_path = "cross_section_chain.xml" + dep_lib.export_to_xml(out_path) + + dep_import = openmc.data.DataLibrary.from_xml(out_path) + for lib in reversed(dep_import.libraries): + if lib['type'] == 'depletion_chain': + break + else: + raise IndexError("depletion_chain not found in exported DataLibrary") + assert os.path.exists(lib['path']) + + def test_linearize(): """Test linearization of a continuous function.""" x, y = openmc.data.linearize([-1., 1.], lambda x: 1 - x*x)