Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions openmc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,16 @@ def plot(
y_min = (origin[y] - 0.5*width[1]) * axis_scaling_factor[axis_units]
y_max = (origin[y] + 0.5*width[1]) * axis_scaling_factor[axis_units]

# Determine whether any materials contains macroscopic data and if so,
# set energy mode accordingly and check that mg cross sections path is accessible
for mat in self.geometry.get_all_materials().values():
if mat._macroscopic is not None:
self.settings.energy_mode = 'multi-group'
if 'mg_cross_sections' not in openmc.config:
raise RuntimeError("'mg_cross_sections' path must be set in "
"openmc.config before plotting.")
break

# Get ID map from the C API
id_map = self.id_map(
origin=origin,
Expand All @@ -1179,8 +1189,8 @@ def plot(

# Convert ID map to RGB image
img = id_map_to_rgb(
id_map=id_map,
color_by=color_by,
id_map=id_map,
color_by=color_by,
colors=colors,
overlap_color=overlap_color
)
Expand Down Expand Up @@ -1217,7 +1227,7 @@ def plot(
extent=(x_min, x_max, y_min, y_max),
**contour_kwargs
)

# If only showing outline, set the axis limits and aspect explicitly
if outline == 'only':
axes.set_xlim(x_min, x_max)
Expand Down
39 changes: 39 additions & 0 deletions tests/unit_tests/test_universe.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import lxml.etree as ET
import numpy as np
import openmc
Expand Down Expand Up @@ -104,6 +106,43 @@ def test_plot(run_in_tmpdir, sphere_model):
plt.close('all')


def test_mg_plot(run_in_tmpdir):
# Create a simple universe with macroscopic data
h2o_data = openmc.Macroscopic('LWTR')
water = openmc.Material(name='Water')
water.set_density('macro', 1.0)
water.add_macroscopic(h2o_data)
sph = openmc.Sphere(r=10, boundary_type="vacuum")
cell = openmc.Cell(region=-sph, fill=water)
univ = openmc.Universe(cells=[cell])

# Create MGXS library and export to HDF5
groups = openmc.mgxs.EnergyGroups([1e-5, 20.0e6])
h2o_xsdata = openmc.XSdata('LWTR', groups)
h2o_xsdata.order = 0
h2o_xsdata.set_total([1.0])
h2o_xsdata.set_absorption([0.5])
scatter_matrix = np.array([[[0.5]]])
scatter_matrix = np.rollaxis(scatter_matrix, 0, 3)
h2o_xsdata.set_scatter_matrix(scatter_matrix)
mg_library = openmc.MGXSLibrary(groups)
mg_library.add_xsdatas([h2o_xsdata])
mgxs_path = Path.cwd() / 'mgxs.h5'
mg_library.export_to_hdf5(mgxs_path)

# Set MG cross sections in config and plot
with openmc.config.patch('mg_cross_sections', mgxs_path):
univ.plot(width=(200, 200), basis='yz', color_by='cell')
univ.plot(width=(200, 200), basis='yz', color_by='material')

with pytest.raises(RuntimeError):
univ.plot(width=(200, 200), basis='yz', color_by='cell')

# Close plots to avoid warning
import matplotlib.pyplot as plt
plt.close('all')


def test_get_nuclides(uo2):
c = openmc.Cell(fill=uo2)
univ = openmc.Universe(cells=[c])
Expand Down
Loading