Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.2.9 #428

Merged
merged 13 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion doc/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
MontePy Changelog
=================

*Next Version*
0.2.9
----------------------

**Bug fixes**

* Fixed bug with parsing tally segments (:issue:`377`)

0.2.8
----------------------


**Documentation**

* Added link to the PyPI project on the Sphinx site (:issue:`410`)
Expand Down
2 changes: 2 additions & 0 deletions montepy/data_inputs/data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
material,
mode,
tally,
tally_segment,
tally_multiplier,
thermal_scattering,
universe_input,
Expand All @@ -23,6 +24,7 @@
mode.Mode,
tally.Tally,
tally_multiplier.TallyMultiplier,
tally_segment.TallySegment,
thermal_scattering.ThermalScatteringLaw,
transform.Transform,
volume.Volume,
Expand Down
22 changes: 22 additions & 0 deletions montepy/data_inputs/tally_segment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved.
import montepy
from montepy.data_inputs.data_input import DataInputAbstract
from montepy.input_parser.tally_seg_parser import TallySegmentParser


class TallySegment(DataInputAbstract):
""" """

_parser = TallySegmentParser()

@staticmethod
def _class_prefix():
return "fs"

@staticmethod
def _has_number():
return True

@staticmethod
def _has_classifier():
return 0
61 changes: 61 additions & 0 deletions montepy/input_parser/tally_seg_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved.
from montepy.input_parser.data_parser import DataParser
from montepy.input_parser import syntax_node


class TallySegmentParser(DataParser):
""" """

debugfile = None

@_("introduction tally_specification")
def tally(self, p):
ret = {}
for key, node in p.introduction.nodes.items():
ret[key] = node
ret["tally"] = p.tally_specification
return syntax_node.SyntaxNode("data", ret)

@_(
"tally_numbers",
"tally_numbers end_phrase",
"tally_numbers end_phrase end_phrase",
)
def tally_specification(self, p):
if hasattr(p, "end_phrase"):
text = p.end_phrase
else:
text = syntax_node.ValueNode(None, str)

return syntax_node.SyntaxNode(
"tally list", {"tally": p.tally_numbers, "end": text}
)

@_("PARTICLE", "PARTICLE padding", "TEXT", "TEXT padding")
def end_phrase(self, p):
"""
A non-zero number with or without padding.

:returns: a float ValueNode
:rtype: ValueNode
"""
return self._flush_phrase(p, str)

@_(
"tally_numbers tally_numbers",
"number_sequence",
"tally_numbers padding",
)
def tally_numbers(self, p):
if hasattr(p, "tally_numbers"):
ret = p.tally_numbers
ret.nodes["right"] += p.padding
return ret
if hasattr(p, "tally_numbers1"):
return syntax_node.SyntaxNode("tally tree", {"left": p[0], "right": p[1]})
else:
left = syntax_node.PaddingNode(None)
right = syntax_node.PaddingNode(None)
return syntax_node.SyntaxNode(
"tally set", {"left": left, "tally": p[0], "right": right}
)
16 changes: 16 additions & 0 deletions tests/test_tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


from unittest import TestCase
import pytest


class TestTallyParser(TestCase):
Expand Down Expand Up @@ -38,3 +39,18 @@ def test_parsing_tally_multiplier(self):
print(test)
input = Input([test], BlockType.DATA)
data = parse_data(input)


@pytest.mark.parametrize(
"line",
[
"fs14 -123",
"fs12 -456 t",
"fs11 -1 -2",
"fs16 +1 +2 c",
"fs17 -1 -2 t c",
],
)
def test_tally_segment_init(line):
input = Input([line], BlockType.DATA)
data = parse_data(input)
Loading