mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 05:05:30 -04:00
Adding checks to geometry.plot to avoid material name overlaps (#3458)
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
This commit is contained in:
parent
3e32aed2da
commit
3d16d4b100
2 changed files with 31 additions and 10 deletions
|
|
@ -758,13 +758,27 @@ class Geometry:
|
|||
model.geometry = self
|
||||
model.materials = self.get_all_materials().values()
|
||||
|
||||
# Add placeholder materials for DAGMCUniverses
|
||||
universes = self.get_all_universes()
|
||||
for universe in universes.values():
|
||||
if isinstance(universe, openmc.DAGMCUniverse):
|
||||
for name in universe.material_names:
|
||||
mat_dag = openmc.Material(name=name)
|
||||
mat_dag.add_nuclide('H1', 1.0)
|
||||
model.materials.append(mat_dag)
|
||||
# collect all the material names from the geometry
|
||||
all_material_names = {m.name for m in model.materials if m.name is not None}
|
||||
|
||||
# makes a placeholder material for each material name if it isn't
|
||||
# already present on the model. These materials are otherwise missing
|
||||
# from the geometry and are needed for plotting.
|
||||
for universe in model.geometry.get_all_universes().values():
|
||||
if not isinstance(universe, openmc.DAGMCUniverse):
|
||||
continue
|
||||
for name in universe.material_names:
|
||||
# if this name is already present in the model, skip it
|
||||
# (this can happen if the same material name is used in multiple
|
||||
# universes)
|
||||
if name in all_material_names:
|
||||
continue
|
||||
# if the material name is not present on the model,
|
||||
# create a placeholder material with the same name
|
||||
# and add it to the model
|
||||
mat_dag = openmc.Material(name=name)
|
||||
mat_dag.add_nuclide('H1', 1.0)
|
||||
model.materials.append(mat_dag)
|
||||
all_material_names.add(name)
|
||||
|
||||
return model.plot(*args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -48,14 +48,21 @@ def test_plotting_geometry_filled_with_dagmc_universe(request):
|
|||
dag_universe = openmc.DAGMCUniverse(request.path.parent / 'dagmc.h5m', auto_geom_ids=True)
|
||||
|
||||
sphere1 = openmc.Sphere(r=50.0)
|
||||
sphere2 = openmc.Sphere(r=60.0, boundary_type='vacuum')
|
||||
sphere2 = openmc.Sphere(r=60.0)
|
||||
sphere2 = openmc.Sphere(r=70.0, boundary_type='vacuum')
|
||||
|
||||
# Adding a material to the CSG Universe to check all materials are accounted for
|
||||
# Adding a material to the CSG Universe to check universe materials are accounted for
|
||||
csg_material = openmc.Material(name='csg_material')
|
||||
csg_material.add_nuclide("H1", 1.0)
|
||||
|
||||
# Adding a material with the same name as a dagmc material to check that
|
||||
# the plot can handel two materials with the same name from different universes
|
||||
csg_material = openmc.Material(name=dag_universe.material_names[0])
|
||||
csg_material.add_nuclide("H1", 1.0)
|
||||
|
||||
cell1 = openmc.Cell(fill=dag_universe, region=-sphere1)
|
||||
cell2 = openmc.Cell(fill=csg_material, region=+sphere1 & -sphere2)
|
||||
|
||||
geometry = openmc.Geometry([cell1, cell2])
|
||||
|
||||
geometry.plot()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue