Skip to content

Commit

Permalink
changing y axis label for heating plots (#2859)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
  • Loading branch information
shimwell and paulromano committed Apr 5, 2024
1 parent 0aad22d commit 27bd315
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
35 changes: 24 additions & 11 deletions openmc/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,37 @@ def _get_legend_label(this, type):
def _get_yaxis_label(reactions, divisor_types):
"""Gets a y axis label for the type of data plotted"""

if all(isinstance(item, str) for item in reactions.keys()):
stem = 'Microscopic'
if divisor_types:
mid, units = 'Data', ''
else:
mid, units = 'Cross Section', '[b]'
heat_values = {"heating", "heating-local", "damage-energy"}

# if all the types are heating a different stem and unit is needed
if all(set(value).issubset(heat_values) for value in reactions.values()):
stem = "Heating"
elif all(isinstance(item, str) for item in reactions.keys()):
for nuc_reactions in reactions.values():
for reaction in nuc_reactions:
if reaction in heat_values:
raise TypeError(
"Mixture of heating and Microscopic reactions. "
"Invalid type for plotting"
)
stem = "Microscopic"
elif all(isinstance(item, openmc.Material) for item in reactions.keys()):
stem = 'Macroscopic'
if divisor_types:
mid, units = 'Data', ''
else:
mid, units = 'Cross Section', '[1/cm]'
else:
msg = "Mixture of openmc.Material and elements/nuclides. Invalid type for plotting"
raise TypeError(msg)

return f'{stem} {mid} {units}'
if divisor_types:
mid, units = "Data", ""
else:
mid = "Cross Section"
units = {
"Macroscopic": "[1/cm]",
"Microscopic": "[b]",
"Heating": "[eV-barn]",
}[stem]

return f'{stem} {mid} {units}'

def _get_title(reactions):
"""Gets a title for the type of data plotted"""
Expand Down
15 changes: 15 additions & 0 deletions tests/unit_tests/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ def test_plot_axes_labels():
)
assert axis_label == 'Microscopic Cross Section [b]'

axis_label = openmc.plotter._get_yaxis_label(
reactions={
"Li": ["heating", "heating-local"],
"Li7": ["heating"],
"Be": ["damage-energy"],
},
divisor_types=False,
)
assert axis_label == "Heating Cross Section [eV-barn]"

with pytest.raises(TypeError):
axis_label = openmc.plotter.plot_xs(
reactions={"Li": ["heating", "heating-local"], "Be9": ["(n,2n)"]}
)

# just materials
mat1 = openmc.Material()
mat1.add_nuclide('Fe56', 1)
Expand Down

0 comments on commit 27bd315

Please sign in to comment.