From ece5de1a7f4099faae1288eae1b7b2c3ef5789b2 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 12 Jun 2024 20:29:53 -0500 Subject: [PATCH 1/5] Wrote tally segment test to replicate #377. --- tests/test_tally.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_tally.py b/tests/test_tally.py index 9e38df73..07b4d9e9 100644 --- a/tests/test_tally.py +++ b/tests/test_tally.py @@ -6,6 +6,7 @@ from unittest import TestCase +import pytest class TestTallyParser(TestCase): @@ -38,3 +39,9 @@ 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"]) +def test_tally_segment_init(line): + input = Input([line], BlockType.DATA) + data = parse_data(input) From 16b58d6d2db3bacc0091f42273c8646198217894 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 12 Jun 2024 20:59:41 -0500 Subject: [PATCH 2/5] Added tally segment tally parser as fall back for now. --- montepy/data_inputs/data_parser.py | 2 ++ montepy/data_inputs/tally_segment.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 montepy/data_inputs/tally_segment.py diff --git a/montepy/data_inputs/data_parser.py b/montepy/data_inputs/data_parser.py index ab893003..5e8b9b1b 100644 --- a/montepy/data_inputs/data_parser.py +++ b/montepy/data_inputs/data_parser.py @@ -7,6 +7,7 @@ material, mode, tally, + tally_segment, tally_multiplier, thermal_scattering, universe_input, @@ -23,6 +24,7 @@ mode.Mode, tally.Tally, tally_multiplier.TallyMultiplier, + tally_segment.TallySegment, thermal_scattering.ThermalScatteringLaw, transform.Transform, volume.Volume, diff --git a/montepy/data_inputs/tally_segment.py b/montepy/data_inputs/tally_segment.py new file mode 100644 index 00000000..52ce82c5 --- /dev/null +++ b/montepy/data_inputs/tally_segment.py @@ -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_parser import TallyParser + + +class TallySegment(DataInputAbstract): + """ """ + + _parser = TallyParser() + + @staticmethod + def _class_prefix(): + return "fs" + + @staticmethod + def _has_number(): + return True + + @staticmethod + def _has_classifier(): + return 0 From c4341387f5865ad2b09d99d9b0bc06fa79d7ebdd Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Wed, 12 Jun 2024 21:01:57 -0500 Subject: [PATCH 3/5] Updated changelog to include #377 --- doc/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst index 86e3ecf1..3ff9a8a8 100644 --- a/doc/source/changelog.rst +++ b/doc/source/changelog.rst @@ -5,6 +5,7 @@ MontePy Changelog ---------------------- **Bug fixes** +* Fixed bug with parsing tally segments (#377) **CI/CD** * Fixed project metadata for author to show up correctly on PyPI (#408) From 2e70529b32be84d774e9df60d5180bda7e76748e Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Mon, 17 Jun 2024 10:48:01 -0500 Subject: [PATCH 4/5] Made tally segment tests more exhaustive, thanks @tjlaboss. --- tests/test_tally.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test_tally.py b/tests/test_tally.py index 07b4d9e9..9b840321 100644 --- a/tests/test_tally.py +++ b/tests/test_tally.py @@ -41,7 +41,16 @@ def test_parsing_tally_multiplier(self): data = parse_data(input) -@pytest.mark.parametrize("line", ["fs14 -123", "fs12 -456 t"]) +@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) From f9e0d3c9ac715d8958fa3934bd302c83f9afd6b5 Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Mon, 1 Jul 2024 13:28:02 -0500 Subject: [PATCH 5/5] Made a simple tally segment parser. --- montepy/data_inputs/tally_segment.py | 4 +- montepy/input_parser/tally_seg_parser.py | 61 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 montepy/input_parser/tally_seg_parser.py diff --git a/montepy/data_inputs/tally_segment.py b/montepy/data_inputs/tally_segment.py index 52ce82c5..9a78cea2 100644 --- a/montepy/data_inputs/tally_segment.py +++ b/montepy/data_inputs/tally_segment.py @@ -1,13 +1,13 @@ # Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved. import montepy from montepy.data_inputs.data_input import DataInputAbstract -from montepy.input_parser.tally_parser import TallyParser +from montepy.input_parser.tally_seg_parser import TallySegmentParser class TallySegment(DataInputAbstract): """ """ - _parser = TallyParser() + _parser = TallySegmentParser() @staticmethod def _class_prefix(): diff --git a/montepy/input_parser/tally_seg_parser.py b/montepy/input_parser/tally_seg_parser.py new file mode 100644 index 00000000..25ae0856 --- /dev/null +++ b/montepy/input_parser/tally_seg_parser.py @@ -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} + )