Other bug fixes

This commit is contained in:
Patrick Shriwise 2022-11-03 23:57:22 -05:00
parent 5ac6e87a68
commit 2e716589a1
3 changed files with 23 additions and 22 deletions

View file

@ -204,24 +204,24 @@ class Geometry:
surfaces[s1].periodic_surface = surfaces[s2]
# Add any DAGMC universes
for elem in elem.findall('dagmc_universe'):
dag_univ = openmc.DAGMCUniverse.from_xml_element(elem)
for e in elem.findall('dagmc_universe'):
dag_univ = openmc.DAGMCUniverse.from_xml_element(e)
universes[dag_univ.id] = dag_univ
# Dictionary that maps each universe to a list of cells/lattices that
# contain it (needed to determine which universe is the elem)
child_of = defaultdict(list)
for elem in elem.findall('lattice'):
lat = openmc.RectLattice.from_xml_element(elem, get_universe)
for e in elem.findall('lattice'):
lat = openmc.RectLattice.from_xml_element(e, get_universe)
universes[lat.id] = lat
if lat.outer is not None:
child_of[lat.outer].append(lat)
for u in lat.universes.ravel():
child_of[u].append(lat)
for elem in elem.findall('hex_lattice'):
lat = openmc.HexLattice.from_xml_element(elem, get_universe)
for e in elem.findall('hex_lattice'):
lat = openmc.HexLattice.from_xml_element(e, get_universe)
universes[lat.id] = lat
if lat.outer is not None:
child_of[lat.outer].append(lat)
@ -235,15 +235,8 @@ class Geometry:
for u in ring:
child_of[u].append(lat)
# Create dictionary to easily look up materials
if materials is None:
filename = Path(path).parent / 'materials.xml'
materials = openmc.Materials.from_xml(str(filename))
mats = {str(m.id): m for m in materials}
mats['void'] = None
for elem in elem.findall('cell'):
c = openmc.Cell.from_xml_element(elem, surfaces, mats, get_universe)
for e in elem.findall('cell'):
c = openmc.Cell.from_xml_element(e, surfaces, materials, get_universe)
if c.fill_type in ('universe', 'lattice'):
child_of[c.fill].append(c)
@ -276,7 +269,14 @@ class Geometry:
tree = ET.parse(path)
root = tree.getroot()
return cls.from_xml_element(root, materials)
# Create dictionary to easily look up materials
if materials is None:
filename = Path(path).parent / 'materials.xml'
materials = openmc.Materials.from_xml(str(filename))
mats = {str(m.id): m for m in materials}
mats['void'] = None
return cls.from_xml_element(root, mats)
def find(self, point):
"""Find cells/universes/lattices which contain a given point

View file

@ -208,11 +208,11 @@ class Model:
self._plots.append(plot)
@classmethod
def from_xml(cls, separate_xmls=True, **kwargs):
def from_xml(cls, *args, separate_xmls=True, **kwargs):
if separate_xmls:
return cls.from_separate_xmls(**kwargs)
return cls.from_separate_xmls(*args, **kwargs)
else:
return cls.from_model_xml(**kwargs)
return cls.from_model_xml(*args, **kwargs)
@classmethod
def from_model_xml(cls, path='model.xml'):

View file

@ -919,6 +919,7 @@ class Plots(cv.CheckedList):
# Clean the indentation in the file to be user-readable
clean_indentation(self._plots_file)
reorder_attributes(self._plots_file) # TODO: Remove when support is Python 3.8+
return self._plots_file
@ -936,8 +937,8 @@ class Plots(cv.CheckedList):
if p.is_dir():
p /= 'plots.xml'
self.to_xml_element()
# Write the XML Tree to the plots.xml file
reorder_attributes(self._plots_file) # TODO: Remove when support is Python 3.8+
tree = ET.ElementTree(self._plots_file)
tree.write(str(p), xml_declaration=True, encoding='utf-8')
@ -958,8 +959,8 @@ class Plots(cv.CheckedList):
"""
# Generate each plot
plots = cls()
for elem in elem.findall('plot'):
plots.append(Plot.from_xml_element(elem))
for e in elem.findall('plot'):
plots.append(Plot.from_xml_element(e))
return plots
@classmethod