mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Don't have atomic_mass/atomic_weight return None for invalid
This commit is contained in:
parent
8487915f2a
commit
ac28407aa2
2 changed files with 28 additions and 14 deletions
|
|
@ -1,10 +1,9 @@
|
|||
import itertools
|
||||
from math import sqrt
|
||||
import os
|
||||
import re
|
||||
from warnings import warn
|
||||
|
||||
from numpy import sqrt
|
||||
|
||||
|
||||
# Isotopic abundances from Meija J, Coplen T B, et al, "Isotopic compositions
|
||||
# of the elements 2013 (IUPAC Technical Report)", Pure. Appl. Chem. 88 (3),
|
||||
|
|
@ -142,19 +141,18 @@ _GND_NAME_RE = re.compile(r'([A-Zn][a-z]*)(\d+)((?:_[em]\d+)?)')
|
|||
def atomic_mass(isotope):
|
||||
"""Return atomic mass of isotope in atomic mass units.
|
||||
|
||||
Atomic mass data comes from the Atomic Mass Evaluation 2012, published in
|
||||
Chinese Physics C 36 (2012), 1287--1602.
|
||||
Atomic mass data comes from the `Atomic Mass Evaluation 2012
|
||||
<https://www-nds.iaea.org/amdc/ame2012/AME2012-1.pdf>`_.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
isotope : str
|
||||
Name of isotope, e.g. 'Pu239'
|
||||
Name of isotope, e.g., 'Pu239'
|
||||
|
||||
Returns
|
||||
-------
|
||||
float or None
|
||||
Atomic mass of isotope in atomic mass units. If the isotope listed does
|
||||
not have a known atomic mass, None is returned.
|
||||
float
|
||||
Atomic mass of isotope in [amu]
|
||||
|
||||
"""
|
||||
if not _ATOMIC_MASS:
|
||||
|
|
@ -185,7 +183,7 @@ def atomic_mass(isotope):
|
|||
if '_' in isotope:
|
||||
isotope = isotope[:isotope.find('_')]
|
||||
|
||||
return _ATOMIC_MASS.get(isotope.lower())
|
||||
return _ATOMIC_MASS[isotope.lower()]
|
||||
|
||||
|
||||
def atomic_weight(element):
|
||||
|
|
@ -201,16 +199,19 @@ def atomic_weight(element):
|
|||
|
||||
Returns
|
||||
-------
|
||||
float or None
|
||||
Atomic weight of element in atomic mass units. If the element listed does
|
||||
not exist, None is returned.
|
||||
float
|
||||
Atomic weight of element in [amu]
|
||||
|
||||
"""
|
||||
weight = 0.
|
||||
for nuclide, abundance in NATURAL_ABUNDANCE.items():
|
||||
if re.match(r'{}\d+'.format(element), nuclide):
|
||||
weight += atomic_mass(nuclide) * abundance
|
||||
return None if weight == 0. else weight
|
||||
if weight > 0.:
|
||||
return weight
|
||||
else:
|
||||
raise ValueError("No naturally-occurring isotopes for element '{}'."
|
||||
.format(element))
|
||||
|
||||
|
||||
def water_density(temperature, pressure=0.1013):
|
||||
|
|
@ -236,7 +237,7 @@ def water_density(temperature, pressure=0.1013):
|
|||
Returns
|
||||
-------
|
||||
float
|
||||
Water density in units of [g / cm^3]
|
||||
Water density in units of [g/cm^3]
|
||||
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,19 @@ def test_thin():
|
|||
assert f(1.0) == pytest.approx(np.sin(1.0), 0.001)
|
||||
|
||||
|
||||
def test_atomic_mass():
|
||||
assert openmc.data.atomic_mass('H1') == 1.00782503223
|
||||
assert openmc.data.atomic_mass('U235') == 235.043930131
|
||||
with pytest.raises(KeyError):
|
||||
openmc.data.atomic_mass('U100')
|
||||
|
||||
|
||||
def test_atomic_weight():
|
||||
assert openmc.data.atomic_weight('C') == 12.011115164862904
|
||||
with pytest.raises(ValueError):
|
||||
openmc.data.atomic_weight('Qt')
|
||||
|
||||
|
||||
def test_water_density():
|
||||
dens = openmc.data.water_density
|
||||
# These test values are from IAPWS R7-97(2012). They are actually specific
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue