Fixing plot xs for when plotting element string reaction (#3029)

This commit is contained in:
Jonathan Shimwell 2024-06-10 18:18:04 +01:00 committed by GitHub
parent 2a53aba1c1
commit e6c5f56ee2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View file

@ -59,10 +59,15 @@ def _get_legend_label(this, type):
"""Gets a label for the element or nuclide or material and reaction plotted"""
if isinstance(this, str):
if type in openmc.data.DADZ:
z, a, m = openmc.data.zam(this)
da, dz = openmc.data.DADZ[type]
gnds_name = openmc.data.gnds_name(z + dz, a + da, m)
return f'{this} {type} {gnds_name}'
if this in ELEMENT_NAMES:
return f'{this} {type}'
else: # this is a nuclide so the legend can contain more information
z, a, m = openmc.data.zam(this)
da, dz = openmc.data.DADZ[type]
gnds_name = openmc.data.gnds_name(z + dz, a + da, m)
# makes a string with nuclide reaction and new nuclide
# For example "Be9 (n,2n) Be8"
return f'{this} {type} {gnds_name}'
return f'{this} {type}'
elif this.name == '':
return f'Material {this.id} {type}'

View file

@ -75,7 +75,7 @@ def test_calculate_cexs_with_materials(test_mat):
@pytest.mark.parametrize("this", ["Be", "Be9"])
def test_plot_xs(this):
from matplotlib.figure import Figure
assert isinstance(openmc.plot_xs({this: ['total', 'elastic']}), Figure)
assert isinstance(openmc.plot_xs({this: ['total', 'elastic', 16, '(n,2n)']}), Figure)
def test_plot_xs_mat(test_mat):