Merge pull request #1495 from ChasingNeutrons/develop

Adding elements by name rather than symbol #1468
This commit is contained in:
Sterling Harper 2020-02-29 13:24:51 -05:00 committed by GitHub
commit f62bdae0b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 6 deletions

View file

@ -40,6 +40,12 @@ of an element, you specify the element itself. For example,
mat.add_element('C', 1.0)
This method can also accept case-insensitive element names such as
::
mat.add_element('aluminium', 1.0)
Internally, OpenMC stores data on the atomic masses and natural abundances of
all known isotopes and then uses this data to determine what isotopes should be
added to the material. When the material is later exported to XML for use by the

View file

@ -110,6 +110,49 @@ NATURAL_ABUNDANCE = {
'U238': 0.992742
}
# Dictionary to give element symbols from IUPAC names
# (and some common mispellings)
ELEMENT_SYMBOL = {'neutron': 'n', 'hydrogen': 'H', 'helium': 'He',
'lithium': 'Li', 'beryllium': 'Be', 'boron': 'B',
'carbon': 'C', 'nitrogen': 'N', 'oxygen': 'O', 'fluorine': 'F',
'neon': 'Ne', 'sodium': 'Na', 'magnesium': 'Mg',
'aluminium': 'Al', 'aluminum': 'Al', 'silicon': 'Si',
'phosphorus': 'P', 'sulfur': 'S', 'sulphur': 'S',
'chlorine': 'Cl', 'argon': 'Ar', 'potassium': 'K',
'calcium': 'Ca', 'scandium': 'Sc', 'titanium': 'Ti',
'vanadium': 'V', 'chromium': 'Cr', 'manganese': 'Mn',
'iron': 'Fe', 'cobalt': 'Co', 'nickel': 'Ni', 'copper': 'Cu',
'zinc': 'Zn', 'gallium': 'Ga', 'germanium': 'Ge',
'arsenic': 'As', 'selenium': 'Se', 'bromine': 'Br',
'krypton': 'Kr', 'rubidium': 'Rb', 'strontium': 'Sr',
'yttrium': 'Y', 'zirconium': 'Zr', 'niobium': 'Nb',
'molybdenum': 'Mo', 'technetium': 'Tc', 'ruthenium': 'Ru',
'rhodium': 'Rh', 'palladium': 'Pd', 'silver': 'Ag',
'cadmium': 'Cd', 'indium': 'In', 'tin': 'Sn', 'antimony': 'Sb',
'tellurium': 'Te', 'iodine': 'I', 'xenon': 'Xe',
'caesium': 'Cs', 'cesium': 'Cs', 'barium': 'Ba',
'lanthanum': 'La', 'cerium': 'Ce', 'praseodymium': 'Pr',
'neodymium': 'Nd', 'promethium': 'Pm', 'samarium': 'Sm',
'europium': 'Eu', 'gadolinium': 'Gd', 'terbium': 'Tb',
'dysprosium': 'Dy', 'holmium': 'Ho', 'erbium': 'Er',
'thulium': 'Tm', 'ytterbium': 'Yb', 'lutetium': 'Lu',
'hafnium': 'Hf', 'tantalum': 'Ta', 'tungsten': 'W',
'wolfram': 'W', 'rhenium': 'Re', 'osmium': 'Os',
'iridium': 'Ir', 'platinum': 'Pt', 'gold': 'Au',
'mercury': 'Hg', 'thallium': 'Tl', 'lead': 'Pb',
'bismuth': 'Bi', 'polonium': 'Po', 'astatine': 'At',
'radon': 'Rn', 'francium': 'Fr', 'radium': 'Ra',
'actinium': 'Ac', 'thorium': 'Th', 'protactinium': 'Pa',
'uranium': 'U', 'neptunium': 'Np', 'plutonium': 'Pu',
'americium': 'Am', 'curium': 'Cm', 'berkelium': 'Bk',
'californium': 'Cf', 'einsteinium': 'Es', 'fermium': 'Fm',
'mendelevium': 'Md', 'nobelium': 'No', 'lawrencium': 'Lr',
'rutherfordium': 'Rf', 'dubnium': 'Db', 'seaborgium': 'Sg',
'bohrium': 'Bh', 'hassium': 'Hs', 'meitnerium': 'Mt',
'darmstadtium': 'Ds', 'roentgenium': 'Rg', 'copernicium': 'Cn',
'nihonium': 'Nh', 'flerovium': 'Fl', 'moscovium': 'Mc',
'livermorium': 'Lv', 'tennessine': 'Ts', 'oganesson': 'Og'}
ATOMIC_SYMBOL = {0: 'n', 1: 'H', 2: 'He', 3: 'Li', 4: 'Be', 5: 'B', 6: 'C',
7: 'N', 8: 'O', 9: 'F', 10: 'Ne', 11: 'Na', 12: 'Mg', 13: 'Al',
14: 'Si', 15: 'P', 16: 'S', 17: 'Cl', 18: 'Ar', 19: 'K',

View file

@ -505,7 +505,7 @@ class Material(IDManagerMixin):
Parameters
----------
element : str
Element to add, e.g., 'Zr'
Element to add, e.g., 'Zr' or 'Zirconium'
percent : float
Atom or weight percent
percent_type : {'ao', 'wo'}, optional
@ -517,10 +517,24 @@ class Material(IDManagerMixin):
(natural composition).
"""
cv.check_type('nuclide', element, str)
cv.check_type('percent', percent, Real)
cv.check_value('percent type', percent_type, {'ao', 'wo'})
# Make sure element name is just that
if not element.isalpha():
raise ValueError("Element name should be given by the "
"element's symbol or name, e.g., 'Zr', 'zirconium'")
# Allow for element identifier to be given as a symbol or name
if len(element) > 2:
el = element.lower()
element = openmc.data.ELEMENT_SYMBOL.get(el)
if element is None:
msg = 'Element name "{}" not recognised'.format(el)
raise ValueError(msg)
if self._macroscopic is not None:
msg = 'Unable to add an Element to Material ID="{}" as a ' \
'macroscopic data-set has already been added'.format(self._id)
@ -551,11 +565,6 @@ class Material(IDManagerMixin):
format(enrichment, self._id)
warnings.warn(msg)
# Make sure element name is just that
if not element.isalpha():
raise ValueError("Element name should be given by the "
"element's symbol, e.g., 'Zr'")
# Add naturally-occuring isotopes
element = openmc.Element(element)
for nuclide in element.expand(percent, percent_type, enrichment):

View file

@ -34,6 +34,22 @@ def test_elements():
with pytest.raises(ValueError):
m.add_element('Pu', 1.0, enrichment=3.0)
def test_elements_by_name():
"""Test adding elements by name"""
m = openmc.Material()
m.add_element('woLfrAm', 1.0)
with pytest.raises(ValueError):
m.add_element('uranum', 1.0)
m.add_element('uRaNiUm', 1.0)
m.add_element('Aluminium', 1.0)
a = openmc.Material()
b = openmc.Material()
c = openmc.Material()
a.add_element('sulfur', 1.0)
b.add_element('SulPhUR', 1.0)
c.add_element('S', 1.0)
assert a._nuclides == b._nuclides
assert b._nuclides == c._nuclides
def test_density():
m = openmc.Material()