Skip to content

Commit

Permalink
Updated material parser rules to work with libraryless ZAID.
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Feb 12, 2024
1 parent e463a08 commit 8b54488
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion montepy/data_inputs/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from montepy.data_inputs.isotope import Isotope
from montepy.data_inputs.material_component import MaterialComponent
from montepy.input_parser import syntax_node
from montepy.input_parser.material_parser import MaterialParser
from montepy import mcnp_object
from montepy.numbered_mcnp_object import Numbered_MCNP_Object
from montepy.errors import *
Expand All @@ -27,6 +28,8 @@ class Material(data_input.DataInputAbstract, Numbered_MCNP_Object):
:type input: Input
"""

_parser = MaterialParser()

def __init__(self, input=None):
self._material_components = {}
self._thermal_scattering = None
Expand All @@ -43,7 +46,6 @@ def __init__(self, input=None):
def batch_gen():
it = iter(isotope_fractions)
while batch := tuple(itertools.islice(it, 2)):
print(batch)
yield batch

iterator = batch_gen()
Expand Down
1 change: 1 addition & 0 deletions montepy/input_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from . import cell_parser
from . import data_parser
from . import input_reader
from . import material_parser
from . import mcnp_input
from . import parser_base
from . import read_parser
Expand Down
31 changes: 31 additions & 0 deletions montepy/input_parser/material_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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 MaterialParser(DataParser):
debugfile = None

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

@_("isotope_fractions", "number_sequence", "isotope_hybrid_fractions")
def isotopes(self, p):
return p[0]

@_("number_sequence isotope_fraction", "isotope_hybrid_fractions isotope_fraction")
def isotope_hybrid_fractions(self, p):
ret = p[0]
for node in p.isotope_fraction[1:]:
ret.append(node)
return ret

0 comments on commit 8b54488

Please sign in to comment.