@@ -236,6 +236,7 @@ def position_to_cell_index(self, pos: np.ndarray) -> np.ndarray:
236236 cell_indexes [inside , 0 ] = x [inside ] // self .step_vector [None , 0 ]
237237 cell_indexes [inside , 1 ] = y [inside ] // self .step_vector [None , 1 ]
238238 cell_indexes [inside , 2 ] = z [inside ] // self .step_vector [None , 2 ]
239+
239240 return cell_indexes , inside
240241
241242 def position_to_cell_global_index (self , pos ):
@@ -331,12 +332,9 @@ def cell_corner_indexes(self, cell_indexes: np.ndarray) -> np.ndarray:
331332 return corner_indexes
332333
333334 def position_to_cell_corners (self , pos ):
334-
335335 cell_indexes , inside = self .position_to_cell_index (pos )
336336 corner_indexes = self .cell_corner_indexes (cell_indexes )
337-
338337 globalidx = self .global_node_indices (corner_indexes )
339-
340338 # if global index is not inside the support set to -1
341339 globalidx [~ inside ] = - 1
342340 return globalidx , inside
@@ -451,7 +449,7 @@ def element_scale(self):
451449 # all elements are the same size
452450 return 1.0
453451
454- def vtk (self ):
452+ def vtk (self , node_properties = {}, cell_properties = {} ):
455453 try :
456454 import pyvista as pv
457455 except ImportError :
@@ -464,4 +462,9 @@ def vtk(self):
464462 [np .zeros (self .elements .shape [0 ], dtype = int )[:, None ] + 8 , self .elements ]
465463 )
466464 elements = elements .flatten ()
467- return pv .UnstructuredGrid (elements , celltype , self .nodes )
465+ grid = pv .UnstructuredGrid (elements , celltype , self .nodes )
466+ for key , value in node_properties .items ():
467+ grid .point_arrays [key ] = value
468+ for key , value in cell_properties .items ():
469+ grid .cell_arrays [key ] = value
470+ return grid
0 commit comments