mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Merge branch 'develop' into adding_typehints_to_match_docs_material.py
This commit is contained in:
commit
1a8c248597
8 changed files with 3649 additions and 7 deletions
|
|
@ -17,10 +17,15 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
|||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
|
||||
|
||||
# Allow user to specify <project>_ROOT variables
|
||||
if (NOT (CMAKE_VERSION VERSION_LESS 3.12))
|
||||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
endif()
|
||||
|
||||
# Enable correct usage of CXX_EXTENSIONS
|
||||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
|
||||
cmake_policy(SET CMP0128 NEW)
|
||||
endif()
|
||||
|
||||
#===============================================================================
|
||||
# Command line options
|
||||
#===============================================================================
|
||||
|
|
@ -118,7 +123,7 @@ endif()
|
|||
# Version 1.12 of HDF5 deprecates the H5Oget_info_by_idx() interface.
|
||||
# Thus, we give these flags to allow usage of the old interface in newer
|
||||
# versions of HDF5.
|
||||
if(NOT (${HDF5_VERSION} VERSION_LESS 1.12.0))
|
||||
if(${HDF5_VERSION} VERSION_GREATER_EQUAL 1.12.0)
|
||||
list(APPEND cxxflags -DH5Oget_info_by_idx_vers=1 -DH5O_info_t_vers=1)
|
||||
endif()
|
||||
|
||||
|
|
@ -205,7 +210,7 @@ endif()
|
|||
#===============================================================================
|
||||
|
||||
# CMake 3.13+ will complain about policy CMP0079 unless it is set explicitly
|
||||
if (NOT (CMAKE_VERSION VERSION_LESS 3.13))
|
||||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
|
||||
cmake_policy(SET CMP0079 NEW)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ Core Functions
|
|||
atomic_weight
|
||||
dose_coefficients
|
||||
gnd_name
|
||||
half_life
|
||||
isotopes
|
||||
linearize
|
||||
thin
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import itertools
|
||||
from math import sqrt
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from math import sqrt
|
||||
from warnings import warn
|
||||
|
||||
|
||||
# Isotopic abundances from Meija J, Coplen T B, et al, "Isotopic compositions
|
||||
# of the elements 2013 (IUPAC Technical Report)", Pure. Appl. Chem. 88 (3),
|
||||
# pp. 293-306 (2013). The "representative isotopic abundance" values from
|
||||
|
|
@ -199,6 +200,9 @@ _ATOMIC_MASS = {}
|
|||
# Regex for GND nuclide names (used in zam function)
|
||||
_GND_NAME_RE = re.compile(r'([A-Zn][a-z]*)(\d+)((?:_[em]\d+)?)')
|
||||
|
||||
# Used in half_life function as a cache
|
||||
_HALF_LIFE = {}
|
||||
|
||||
|
||||
def atomic_mass(isotope):
|
||||
"""Return atomic mass of isotope in atomic mass units.
|
||||
|
|
@ -273,6 +277,31 @@ def atomic_weight(element):
|
|||
.format(element))
|
||||
|
||||
|
||||
def half_life(isotope):
|
||||
"""Return half-life of isotope in seconds or None if isotope is stable
|
||||
|
||||
Half-life values are from the `ENDF/B-VIII.0 decay sublibrary
|
||||
<https://www.nndc.bnl.gov/endf-b8.0/download.html>`_.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
isotope : str
|
||||
Name of isotope, e.g., 'Pu239'
|
||||
|
||||
Returns
|
||||
-------
|
||||
float
|
||||
Half-life of isotope in [s]
|
||||
|
||||
"""
|
||||
global _HALF_LIFE
|
||||
if not _HALF_LIFE:
|
||||
# Load ENDF/B-VIII.0 data from JSON file
|
||||
half_life_path = Path(__file__).with_name('half_life.json')
|
||||
_HALF_LIFE = json.loads(half_life_path.read_text())
|
||||
|
||||
return _HALF_LIFE.get(isotope.lower())
|
||||
|
||||
def water_density(temperature, pressure=0.1013):
|
||||
"""Return the density of liquid water at a given temperature and pressure.
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ def _load_dose_icrp116():
|
|||
"""Load effective dose tables from text files"""
|
||||
for particle, filename in _FILES:
|
||||
path = Path(__file__).parent / filename
|
||||
data = np.loadtxt(path, skiprows=3)
|
||||
data = np.loadtxt(path, skiprows=3, encoding='utf-8')
|
||||
data[:, 0] *= 1e6 # Change energies to eV
|
||||
_DOSE_ICRP116[particle] = data
|
||||
|
||||
|
|
|
|||
3563
openmc/data/half_life.json
Normal file
3563
openmc/data/half_life.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -3,7 +3,9 @@ from collections.abc import Iterable
|
|||
from copy import deepcopy
|
||||
from numbers import Real
|
||||
from pathlib import Path
|
||||
|
||||
import os
|
||||
import math
|
||||
import re
|
||||
import typing # imported separately as py3.8 requires typing.Iterable
|
||||
import warnings
|
||||
|
|
@ -144,6 +146,21 @@ class Material(IDManagerMixin):
|
|||
|
||||
return string
|
||||
|
||||
|
||||
@property
|
||||
def activity(self):
|
||||
"""Returns the total activity of the material in Becquerels."""
|
||||
|
||||
atoms_per_barn_cm = self.get_nuclide_atom_densities()
|
||||
total_activity = 0
|
||||
for key, value in atoms_per_barn_cm.items():
|
||||
half_life = openmc.data.half_life(key)
|
||||
if half_life:
|
||||
total_activity += value[1] / half_life
|
||||
total_activity *= math.log(2) * 1e24 * self.volume
|
||||
|
||||
return total_activity
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -32,7 +32,7 @@ kwargs = {
|
|||
# Data files and libraries
|
||||
'package_data': {
|
||||
'openmc.lib': ['libopenmc.{}'.format(suffix)],
|
||||
'openmc.data': ['mass16.txt', 'BREMX.DAT', '*.h5'],
|
||||
'openmc.data': ['mass16.txt', 'BREMX.DAT', 'half_life.json', '*.h5'],
|
||||
'openmc.data.effective_dose': ['*.txt']
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -404,3 +404,30 @@ def test_mix_materials():
|
|||
assert m3.density == pytest.approx(dens3)
|
||||
assert m4.density == pytest.approx(dens4)
|
||||
assert m5.density == pytest.approx(dens5)
|
||||
|
||||
|
||||
def test_activity_of_stable():
|
||||
"""Creates a material with stable isotopes to checks the activity is 0"""
|
||||
m1 = openmc.Material()
|
||||
m1.add_element("Fe", 1)
|
||||
m1.set_density('g/cm3', 1)
|
||||
m1.volume = 1
|
||||
assert m1.activity == 0
|
||||
|
||||
|
||||
def test_activity_of_tritium():
|
||||
"""Checks that 1g of tritium has the correct activity"""
|
||||
m1 = openmc.Material()
|
||||
m1.add_nuclide("H3", 1)
|
||||
m1.set_density('g/cm3', 1)
|
||||
m1.volume = 1
|
||||
assert pytest.approx(m1.activity) == 3.559778e14
|
||||
|
||||
|
||||
def test_activity_of_metastable():
|
||||
"""Checks that 1 mol of a Tc99_m1 nuclides has the correct activity"""
|
||||
m1 = openmc.Material()
|
||||
m1.add_nuclide("Tc99_m1", 1)
|
||||
m1.set_density('g/cm3', 1)
|
||||
m1.volume = 98.9
|
||||
assert pytest.approx(m1.activity, rel=0.001) == 1.93e19
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue