@@ -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 )
0 commit comments