Skip to content

Commit 7a1cafa

Browse files
shimwellpaulromano
andauthored
adding plot function to DAGMCUnvierse (#3451)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent 23eab2c commit 7a1cafa

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

openmc/dagmc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .surface import _BOUNDARY_TYPES
1414
from .bounding_box import BoundingBox
1515
from .utility_funcs import input_path
16+
from .plots import add_plot_params
1617

1718

1819
class DAGMCUniverse(openmc.UniverseBase):
@@ -566,6 +567,21 @@ def sync_dagmc_cells(self, mats: Iterable[openmc.Material]):
566567
fill = mats_per_id[dag_cell.fill.id] if dag_cell.fill else None
567568
self.add_cell(openmc.DAGMCCell(cell_id=dag_cell_id, fill=fill))
568569

570+
@add_plot_params
571+
def plot(self, *args, **kwargs):
572+
"""Display a slice plot of the DAGMCUniverse.
573+
"""
574+
model = openmc.Model()
575+
model.geometry = openmc.Geometry(self)
576+
577+
for mat_name in self.material_names:
578+
material = openmc.Material(name=mat_name)
579+
# Placeholder nuclide to ensure material is not empty
580+
material.add_nuclide('H1', 1.0)
581+
model.materials.append(material)
582+
583+
return model.plot(*args, **kwargs)
584+
569585

570586
class DAGMCCell(openmc.Cell):
571587
"""A cell class for DAGMC-based geometries.

tests/unit_tests/dagmc/test_plot.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled."
88
)
99

10-
def test_plotting_dagmc_geometry(request):
11-
"""Test plotting a DAGMC geometry with OpenMC. This is different to CSG
12-
geometry plotting as the path to the DAGMC file needs handling."""
10+
def test_plotting_dagmc_model(request):
11+
"""Test plotting a DAGMC model with OpenMC. This is different to CSG
12+
model plotting as the path to the DAGMC file needs handling."""
1313

1414
dag_universe = openmc.DAGMCUniverse(request.path.parent / 'dagmc.h5m')
1515
csg_with_dag_inside = dag_universe.bounded_universe()
@@ -30,3 +30,11 @@ def test_plotting_dagmc_geometry(request):
3030
model.settings.particles = 50
3131

3232
model.plot()
33+
34+
35+
def test_plotting_dagmc_universe(request):
36+
"""Test plotting a DAGMCUniverse with OpenMC. This is different to plotting
37+
UniverseBase as the materials are not defined withing the DAGMCUniverse."""
38+
39+
dag_universe = openmc.DAGMCUniverse(request.path.parent / 'dagmc.h5m')
40+
dag_universe.plot()

0 commit comments

Comments
 (0)