From 021bb280c9b4cad713ecdd516c9ef8b9ee97bd2c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 4 Nov 2022 22:45:37 -0500 Subject: [PATCH] Adding initial test for exporting model.xmls. Correcting material maps --- openmc/model/model.py | 3 ++- tests/unit_tests/test_model.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/openmc/model/model.py b/openmc/model/model.py index bc8f0b531..6950642e0 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -230,8 +230,9 @@ class Model: model.settings = openmc.Settings.from_xml_element(root.find('settings')) model.materials = openmc.Materials.from_xml_element(root.find('materials')) + materials = {str(m.id): m for m in model.materials} model.geometry = \ - openmc.Geometry.from_xml_element(root.find('geometry'), model.materials) + openmc.Geometry.from_xml_element(root.find('geometry'), materials) if root.find('tallies'): model.tallies = openmc.Tallies.from_xml_element(root.find('tallies')) diff --git a/tests/unit_tests/test_model.py b/tests/unit_tests/test_model.py index 9b05ed2a5..ce81b00ee 100644 --- a/tests/unit_tests/test_model.py +++ b/tests/unit_tests/test_model.py @@ -7,6 +7,8 @@ import pytest import openmc import openmc.lib +from .. import cdtemp + @pytest.fixture(scope='function') def pin_model_attributes(): @@ -529,3 +531,22 @@ def test_calc_volumes(run_in_tmpdir, pin_model_attributes, mpi_intracomm): assert openmc.lib.materials[3].volume == mats[2].volume test_model.finalize_lib() + +def test_model_xml(): + + with cdtemp(): + # load a model from examples + pwr_model = openmc.examples.pwr_core() + + # export to separate XMLs manually + pwr_model.settings.export_to_xml('settings_ref.xml') + pwr_model.materials.export_to_xml('materials_ref.xml') + pwr_model.geometry.export_to_xml('geometry_ref.xml') + + # now write and read a model.xml file + pwr_model.export_to_xml(separate_xmls=False) + new_model = openmc.Model.from_xml(separate_xmls=False) + + # make sure we can also export this again to separate + # XML files + new_model.export_to_xml(separate_xmls=True) \ No newline at end of file