added deep copy option
This commit is contained in:
parent
e2fe40c460
commit
6025421d3b
15
field.py
15
field.py
|
|
@ -267,27 +267,30 @@ class Field3d:
|
|||
self.data.setflags(write=flag)
|
||||
return
|
||||
|
||||
def to_vtk(self):
|
||||
def to_vtk(self,deep=False):
|
||||
import pyvista as pv
|
||||
mesh = pv.UniformGrid()
|
||||
mesh.dimensions = self.dim(axis=None)
|
||||
mesh.origin = self.origin
|
||||
mesh.spacing = self.spacing
|
||||
# order needs to be F no matter how array is stored in memory
|
||||
mesh.point_arrays['data'] = self.data.ravel(order='F')
|
||||
if deep:
|
||||
mesh.point_arrays['data'] = self.data.flatten(order='F')
|
||||
else:
|
||||
mesh.point_arrays['data'] = self.data.ravel(order='F')
|
||||
return mesh
|
||||
|
||||
def vtk_contour(self,val):
|
||||
def vtk_contour(self,val,deep=False):
|
||||
if not isinstance(val,(tuple,list)):
|
||||
val = [val]
|
||||
return self.to_vtk().contour(val)
|
||||
return self.to_vtk(deep=deep).contour(val)
|
||||
|
||||
def vtk_slice(self,normal,origin):
|
||||
def vtk_slice(self,normal,origin,deep=False):
|
||||
assert (normal in ('x','y','z') or (isinstance(normal,(tuple,list))
|
||||
and len(normal)==3)), "'normal' must be 'x','y','z' or tuple of length 3."
|
||||
assert isinstance(origin,(tuple,list)) and len(origin)==3,\
|
||||
"'origin' must be tuple of length 3."
|
||||
return self.to_vtk().slice(normal=normal,origin=origin)
|
||||
return self.to_vtk(deep=deep).slice(normal=normal,origin=origin)
|
||||
|
||||
class ChunkIterator:
|
||||
'''Iterates through all chunks. 'snapshot' must be an instance
|
||||
|
|
|
|||
Loading…
Reference in New Issue