diff --git a/openmc/plotter.py b/openmc/plotter.py index 849672fceb8..97ca5f92975 100644 --- a/openmc/plotter.py +++ b/openmc/plotter.py @@ -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""" diff --git a/tests/unit_tests/test_plotter.py b/tests/unit_tests/test_plotter.py index fd635d89d5e..2c195c5e120 100644 --- a/tests/unit_tests/test_plotter.py +++ b/tests/unit_tests/test_plotter.py @@ -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)