Skip to content

Commit

Permalink
fix: add node/cell props to a vtk structured grid
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlangrose committed Sep 2, 2024
1 parent a6b326f commit 37bbb88
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions LoopStructural/interpolators/supports/_3d_base_structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def position_to_cell_index(self, pos: np.ndarray) -> np.ndarray:
cell_indexes[inside, 0] = x[inside] // self.step_vector[None, 0]
cell_indexes[inside, 1] = y[inside] // self.step_vector[None, 1]
cell_indexes[inside, 2] = z[inside] // self.step_vector[None, 2]

return cell_indexes, inside

def position_to_cell_global_index(self, pos):
Expand Down Expand Up @@ -331,12 +332,9 @@ def cell_corner_indexes(self, cell_indexes: np.ndarray) -> np.ndarray:
return corner_indexes

def position_to_cell_corners(self, pos):

cell_indexes, inside = self.position_to_cell_index(pos)
corner_indexes = self.cell_corner_indexes(cell_indexes)

globalidx = self.global_node_indices(corner_indexes)

# if global index is not inside the support set to -1
globalidx[~inside] = -1
return globalidx, inside
Expand Down Expand Up @@ -451,7 +449,7 @@ def element_scale(self):
# all elements are the same size
return 1.0

def vtk(self):
def vtk(self, node_properties={}, cell_properties={}):
try:
import pyvista as pv
except ImportError:
Expand All @@ -464,4 +462,9 @@ def vtk(self):
[np.zeros(self.elements.shape[0], dtype=int)[:, None] + 8, self.elements]
)
elements = elements.flatten()
return pv.UnstructuredGrid(elements, celltype, self.nodes)
grid = pv.UnstructuredGrid(elements, celltype, self.nodes)
for key, value in node_properties.items():
grid.point_arrays[key] = value
for key, value in cell_properties.items():
grid.cell_arrays[key] = value
return grid

0 comments on commit 37bbb88

Please sign in to comment.