Skip to content

Commit

Permalink
Print warning if no natural isotopes when using add_element and wrote…
Browse files Browse the repository at this point in the history
… unit test (#2938)

Co-authored-by: Catherine Yu <[email protected]>
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
3 people authored Apr 24, 2024
1 parent 1d56adb commit 3370ce1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions openmc/element.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import warnings

import lxml.etree as ET

Expand Down Expand Up @@ -123,6 +124,10 @@ def expand(self, percent, percent_type, enrichment=None,
# Get the nuclides present in nature
natural_nuclides = {name for name, abundance in natural_isotopes(self)}

# Issue warning if no existing nuclides
if len(natural_nuclides) == 0:
warnings.warn(f"No naturally occurring isotopes found for {self}.")

# Create dict to store the expanded nuclides and abundances
abundances = {}

Expand Down
9 changes: 8 additions & 1 deletion tests/unit_tests/test_element.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import openmc
from pytest import approx, raises
from pytest import approx, raises, warns

from openmc.data import NATURAL_ABUNDANCE, atomic_mass

Expand Down Expand Up @@ -37,6 +37,13 @@ def test_expand_enrichment():
assert isotope[1] == approx(ref[isotope[0]])


def test_expand_no_isotopes():
"""Test that correct warning is raised for elements with no isotopes"""
with warns(UserWarning, match='No naturally occurring'):
element = openmc.Element('Tc')
element.expand(100.0, 'ao')


def test_expand_exceptions():
""" Test that correct exceptions are raised for invalid input """

Expand Down

0 comments on commit 3370ce1

Please sign in to comment.