From 7a1cafa6c17d456dabdd4a2aa33fd5e586e98794 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 18 Jun 2025 00:36:35 +0200 Subject: [PATCH] adding plot function to DAGMCUnvierse (#3451) Co-authored-by: Paul Romano --- openmc/dagmc.py | 16 ++++++++++++++++ tests/unit_tests/dagmc/test_plot.py | 14 +++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/openmc/dagmc.py b/openmc/dagmc.py index 8ab0aaf69e..3f20fb0ac8 100644 --- a/openmc/dagmc.py +++ b/openmc/dagmc.py @@ -13,6 +13,7 @@ from .checkvalue import check_type, check_value from .surface import _BOUNDARY_TYPES from .bounding_box import BoundingBox from .utility_funcs import input_path +from .plots import add_plot_params class DAGMCUniverse(openmc.UniverseBase): @@ -566,6 +567,21 @@ class DAGMCUniverse(openmc.UniverseBase): fill = mats_per_id[dag_cell.fill.id] if dag_cell.fill else None self.add_cell(openmc.DAGMCCell(cell_id=dag_cell_id, fill=fill)) + @add_plot_params + def plot(self, *args, **kwargs): + """Display a slice plot of the DAGMCUniverse. + """ + model = openmc.Model() + model.geometry = openmc.Geometry(self) + + for mat_name in self.material_names: + material = openmc.Material(name=mat_name) + # Placeholder nuclide to ensure material is not empty + material.add_nuclide('H1', 1.0) + model.materials.append(material) + + return model.plot(*args, **kwargs) + class DAGMCCell(openmc.Cell): """A cell class for DAGMC-based geometries. diff --git a/tests/unit_tests/dagmc/test_plot.py b/tests/unit_tests/dagmc/test_plot.py index 83f6df7676..d768ba5081 100644 --- a/tests/unit_tests/dagmc/test_plot.py +++ b/tests/unit_tests/dagmc/test_plot.py @@ -7,9 +7,9 @@ pytestmark = pytest.mark.skipif( not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled." ) -def test_plotting_dagmc_geometry(request): - """Test plotting a DAGMC geometry with OpenMC. This is different to CSG - geometry plotting as the path to the DAGMC file needs handling.""" +def test_plotting_dagmc_model(request): + """Test plotting a DAGMC model with OpenMC. This is different to CSG + model plotting as the path to the DAGMC file needs handling.""" dag_universe = openmc.DAGMCUniverse(request.path.parent / 'dagmc.h5m') csg_with_dag_inside = dag_universe.bounded_universe() @@ -30,3 +30,11 @@ def test_plotting_dagmc_geometry(request): model.settings.particles = 50 model.plot() + + +def test_plotting_dagmc_universe(request): + """Test plotting a DAGMCUniverse with OpenMC. This is different to plotting + UniverseBase as the materials are not defined withing the DAGMCUniverse.""" + + dag_universe = openmc.DAGMCUniverse(request.path.parent / 'dagmc.h5m') + dag_universe.plot()