Merge pull request #1839 from Shimwell/allowing_lower_case_element_symbols_in_add_element

changing element to element.title to catch lowercase entries
This commit is contained in:
Paul Romano 2021-05-27 07:54:08 -05:00 committed by GitHub
commit ef128f5609
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -521,6 +521,19 @@ class Material(IDManagerMixin):
if element is None:
msg = 'Element name "{}" not recognised'.format(el)
raise ValueError(msg)
else:
if element[0].islower():
msg = 'Element name "{}" should start with an uppercase ' \
'letter'.format(element)
raise ValueError(msg)
if len(element) == 2 and element[1].isupper():
msg = 'Element name "{}" should end with a lowercase ' \
'letter'.format(element)
raise ValueError(msg)
# skips the first entry of ATOMIC_SYMBOL which is n for neutron
if element not in list(openmc.data.ATOMIC_SYMBOL.values())[1:]:
msg = 'Element name "{}" not recognised'.format(element)
raise ValueError(msg)
if self._macroscopic is not None:
msg = 'Unable to add an Element to Material ID="{}" as a ' \

View file

@ -54,6 +54,15 @@ def test_elements():
m.add_element('U', 1.0, enrichment=70.0, enrichment_target='U235')
with pytest.raises(ValueError):
m.add_element('He', 1.0, enrichment=17.0, enrichment_target='He6')
with pytest.raises(ValueError):
m.add_element('li', 1.0) # should fail as 1st char is lowercase
with pytest.raises(ValueError):
m.add_element('LI', 1.0) # should fail as 2nd char is uppercase
with pytest.raises(ValueError):
m.add_element('Xx', 1.0) # should fail as Xx is not an element
with pytest.raises(ValueError):
m.add_element('n', 1.0) # check to avoid n for neutron being accepted
def test_elements_by_name():
"""Test adding elements by name"""