Skip to content

Commit

Permalink
Merge pull request #102 from paulromano/mcnp-expand-weight
Browse files Browse the repository at this point in the history
Support expanding elements in MCNP by weight percent
  • Loading branch information
nstauff authored Jun 28, 2023
2 parents 1e72fcb + d84fc05 commit 8e4d6f2
Show file tree
Hide file tree
Showing 7 changed files with 3,674 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* The `Plugin.__call__` method now supports a `cleanup` argument
([#92](https://github.com/watts-dev/watts/pull/92))
* Support for natural element expansion in `PluginMCNP`
([#93](https://github.com/watts-dev/watts/pull/93))
([#93](https://github.com/watts-dev/watts/pull/93),
[#102](https://github.com/watts-dev/watts/pull/102))
* Reorganize the structure of `csv_data` generated by `PluginSAS` ([#98](https://github.com/watts-dev/watts/pull/98))

### Fixed
Expand Down
24 changes: 12 additions & 12 deletions doc/source/user/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ MCNP input file, this feature can be utilized by adding a `filter section
.. code-block:: jinja
{% filter expand_element %}
m1 24000.70c 0.17
26000.70c 0.79
28000.70c 0.10
42000.70c 0.02
m1 24000.70c -0.17
26000.70c -0.79
28000.70c -0.10
42000.70c -0.02
{% endfilter %}
Natural elements can be represented using the standard ZAID identifiers as above
Expand All @@ -254,10 +254,10 @@ Natural elements can be represented using the standard ZAID identifiers as above
.. code-block:: jinja
{% filter expand_element %}
m1 Cr.70c 0.17
Fe.70c 0.79
Ni.70c 0.10
Mo.70c 0.02
m1 Cr.70c -0.17
Fe.70c -0.79
Ni.70c -0.10
Mo.70c -0.02
{% endfilter %}
The ``expand_element`` custom filter also accepts a single argument specifying
Expand All @@ -266,10 +266,10 @@ what cross section suffix to apply by default when one is missing:
.. code-block:: jinja
{% filter expand_element('70c') %}
m1 Cr 0.17
Fe 0.79
Ni 0.10
Mo 0.02
m1 Cr -0.17
Fe -0.79
Ni -0.10
Mo -0.02
{% endfilter %}
By default, :class:`~watts.PluginMCNP` will look for the ``xsdir`` file found
Expand Down
5 changes: 1 addition & 4 deletions doc/source/user/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ object::
values=[10.0, 20.0, 0.05]
)

Most native Python datatypes (:class:`int`, :class:`float`, :class:`bool`,
:class:`str`, :class:`list`, :class:`set`, :class:`tuple`, :class:`dict`) are
supported along with :class:`NumPy arrays <numpy.ndarray>` as well. Parameters
can be saved to a pickle file::
Parameters can be saved to a pickle file::

params.save('parameters.pkl')

Expand Down
43 changes: 42 additions & 1 deletion src/watts/fundamental_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

import itertools
import re
from typing import List, Tuple
from pathlib import Path
from typing import List, Tuple, Dict


ATOMIC_SYMBOL = {
Expand Down Expand Up @@ -188,3 +190,42 @@ def isotopes(element: str) -> List[Tuple[str, float]]:
if re.match(r'{}\d+'.format(element), kv[0]):
result.append(kv)
return result


# Used in atomic_mass function as a cache
_ATOMIC_MASS: Dict[str, float] = {}


def atomic_mass(nuclide):
"""Return atomic mass of isotope in atomic mass units.
Atomic mass data comes from the `Atomic Mass Evaluation 2020
<https://doi.org/10.1088/1674-1137/abddaf>`_.
Parameters
----------
nuclide : str
Name of nuclide, e.g., 'Pu239'
Returns
-------
float
Atomic mass of nuclide in [amu]
"""
if not _ATOMIC_MASS:
# Load data from AME2020 file
mass_file = Path(__file__).with_name('mass_1.mas20.txt')
with mass_file.open('r') as ame:
# Read lines in file starting at line 37
for line in itertools.islice(ame, 36, None):
name = f'{line[20:22].strip()}{int(line[16:19])}'
mass = float(line[106:109]) + 1e-6*float(
line[110:116] + '.' + line[117:123])
_ATOMIC_MASS[name.lower()] = mass

# Get rid of metastable information
if '_' in nuclide:
nuclide = nuclide[:nuclide.find('_')]

return _ATOMIC_MASS[nuclide.lower()]
Loading

0 comments on commit 8e4d6f2

Please sign in to comment.