Skip to content

Commit

Permalink
Made update pointers.
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Jan 20, 2024
1 parent de86019 commit c2471c2
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions montepy/data_inputs/tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from montepy.input_parser.tally_parser import TallyParser
from montepy.input_parser import syntax_node
from montepy.numbered_mcnp_object import Numbered_MCNP_Object
from montepy.surface_collection import Surfaces
from montepy.utilities import *

_TALLY_TYPE_MODULUS = 10
Expand Down Expand Up @@ -92,6 +93,10 @@ def number(self):
"""
pass

def update_pointers(self, data_inputs):
if self._problem is not None:
for group in self.groups:
group.update_pointers(self.problem, *self._obj_type)


class SurfaceTally(Tally):
Expand All @@ -107,11 +112,12 @@ class CellFluxTally(CellTally):


class TallyGroup:
__slots__ = {"_cells", "_old_numbers"}
__slots__ = {"_objs", "_old_numbers", "_obj_name"}

def __init__(self, cells=None, nodes=None):
self._cells = montepy.cells.Cells()
self._cells = None
self._old_numbers = []
self._obj_name = ""

@staticmethod
def parse_tally_specification(tally_spec):
Expand All @@ -121,7 +127,6 @@ def parse_tally_specification(tally_spec):
buff = None
has_total = False
for node in tally_spec:
# TODO handle total
if in_parens:
if node.value == ")":
in_parens = False
Expand All @@ -136,7 +141,14 @@ def parse_tally_specification(tally_spec):
buff = TallyGroup()
buff._append_node(node)
else:
ret.append(TallyGroup(nodes=[node]))
if (
isinstance(node, syntax_node.ValueNode)
and node.type == str
and node.value.lower() == "t"
):
has_total = True
else:
ret.append(TallyGroup(nodes=[node]))
return (ret, has_total)

def _append_node(self, node):
Expand All @@ -147,6 +159,17 @@ def _append_node(self, node):
def append(self, cell):
self._cells.append(cell)

def update_pointers(self, problem, ObjContainer, obj_name):
self._objs = ObjContainer()
obj_source = getattr(problem, f"{obj_name}s")
self._obj_name = obj_name
for number in self._older_numbers:
try:
self._objs.append(obj_source[number])
except KeyError:
# Todo
pass


TALLY_TYPE_CLASS_MAP = {
# TallyType.CURRENT: CurrentTally,
Expand Down

0 comments on commit c2471c2

Please sign in to comment.