Skip to content

Commit

Permalink
Made sure linking operation takes place in the right order.
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Sep 10, 2024
1 parent 057486b commit e108ac3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions montepy/mcnp_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, file_name):
self._input_file = MCNP_InputFile(file_name)
self._title = None
self._message = None
self.__unpickled = False
self._print_in_data_block = CellDataPrintController()
self._original_inputs = []
self._cells = Cells(problem=self)
Expand All @@ -44,9 +45,7 @@ def __init__(self, file_name):

def __setstate__(self, nom_nom):
self.__dict__.update(nom_nom)
for collection in {"cells", "surfaces", "data_inputs"}:
for obj in getattr(self, collection):
obj.link_to_problem(self)
self.__unpickled = True

@property
def original_inputs(self):
Expand All @@ -64,6 +63,13 @@ def original_inputs(self):
"""
return self._original_inputs

def __relink_objs(self):
if self.__unpickled:
for collection in {"_cells", "_surfaces", "_data_inputs"}:
for obj in getattr(self, collection):
obj.link_to_problem(self)
self.__unpickled = False

@property
def cells(self):
"""
Expand All @@ -72,6 +78,7 @@ def cells(self):
:return: a collection of the Cell objects, ordered by the order they were in the input file.
:rtype: Cells
"""
self.__relink_objs()
return self._cells

@cells.setter
Expand Down Expand Up @@ -141,6 +148,7 @@ def surfaces(self):
:return: a collection of the Surface objects, ordered by the order they were in the input file.
:rtype: Surfaces
"""
self.__relink_objs()
return self._surfaces

@property
Expand All @@ -151,6 +159,7 @@ def materials(self):
:return: a colection of the Material objects, ordered by the order they were in the input file.
:rtype: Materials
"""
self.__relink_objs()
return self._materials

@materials.setter
Expand Down Expand Up @@ -183,6 +192,7 @@ def data_inputs(self):
:return: a list of the :class:`~montepy.data_cards.data_card.DataCardAbstract` objects, ordered by the order they were in the input file.
:rtype: list
"""
self.__relink_objs()
return self._data_inputs

@property
Expand Down

0 comments on commit e108ac3

Please sign in to comment.