Skip to content

Commit 2b05f69

Browse files
committed
fix: copy dictionary before creating structured grid to prevent shared variable
1 parent 0f565f4 commit 2b05f69

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

LoopStructural/datatypes/_bounding_box.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from LoopStructural.utils import rng
55
from LoopStructural.datatypes._structured_grid import StructuredGrid
66
import numpy as np
7+
import copy
78

89
from LoopStructural.utils.logging import getLogger
910

@@ -412,11 +413,16 @@ def vtk(self):
412413
def structured_grid(
413414
self, cell_data: Dict[str, np.ndarray] = {}, vertex_data={}, name: str = "bounding_box"
414415
):
416+
# python is passing a reference to the cell_data, vertex_data dicts so we need to
417+
# copy them to make sure that different instances of StructuredGrid are not sharing the same
418+
# underlying objects
419+
_cell_data = copy.deepcopy(cell_data)
420+
_vertex_data = copy.deepcopy(vertex_data)
415421
return StructuredGrid(
416422
origin=self.global_origin,
417423
step_vector=self.step_vector,
418424
nsteps=self.nsteps,
419-
cell_properties=cell_data,
420-
properties=vertex_data,
425+
cell_properties=_cell_data,
426+
properties=_vertex_data,
421427
name=name,
422428
)

0 commit comments

Comments
 (0)