Skip to content

Commit 8e4d6f2

Browse files
authored
Merge pull request #102 from paulromano/mcnp-expand-weight
Support expanding elements in MCNP by weight percent
2 parents 1e72fcb + d84fc05 commit 8e4d6f2

7 files changed

Lines changed: 3674 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
* The `Plugin.__call__` method now supports a `cleanup` argument
1313
([#92](https://github.com/watts-dev/watts/pull/92))
1414
* Support for natural element expansion in `PluginMCNP`
15-
([#93](https://github.com/watts-dev/watts/pull/93))
15+
([#93](https://github.com/watts-dev/watts/pull/93),
16+
[#102](https://github.com/watts-dev/watts/pull/102))
1617
* Reorganize the structure of `csv_data` generated by `PluginSAS` ([#98](https://github.com/watts-dev/watts/pull/98))
1718

1819
### Fixed

doc/source/user/plugins.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ MCNP input file, this feature can be utilized by adding a `filter section
242242
.. code-block:: jinja
243243
244244
{% filter expand_element %}
245-
m1 24000.70c 0.17
246-
26000.70c 0.79
247-
28000.70c 0.10
248-
42000.70c 0.02
245+
m1 24000.70c -0.17
246+
26000.70c -0.79
247+
28000.70c -0.10
248+
42000.70c -0.02
249249
{% endfilter %}
250250
251251
Natural elements can be represented using the standard ZAID identifiers as above
@@ -254,10 +254,10 @@ Natural elements can be represented using the standard ZAID identifiers as above
254254
.. code-block:: jinja
255255
256256
{% filter expand_element %}
257-
m1 Cr.70c 0.17
258-
Fe.70c 0.79
259-
Ni.70c 0.10
260-
Mo.70c 0.02
257+
m1 Cr.70c -0.17
258+
Fe.70c -0.79
259+
Ni.70c -0.10
260+
Mo.70c -0.02
261261
{% endfilter %}
262262
263263
The ``expand_element`` custom filter also accepts a single argument specifying
@@ -266,10 +266,10 @@ what cross section suffix to apply by default when one is missing:
266266
.. code-block:: jinja
267267
268268
{% filter expand_element('70c') %}
269-
m1 Cr 0.17
270-
Fe 0.79
271-
Ni 0.10
272-
Mo 0.02
269+
m1 Cr -0.17
270+
Fe -0.79
271+
Ni -0.10
272+
Mo -0.02
273273
{% endfilter %}
274274
275275
By default, :class:`~watts.PluginMCNP` will look for the ``xsdir`` file found

doc/source/user/usage.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ object::
3737
values=[10.0, 20.0, 0.05]
3838
)
3939

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

4542
params.save('parameters.pkl')
4643

src/watts/fundamental_data.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2727
"""
2828

29+
import itertools
2930
import re
30-
from typing import List, Tuple
31+
from pathlib import Path
32+
from typing import List, Tuple, Dict
3133

3234

3335
ATOMIC_SYMBOL = {
@@ -188,3 +190,42 @@ def isotopes(element: str) -> List[Tuple[str, float]]:
188190
if re.match(r'{}\d+'.format(element), kv[0]):
189191
result.append(kv)
190192
return result
193+
194+
195+
# Used in atomic_mass function as a cache
196+
_ATOMIC_MASS: Dict[str, float] = {}
197+
198+
199+
def atomic_mass(nuclide):
200+
"""Return atomic mass of isotope in atomic mass units.
201+
202+
Atomic mass data comes from the `Atomic Mass Evaluation 2020
203+
<https://doi.org/10.1088/1674-1137/abddaf>`_.
204+
205+
Parameters
206+
----------
207+
nuclide : str
208+
Name of nuclide, e.g., 'Pu239'
209+
210+
Returns
211+
-------
212+
float
213+
Atomic mass of nuclide in [amu]
214+
215+
"""
216+
if not _ATOMIC_MASS:
217+
# Load data from AME2020 file
218+
mass_file = Path(__file__).with_name('mass_1.mas20.txt')
219+
with mass_file.open('r') as ame:
220+
# Read lines in file starting at line 37
221+
for line in itertools.islice(ame, 36, None):
222+
name = f'{line[20:22].strip()}{int(line[16:19])}'
223+
mass = float(line[106:109]) + 1e-6*float(
224+
line[110:116] + '.' + line[117:123])
225+
_ATOMIC_MASS[name.lower()] = mass
226+
227+
# Get rid of metastable information
228+
if '_' in nuclide:
229+
nuclide = nuclide[:nuclide.find('_')]
230+
231+
return _ATOMIC_MASS[nuclide.lower()]

0 commit comments

Comments
 (0)