Skip to content

Commit cdceace

Browse files
authored
Merge branch 'openmc-dev:develop' into Sensitivity-Analysis
2 parents ab4c484 + 3d16d4b commit cdceace

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

openmc/geometry.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -758,13 +758,27 @@ def plot(self, *args, **kwargs):
758758
model.geometry = self
759759
model.materials = self.get_all_materials().values()
760760

761-
# Add placeholder materials for DAGMCUniverses
762-
universes = self.get_all_universes()
763-
for universe in universes.values():
764-
if isinstance(universe, openmc.DAGMCUniverse):
765-
for name in universe.material_names:
766-
mat_dag = openmc.Material(name=name)
767-
mat_dag.add_nuclide('H1', 1.0)
768-
model.materials.append(mat_dag)
761+
# collect all the material names from the geometry
762+
all_material_names = {m.name for m in model.materials if m.name is not None}
763+
764+
# makes a placeholder material for each material name if it isn't
765+
# already present on the model. These materials are otherwise missing
766+
# from the geometry and are needed for plotting.
767+
for universe in model.geometry.get_all_universes().values():
768+
if not isinstance(universe, openmc.DAGMCUniverse):
769+
continue
770+
for name in universe.material_names:
771+
# if this name is already present in the model, skip it
772+
# (this can happen if the same material name is used in multiple
773+
# universes)
774+
if name in all_material_names:
775+
continue
776+
# if the material name is not present on the model,
777+
# create a placeholder material with the same name
778+
# and add it to the model
779+
mat_dag = openmc.Material(name=name)
780+
mat_dag.add_nuclide('H1', 1.0)
781+
model.materials.append(mat_dag)
782+
all_material_names.add(name)
769783

770784
return model.plot(*args, **kwargs)

tests/unit_tests/dagmc/test_plot.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,21 @@ def test_plotting_geometry_filled_with_dagmc_universe(request):
4848
dag_universe = openmc.DAGMCUniverse(request.path.parent / 'dagmc.h5m', auto_geom_ids=True)
4949

5050
sphere1 = openmc.Sphere(r=50.0)
51-
sphere2 = openmc.Sphere(r=60.0, boundary_type='vacuum')
51+
sphere2 = openmc.Sphere(r=60.0)
52+
sphere2 = openmc.Sphere(r=70.0, boundary_type='vacuum')
5253

53-
# Adding a material to the CSG Universe to check all materials are accounted for
54+
# Adding a material to the CSG Universe to check universe materials are accounted for
5455
csg_material = openmc.Material(name='csg_material')
5556
csg_material.add_nuclide("H1", 1.0)
5657

58+
# Adding a material with the same name as a dagmc material to check that
59+
# the plot can handel two materials with the same name from different universes
60+
csg_material = openmc.Material(name=dag_universe.material_names[0])
61+
csg_material.add_nuclide("H1", 1.0)
62+
5763
cell1 = openmc.Cell(fill=dag_universe, region=-sphere1)
5864
cell2 = openmc.Cell(fill=csg_material, region=+sphere1 & -sphere2)
5965

6066
geometry = openmc.Geometry([cell1, cell2])
67+
6168
geometry.plot()

0 commit comments

Comments
 (0)