Adding a from_xml method to the DAGUniverse class. Ensuring DAGMC universes are read into geometries from XML files.

This commit is contained in:
Patrick Shriwise 2021-06-29 17:54:57 -05:00
parent 9c849f4058
commit e2826fa57b
2 changed files with 22 additions and 0 deletions

View file

@ -198,6 +198,11 @@ class Geometry:
if c.fill_type in ('universe', 'lattice'):
child_of[c.fill].append(c)
# Add any DAGMC universes
for elem in root.findall('dagmc_universe'):
dag_univ = openmc.DAGMCUniverse.from_xml(elem)
universes[dag_univ.id] = dag_univ
# Determine which universe is the root by finding one which is not a
# child of any other object
for u in universes.values():

View file

@ -10,6 +10,7 @@ import numpy as np
import openmc
import openmc.checkvalue as cv
from ._xml import get_text
from .mixin import IDManagerMixin
from .plots import _SVG_COLORS
@ -729,3 +730,19 @@ class DAGMCUniverse(UniverseBase):
dagmc_element.set('auto_mat_ids', 'true')
dagmc_element.set('filename', self.filename)
xml_element.append(dagmc_element)
@classmethod
def from_xml(cls, elem):
id = int(get_text(elem, 'id'))
fname = get_text(elem, 'filename')
out = cls(fname, universe_id=id)
name = get_text(elem, 'name')
if name is not None:
out.name = name
out.auto_geom_ids = bool(elem.get('auto_geom_ids'))
out.auto_mat_ids = bool(elem.get('auto_mat_ids'))
return out