Skip to content

Commit

Permalink
Merge pull request #537 from idaholab/521-problem-formatting-material…
Browse files Browse the repository at this point in the history
…-with-plib-for-mcnp-input

Fixed bug with plib in Material
  • Loading branch information
MicahGale authored Sep 11, 2024
2 parents bd98d60 + 6e3a273 commit 7d3294d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ MontePy Changelog
**Bug Fixes**

* Fixed a bug where ``problem.materials.append_renumber`` would double add a material to ``problem.data_inputs`` (:issue:`516`).
* Fixed bug where material-level library specifications (e.g., ``m1 plib=84p``) could not be fully parsed (:issue:`521`).

**Performance Improvement**

Expand Down
46 changes: 46 additions & 0 deletions montepy/input_parser/material_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MaterialParser(DataParser):
@_(
"introduction isotopes",
"introduction isotopes parameters",
"introduction isotopes mat_parameters",
)
def material(self, p):
ret = {}
Expand Down Expand Up @@ -47,3 +48,48 @@ def batch_gen():
for group in batch_gen():
new_list.append(("foo", *group))
return new_list

@_(
"mat_parameter",
"parameter",
"mat_parameters mat_parameter",
"mat_parameters parameter",
)
def mat_parameters(self, p):
"""
A list of the parameters (key, value pairs) that allows material libraries.
:returns: all parameters
:rtype: ParametersNode
"""
if len(p) == 1:
params = syntax_node.ParametersNode()
param = p[0]
else:
params = p[0]
param = p[1]
params.append(param)
return params

@_(
"classifier param_seperator library",
)
def mat_parameter(self, p):
"""
A singular Key-value pair that includes a material library.
:returns: the parameter.
:rtype: SyntaxNode
"""
return syntax_node.SyntaxNode(
p.classifier.prefix.value,
{"classifier": p.classifier, "seperator": p.param_seperator, "data": p[2]},
)

@_("NUMBER_WORD")
@_("NUMBER_WORD padding")
def library(self, p):
"""
A library name.
"""
return self._flush_phrase(p, str)
1 change: 1 addition & 0 deletions tests/inputs/test.imcnp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ C water
C foo
m3 1001.80c 2
8016.80c 1
plib=84p
MT3 lwtr.23t h-zr.20t h/zr.28t
C execution
ksrc 0 0 0
Expand Down
10 changes: 10 additions & 0 deletions tests/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ def test_material_update_format():
True,
[2.6999999e-2, 9.9999998e-01],
),
*[
(f"M20 1001.80c 0.5 8016.80c 0.5 {part}={lib}", 20, True, [0.5, 0.5])
for part, lib in [
("nlib", "80c"),
("nlib", "701nc"),
("estep", 1),
("pnlib", "710nc"),
("slib", "80c"),
]
],
],
)
def test_material_init(line, mat_number, is_atom, fractions):
Expand Down

0 comments on commit 7d3294d

Please sign in to comment.