I’d like to plot multigroup cross-sections by material. However, the plot_xs
function seems to require that the mgxs.h5
file require nuclide cross-sections. A minimum working example and the error produced are below. This behavior occurs whether mgxs_lib.by_nuclide
is True
or False
. I am running the development version of the code 0.15.3-dev5 on a Macbook M4.
import openmc
import matplotlib.pyplot as plt
model = openmc.examples.pwr_pin_cell()
geometry = model.geometry
# Initialize MGXS library with a finished OpenMC geometry object
mgxs_lib = openmc.mgxs.Library(geometry)
# Pick energy group structure
groups = openmc.mgxs.EnergyGroups('CASMO-2')
mgxs_lib.energy_groups = groups
# Disable transport correction
mgxs_lib.correction = None
# Specify needed cross sections for random ray
mgxs_lib.mgxs_types = ['total', 'absorption', 'nu-fission', 'fission',
'nu-scatter matrix', 'multiplicity matrix', 'chi']
# Specify a "cell" domain type for the cross section tally filters
mgxs_lib.domain_type = "material"
# Specify the cell domains over which to compute multi-group cross sections
mgxs_lib.domains = geometry.get_all_materials().values()
# Do not compute cross sections on a nuclide-by-nuclide basis
mgxs_lib.by_nuclide = True
# Check the library - if no errors are raised, then the library is satisfactory.
mgxs_lib.check_library_for_openmc_mgxs()
# Construct all tallies needed for the multi-group cross section library
mgxs_lib.build_library()
# Create a "tallies.xml" file for the MGXS Library
mgxs_lib.add_to_tallies_file(model.tallies, merge=True)
# Run
statepoint_filename = model.run()
# Load MGXS
with openmc.StatePoint(statepoint_filename) as sp:
mgxs_lib.load_from_statepoint(sp)
names = [mat.name for mat in mgxs_lib.domains]
# Create a MGXS File which can then be written to disk
mgxs_file = mgxs_lib.create_mg_library(
xs_type='macro', xsdata_names=names)
mgxs_file.export_to_hdf5('mgxs.h5')
# Plot multigroup xs for water
water = model.materials[2]
openmc.plot_xs(
reactions = {
water: ['total'],
},
mg_cross_sections='mgxs.h5',
plot_CE=False
)
plt.show()
with error
Traceback (most recent call last):
File "/Users/Nick/MIT Dropbox/Nick Schwartz/Research/Neutronics/xs_plotting/xs_plot.py", line 54<
openmc.plot_xs(
~~~~~~~~~~~~~~^
reactions = {
^^^^^^^^^^^^^
...<3 lines>...
plot_CE=False
^^^^^^^^^^^^^
)
^
File "/opt/miniconda3/envs/openmc-dev/lib/python3.13/site-packages/openmc/plotter.py", line 241,p
E, data = calculate_mgxs(this, types, orders, temperature,
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mg_cross_sections, ce_cross_sections,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
enrichment)
^^^^^^^^^^^
File "/opt/miniconda3/envs/openmc-dev/lib/python3.13/site-packages/openmc/plotter.py", line 740,c
mgxs = _calculate_mgxs_elem_mat(this, types, library, orders,
temperature, ce_cross_sections,
enrichment)
File "/opt/miniconda3/envs/openmc-dev/lib/python3.13/site-packages/openmc/plotter.py", line 973,_
nuc_data.append(_calculate_mgxs_nuc_macro(nuclide[0], types, library,
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
orders, T))
^^^^^^^^^^
File "/opt/miniconda3/envs/openmc-dev/lib/python3.13/site-packages/openmc/plotter.py", line 898,_
raise ValueError(f"{this} not present in provided MGXS library")
ValueError: H1 not present in provided MGXS library