@@ -378,12 +378,12 @@ def position_to_cell_corners(self, pos):
378378 ----------
379379 pos : np.array
380380 (N, 2) array of xy coordinates representing the positions of N points.
381-
381+
382382 Returns
383383 -------
384384 globalidx : np.array
385- (N, 4) array of global indices corresponding to the 4 corner nodes of the cell
386- each point lies in. If a point lies outside the support, its corresponding entry
385+ (N, 4) array of global indices corresponding to the 4 corner nodes of the cell
386+ each point lies in. If a point lies outside the support, its corresponding entry
387387 will be set to -1.
388388 inside : np.array
389389 (N,) boolean array indicating whether each point is inside the support domain.
@@ -490,9 +490,31 @@ def position_to_cell_vertices(self, pos):
490490 def onGeometryChange (self ):
491491 pass
492492
493- def vtk (self , node_properties = {}, cell_properties = {}):
494- raise NotImplementedError ("VTK output not implemented for structured grid" )
495- pass
493+ def vtk (self , z = 0.0 , * , node_properties = {}, cell_properties = {}):
494+ """
495+ Create a vtk unstructured grid from the mesh
496+ """
497+ try :
498+ import pyvista as pv
499+ except ImportError :
500+ raise ImportError ("pyvista is required for this functionality" )
501+
502+ from pyvista import CellType
503+
504+ points = np .zeros ((self .n_nodes , 3 ))
505+ points [:, :2 ] = self .nodes
506+ points [:, 2 ] = z
507+ celltype = np .full (self .n_elements , CellType .QUAD , dtype = np .uint8 )
508+ vtk_elements = self .elements [:, [0 , 1 , 3 , 2 ]]
509+ elements = np .hstack (
510+ [np .full ((vtk_elements .shape [0 ], 1 ), 4 , dtype = int ), vtk_elements .astype (np .int64 )]
511+ ).ravel ()
512+ grid = pv .UnstructuredGrid (elements , celltype , points )
513+ for key , value in node_properties .items ():
514+ grid .point_data [key ] = value
515+ for key , value in cell_properties .items ():
516+ grid .cell_data [key ] = value
517+ return grid
496518
497519 def get_operators (self , weights : Dict [str , float ]) -> Dict [str , Tuple [np .ndarray , float ]]:
498520 """Get
@@ -509,8 +531,8 @@ def get_operators(self, weights: Dict[str, float]) -> Dict[str, Tuple[np.ndarray
509531 """
510532 # in a map we only want the xy operators
511533 operators = {
512- ' dxy' : (Operator .Dxy_mask [1 , :, :], weights [' dxy' ] * 2 ),
513- ' dxx' : (Operator .Dxx_mask [1 , :, :], weights [' dxx' ]),
514- ' dyy' : (Operator .Dyy_mask [1 , :, :], weights [' dyy' ]),
534+ " dxy" : (Operator .Dxy_mask [1 , :, :], weights [" dxy" ] * 2 ),
535+ " dxx" : (Operator .Dxx_mask [1 , :, :], weights [" dxx" ]),
536+ " dyy" : (Operator .Dyy_mask [1 , :, :], weights [" dyy" ]),
515537 }
516538 return operators
0 commit comments