Problem Plotting Material Cross Sections with openmc.plot_xs

Hi all,

I’m attempting to plot various cross sections for a material I have defined in my materials.xml file as shown below.

<material depletable="true" id="5" name="fuel(0.06896551724137931)-li_salt(0.1896551724137931)-k_salt(0.15517241379310345)-chlor(0.5862068965517242)" temperature="900">
    <density units="g/cm3" value="2.3367120000000003" />
    <nuclide ao="0.002548104822851506" name="Np237" />
    <nuclide ao="0.02591765558141982" name="Am241" />
    <nuclide ao="0.00017202307213090836" name="Am242" />
    <nuclide ao="0.017968453318747826" name="Am243" />
    <nuclide ao="1.3783570234063908e-05" name="Cm242" />
    <nuclide ao="0.00011015937937005189" name="Cm243" />
    <nuclide ao="0.010559337947889933" name="Cm244" />
    <nuclide ao="0.011477494506624643" name="Cm245" />
    <nuclide ao="0.00019850504211056688" name="Cm246" />
    <nuclide ao="0.17526034482758623" name="Li7" />
    <nuclide ao="0.0143948275862069" name="Li6" />
    <nuclide ao="0.14472777797760963" name="K39" />
    <nuclide ao="0.010444635815493864" name="K41" />
    <nuclide ao="0.029310344827586206" name="Cl35" />
    <nuclide ao="0.5568965517241379" name="Cl37" />

Then I run my simple python script.

# Define material object
mat = openmc.Material(5)

# Plot reaction for material
fig = openmc.plot_xs(mat, ['fission'])

But I am encountering the following error.

/home/jeickman/.local/lib/python3.8/site-packages/openmc/material.py:1004: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
percent_in_atom = np.all(nuc_density_types == ‘ao’)
Traceback (most recent call last):
File “plot_mat_xs_test.py”, line 11, in
fig = openmc.plot_xs(mat, [‘total’])
File “/home/jeickman/.local/lib/python3.8/site-packages/openmc/plotter.py”, line 122, in plot_xs
E, data = calculate_cexs(this, types, temperature, sab_name,
File “/home/jeickman/.local/lib/python3.8/site-packages/openmc/plotter.py”, line 278, in calculate_cexs
energy_grid, data = _calculate_cexs_elem_mat(this, types, temperature,
File “/home/jeickman/.local/lib/python3.8/site-packages/openmc/plotter.py”, line 527, in _calculate_cexs_elem_mat
nuc_fractions = this.get_nuclide_atom_densities()
File “/home/jeickman/.local/lib/python3.8/site-packages/openmc/material.py”, line 1020, in get_nuclide_atom_densities
density = -density / self.average_molar_mass * 1.e-24
File “/home/jeickman/.local/lib/python3.8/site-packages/openmc/material.py”, line 226, in average_molar_mass
return mass / moles
ZeroDivisionError: float division by zero

Anyone know what the issue is here? I’m using OpenMC v0.13.3

2 Likes

Thanks for posting and welcome to the community

I would expect that sort of error if the material contained no nuclides.

Thanks for including the xml and the two lines of python. Do you have another line that reads the xml file in to a material object?

1 Like

Also I just wanted to mention this plot_xs function has been upgraded recently and the next release or the current development branch as a slightly different interface. examples are here for the future more flexible cross section plotting by shimwell · Pull Request #2478 · openmc-dev/openmc · GitHub

1 Like

No I don’t have any more lines in my python code. Could you give me an example of how to read the xml into a material object? I just assumed that defining mat from openmc.Material would do that.

You could use the openmc.Materials.from_xml class method to read in a materials xml file
https://docs.openmc.org/en/stable/pythonapi/generated/openmc.Materials.html#openmc.Materials.from_xml

However I would be tempted to rebuild the material with the python API

mat = openmc.Material()
mat.add_nuclide('Np237', 0.002548104822851506)
...
mat.set_density('g/cm3', 2.336712)
2 Likes

I rebuilt the fuel as you said and it works now. Thanks!
test_plot

3 Likes