Merge branch 'Poly_data_with_verts' into 'development'
Poly data with verts See merge request damask/DAMASK!262
This commit is contained in:
commit
ea49044992
|
@ -473,7 +473,7 @@ class Geom:
|
|||
Compress with zlib algorithm. Defaults to True.
|
||||
|
||||
"""
|
||||
v = VTK.from_rectilinearGrid(self.grid,self.size,self.origin)
|
||||
v = VTK.from_rectilinear_grid(self.grid,self.size,self.origin)
|
||||
v.add(self.material.flatten(order='F'),'material')
|
||||
v.add_comments(self.comments)
|
||||
|
||||
|
@ -508,7 +508,7 @@ class Geom:
|
|||
|
||||
def show(self):
|
||||
"""Show on screen."""
|
||||
v = VTK.from_rectilinearGrid(self.grid,self.size,self.origin)
|
||||
v = VTK.from_rectilinear_grid(self.grid,self.size,self.origin)
|
||||
v.show()
|
||||
|
||||
|
||||
|
|
|
@ -1212,14 +1212,14 @@ class Result:
|
|||
if mode.lower()=='cell':
|
||||
|
||||
if self.structured:
|
||||
v = VTK.from_rectilinearGrid(self.grid,self.size,self.origin)
|
||||
v = VTK.from_rectilinear_grid(self.grid,self.size,self.origin)
|
||||
else:
|
||||
with h5py.File(self.fname,'r') as f:
|
||||
v = VTK.from_unstructuredGrid(f['/geometry/x_n'][()],
|
||||
v = VTK.from_unstructured_grid(f['/geometry/x_n'][()],
|
||||
f['/geometry/T_c'][()]-1,
|
||||
f['/geometry/T_c'].attrs['VTK_TYPE'].decode())
|
||||
elif mode.lower()=='point':
|
||||
v = VTK.from_polyData(self.cell_coordinates())
|
||||
v = VTK.from_poly_data(self.cell_coordinates)
|
||||
|
||||
N_digits = int(np.floor(np.log10(max(1,int(self.increments[-1][3:])))))+1
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class VTK:
|
|||
|
||||
|
||||
@staticmethod
|
||||
def from_rectilinearGrid(grid,size,origin=np.zeros(3)):
|
||||
def from_rectilinear_grid(grid,size,origin=np.zeros(3)):
|
||||
"""
|
||||
Create VTK of type vtk.vtkRectilinearGrid.
|
||||
|
||||
|
@ -64,7 +64,7 @@ class VTK:
|
|||
|
||||
|
||||
@staticmethod
|
||||
def from_unstructuredGrid(nodes,connectivity,cell_type):
|
||||
def from_unstructured_grid(nodes,connectivity,cell_type):
|
||||
"""
|
||||
Create VTK of type vtk.vtkUnstructuredGrid.
|
||||
|
||||
|
@ -96,7 +96,7 @@ class VTK:
|
|||
|
||||
|
||||
@staticmethod
|
||||
def from_polyData(points):
|
||||
def from_poly_data(points):
|
||||
"""
|
||||
Create VTK of type vtk.polyData.
|
||||
|
||||
|
@ -108,11 +108,18 @@ class VTK:
|
|||
Spatial position of the points.
|
||||
|
||||
"""
|
||||
N = points.shape[0]
|
||||
vtk_points = vtk.vtkPoints()
|
||||
vtk_points.SetData(np_to_vtk(points))
|
||||
|
||||
vtk_cells = vtk.vtkCellArray()
|
||||
vtk_cells.SetNumberOfCells(N)
|
||||
vtk_cells.SetCells(N,np_to_vtkIdTypeArray(np.stack((np.ones (N,dtype=np.int64),
|
||||
np.arange(N,dtype=np.int64)),axis=1).ravel(),deep=True))
|
||||
|
||||
vtk_data = vtk.vtkPolyData()
|
||||
vtk_data.SetPoints(vtk_points)
|
||||
vtk_data.SetVerts(vtk_cells)
|
||||
|
||||
return VTK(vtk_data)
|
||||
|
||||
|
@ -164,6 +171,7 @@ class VTK:
|
|||
|
||||
return VTK(vtk_data)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _write(writer):
|
||||
"""Wrapper for parallel writing."""
|
||||
|
@ -192,7 +200,7 @@ class VTK:
|
|||
default_ext = writer.GetDefaultFileExtension()
|
||||
ext = Path(fname).suffix
|
||||
if ext and ext != '.'+default_ext:
|
||||
raise ValueError(f'Given extension {ext} does not match default .{default_ext}')
|
||||
raise ValueError(f'Given extension "{ext}" does not match default ".{default_ext}"')
|
||||
writer.SetFileName(str(Path(fname).with_suffix('.'+default_ext)))
|
||||
if compress:
|
||||
writer.SetCompressorTypeToZLib()
|
||||
|
@ -238,10 +246,10 @@ class VTK:
|
|||
else data).reshape(N_data,-1),deep=True) # avoid large files
|
||||
d.SetName(label)
|
||||
|
||||
if N_data == N_cells:
|
||||
self.vtk_data.GetCellData().AddArray(d)
|
||||
elif N_data == N_points:
|
||||
if N_data == N_points:
|
||||
self.vtk_data.GetPointData().AddArray(d)
|
||||
elif N_data == N_cells:
|
||||
self.vtk_data.GetCellData().AddArray(d)
|
||||
else:
|
||||
raise ValueError(f'Cell / point count ({N_cells} / {N_points}) differs from data ({N_data}).')
|
||||
elif isinstance(data,pd.DataFrame):
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
4 header
|
||||
grid a 6 b 7 c 8
|
||||
size x 0.75 y 0.875 z 1.0
|
||||
origin x 0.0 y 0.0 z 0.0
|
||||
homogenization 1
|
||||
9 3 3 10 9 9
|
||||
9 1 1 1 9 9
|
||||
9 11 1 1 7 9
|
||||
7 11 11 7 7 7
|
||||
7 11 11 7 7 7
|
||||
12 3 3 10 7 12
|
||||
12 3 3 10 10 12
|
||||
12 3 3 1 9 9
|
||||
9 1 1 1 9 9
|
||||
9 1 1 1 7 7
|
||||
7 1 1 7 7 7
|
||||
12 12 3 7 7 7
|
||||
12 3 3 3 12 12
|
||||
12 3 3 3 12 12
|
||||
12 3 3 1 1 12
|
||||
9 1 1 1 1 9
|
||||
6 1 1 1 8 8
|
||||
7 6 8 8 8 8
|
||||
12 12 8 8 8 12
|
||||
12 3 3 3 12 12
|
||||
12 3 3 3 12 12
|
||||
5 6 6 6 1 12
|
||||
6 6 6 6 8 8
|
||||
6 6 6 8 8 8
|
||||
8 6 8 8 8 8
|
||||
12 5 8 8 8 8
|
||||
12 5 5 8 8 12
|
||||
5 5 5 3 12 12
|
||||
5 5 6 6 6 5
|
||||
6 6 6 6 6 6
|
||||
6 6 6 6 8 8
|
||||
4 4 6 8 8 8
|
||||
4 4 2 2 2 8
|
||||
5 5 5 2 2 2
|
||||
5 5 5 5 2 5
|
||||
5 5 5 10 10 5
|
||||
6 6 6 6 10 4
|
||||
4 4 11 11 2 4
|
||||
4 4 11 2 2 4
|
||||
4 4 2 2 2 2
|
||||
5 5 5 2 2 2
|
||||
5 5 5 10 10 5
|
||||
5 5 10 10 10 9
|
||||
4 11 11 11 10 9
|
||||
4 4 11 11 11 4
|
||||
4 4 11 11 2 4
|
||||
4 4 2 2 2 2
|
||||
5 5 2 2 2 2
|
||||
5 5 10 10 10 10
|
||||
9 10 10 10 10 9
|
||||
9 11 11 10 9 9
|
||||
4 11 11 11 9 9
|
||||
4 11 11 11 7 7
|
||||
4 4 11 2 7 7
|
||||
12 10 10 10 10 7
|
||||
9 10 10 10 10 9
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0"?>
|
||||
<VTKFile type="RectilinearGrid" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
|
||||
<RectilinearGrid WholeExtent="0 6 0 7 0 8">
|
||||
<FieldData>
|
||||
<Array type="String" Name="comments" NumberOfTuples="1" format="binary">
|
||||
AQAAAACAAAARAAAAGQAAAA==eF7LyM/NT0/Ny6xKLMnMz1MwZAAAPsIGPQ==
|
||||
</Array>
|
||||
</FieldData>
|
||||
<Piece Extent="0 6 0 7 0 8">
|
||||
<PointData>
|
||||
</PointData>
|
||||
<CellData>
|
||||
<DataArray type="Int64" Name="material" format="binary" RangeMin="0" RangeMax="11">
|
||||
AQAAAACAAACACgAA2wAAAA==eF6tlssOgkAQBNcHiPj//2uM25eOZc8oc6kYagzdISzbeM/ZeJ/cgDTk7x/c16zm6fduXAOr/mOS8rqXfDH5mqP6pKHcVY9yJN/ziv5/R/k+8lI/GnnLV2uMm1G5tefXnZ6j6v3bD/nXyQWokU8e5a96tJc8z9H1aY88MfWZek3Xf6XnuBhTr+6fgPKpH9oj3/eS5+/bap/yPafo54buJ/mek3zqJeXu+tRP8vycp15E8tNe6rPaf7fPrk/9eO6q598/1GO1/67v53V6nul8T3n9Oy758p47Sgdl
|
||||
</DataArray>
|
||||
</CellData>
|
||||
<Coordinates>
|
||||
<DataArray type="Float64" Name="x" format="binary" RangeMin="0" RangeMax="0.75">
|
||||
AQAAAACAAAA4AAAAHAAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0C3sAisIGjw==
|
||||
</DataArray>
|
||||
<DataArray type="Float64" Name="y" format="binary" RangeMin="0" RangeMax="0.875">
|
||||
AQAAAACAAABAAAAAHwAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0Cyj9xh4AwVEHug==
|
||||
</DataArray>
|
||||
<DataArray type="Float64" Name="z" format="binary" RangeMin="0" RangeMax="1">
|
||||
AQAAAACAAABIAAAAIgAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0Cyj9Bkp/sAcAAU8I6Q==
|
||||
</DataArray>
|
||||
</Coordinates>
|
||||
</Piece>
|
||||
</RectilinearGrid>
|
||||
</VTKFile>
|
|
@ -1,61 +0,0 @@
|
|||
4 header
|
||||
grid a 6 b 7 c 8
|
||||
size x 0.75 y 0.875 z 1.0
|
||||
origin x 0.0 y 0.0 z 0.0
|
||||
homogenization 1
|
||||
3 3 3 4 3 3
|
||||
3 1 1 1 3 3
|
||||
3 5 1 1 1 3
|
||||
1 5 5 1 1 1
|
||||
1 5 5 1 1 1
|
||||
6 3 3 4 1 6
|
||||
6 3 3 4 4 6
|
||||
6 3 3 1 3 3
|
||||
3 1 1 1 3 3
|
||||
3 1 1 1 1 1
|
||||
1 1 1 1 1 1
|
||||
6 6 3 1 1 1
|
||||
6 3 3 3 6 6
|
||||
6 3 3 3 6 6
|
||||
6 3 3 1 1 6
|
||||
3 1 1 1 1 3
|
||||
6 1 1 1 2 2
|
||||
1 6 2 2 2 2
|
||||
6 6 2 2 2 6
|
||||
6 3 3 3 6 6
|
||||
6 3 3 3 6 6
|
||||
5 6 6 6 1 6
|
||||
6 6 6 6 2 2
|
||||
6 6 6 2 2 2
|
||||
2 6 2 2 2 2
|
||||
6 5 2 2 2 2
|
||||
6 5 5 2 2 6
|
||||
5 5 5 3 6 6
|
||||
5 5 6 6 6 5
|
||||
6 6 6 6 6 6
|
||||
6 6 6 6 2 2
|
||||
4 4 6 2 2 2
|
||||
4 4 2 2 2 2
|
||||
5 5 5 2 2 2
|
||||
5 5 5 5 2 5
|
||||
5 5 5 4 4 5
|
||||
6 6 6 6 4 4
|
||||
4 4 5 5 2 4
|
||||
4 4 5 2 2 4
|
||||
4 4 2 2 2 2
|
||||
5 5 5 2 2 2
|
||||
5 5 5 4 4 5
|
||||
5 5 4 4 4 3
|
||||
4 5 5 5 4 3
|
||||
4 4 5 5 5 4
|
||||
4 4 5 5 2 4
|
||||
4 4 2 2 2 2
|
||||
5 5 2 2 2 2
|
||||
5 5 4 4 4 4
|
||||
3 4 4 4 4 3
|
||||
3 5 5 4 3 3
|
||||
4 5 5 5 3 3
|
||||
4 5 5 5 1 1
|
||||
4 4 5 2 1 1
|
||||
6 4 4 4 4 1
|
||||
3 4 4 4 4 3
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0"?>
|
||||
<VTKFile type="RectilinearGrid" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
|
||||
<RectilinearGrid WholeExtent="0 6 0 7 0 8">
|
||||
<FieldData>
|
||||
<Array type="String" Name="comments" NumberOfTuples="1" format="binary">
|
||||
AQAAAACAAAARAAAAGQAAAA==eF7LyM/NT0/Ny6xKLMnMz1MwZAAAPsIGPQ==
|
||||
</Array>
|
||||
</FieldData>
|
||||
<Piece Extent="0 6 0 7 0 8">
|
||||
<PointData>
|
||||
</PointData>
|
||||
<CellData>
|
||||
<DataArray type="Int64" Name="material" format="binary" RangeMin="0" RangeMax="5">
|
||||
AQAAAACAAACACgAAwAAAAA==eF69lcsOwjAQA6GU//9lDsUSGjHyBgq+WGpm09jqY7sc2uA3uR43Gb+/YV/FfXd405S/P93ykmt8vPHRWX3+SpbDZHnj3O8snpqeN+L9TFd4lDmu05ljyn3bj/F5P2yfyNZbnilnc1MuOVZ5mzMu3vpsvbb1T5057Ltk/ZBvfVo/qzznGsdzTvvknO3D8zS+9fjvPlsu4/ifn87bf7DNNf7sPlf59rxYbuPircdp/6s81Z5navoeRav9PACxsANv
|
||||
</DataArray>
|
||||
</CellData>
|
||||
<Coordinates>
|
||||
<DataArray type="Float64" Name="x" format="binary" RangeMin="0" RangeMax="0.75">
|
||||
AQAAAACAAAA4AAAAHAAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0C3sAisIGjw==
|
||||
</DataArray>
|
||||
<DataArray type="Float64" Name="y" format="binary" RangeMin="0" RangeMax="0.875">
|
||||
AQAAAACAAABAAAAAHwAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0Cyj9xh4AwVEHug==
|
||||
</DataArray>
|
||||
<DataArray type="Float64" Name="z" format="binary" RangeMin="0" RangeMax="1">
|
||||
AQAAAACAAABIAAAAIgAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0Cyj9Bkp/sAcAAU8I6Q==
|
||||
</DataArray>
|
||||
</Coordinates>
|
||||
</Piece>
|
||||
</RectilinearGrid>
|
||||
</VTKFile>
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<VTKFile type="PolyData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
|
||||
<PolyData>
|
||||
<Piece NumberOfPoints="10" NumberOfVerts="0" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="0">
|
||||
<Piece NumberOfPoints="10" NumberOfVerts="10" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="0">
|
||||
<PointData>
|
||||
<DataArray type="Float32" Name="coordinates" NumberOfComponents="3" format="binary" RangeMin="0.7453560147132696" RangeMax="2.449489742783178">
|
||||
AQAAAACAAAB4AAAAVgAAAA==eF5jYICBhv2WfY9tLfuS7Ypk3PeDaCDf7okF3/7Vq1bZrV6lZQ+k94HEgHL2QHovUM7+iUUfiG0LlQdhkH77Ipnj9iB5qFp7kBjQDiBmcADRANsaLXM=
|
||||
|
@ -31,11 +31,11 @@
|
|||
</DataArray>
|
||||
</Points>
|
||||
<Verts>
|
||||
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="0" RangeMax="9">
|
||||
AQAAAACAAABQAAAAIgAAAA==eF4txbcBACAIADAsiP7/sAPJkog2PL28nT4uXz9/BXgALg==
|
||||
</DataArray>
|
||||
<DataArray type="Int64" Name="offsets" format="binary" RangeMin="1e+299" RangeMax="-1e+299">
|
||||
AAAAAACAAAAAAAAA
|
||||
<DataArray type="Int64" Name="offsets" format="binary" RangeMin="1" RangeMax="10">
|
||||
AQAAAACAAABQAAAAIgAAAA==eF4txbcBACAIADA76v8HM5As6a0MTy9vH4evn78TBzAAOA==
|
||||
</DataArray>
|
||||
</Verts>
|
||||
<Lines>
|
||||
|
|
|
@ -49,7 +49,7 @@ class TestGeom:
|
|||
assert geom_equal(new,default)
|
||||
|
||||
def test_invalid_vtr(self,tmp_path):
|
||||
v = VTK.from_rectilinearGrid(np.random.randint(5,10,3)*2,np.random.random(3) + 1.0)
|
||||
v = VTK.from_rectilinear_grid(np.random.randint(5,10,3)*2,np.random.random(3) + 1.0)
|
||||
v.save(tmp_path/'no_materialpoint.vtr')
|
||||
with pytest.raises(ValueError):
|
||||
Geom.load(tmp_path/'no_materialpoint.vtr')
|
||||
|
|
|
@ -341,6 +341,11 @@ class TestResult:
|
|||
os.chdir(tmp_path)
|
||||
default.save_vtk(output)
|
||||
|
||||
@pytest.mark.parametrize('mode',['point','cell'])
|
||||
def test_vtk_mode(self,tmp_path,single_phase,mode):
|
||||
os.chdir(tmp_path)
|
||||
single_phase.save_vtk(mode=mode)
|
||||
|
||||
def test_XDMF(self,tmp_path,single_phase):
|
||||
os.chdir(tmp_path)
|
||||
single_phase.save_XDMF()
|
||||
|
|
|
@ -18,7 +18,7 @@ def default():
|
|||
"""Simple VTK."""
|
||||
grid = np.array([5,6,7],int)
|
||||
size = np.array([.6,1.,.5])
|
||||
return VTK.from_rectilinearGrid(grid,size)
|
||||
return VTK.from_rectilinear_grid(grid,size)
|
||||
|
||||
class TestVTK:
|
||||
|
||||
|
@ -30,7 +30,7 @@ class TestVTK:
|
|||
grid = np.random.randint(5,10,3)*2
|
||||
size = np.random.random(3) + 1.0
|
||||
origin = np.random.random(3)
|
||||
v = VTK.from_rectilinearGrid(grid,size,origin)
|
||||
v = VTK.from_rectilinear_grid(grid,size,origin)
|
||||
string = v.__repr__()
|
||||
v.save(tmp_path/'rectilinearGrid',False)
|
||||
vtr = VTK.load(tmp_path/'rectilinearGrid.vtr')
|
||||
|
@ -41,7 +41,7 @@ class TestVTK:
|
|||
|
||||
def test_polyData(self,tmp_path):
|
||||
points = np.random.rand(100,3)
|
||||
v = VTK.from_polyData(points)
|
||||
v = VTK.from_poly_data(points)
|
||||
string = v.__repr__()
|
||||
v.save(tmp_path/'polyData',False)
|
||||
vtp = VTK.load(tmp_path/'polyData.vtp')
|
||||
|
@ -60,7 +60,7 @@ class TestVTK:
|
|||
def test_unstructuredGrid(self,tmp_path,cell_type,n):
|
||||
nodes = np.random.rand(n,3)
|
||||
connectivity = np.random.choice(np.arange(n),n,False).reshape(-1,n)
|
||||
v = VTK.from_unstructuredGrid(nodes,connectivity,cell_type)
|
||||
v = VTK.from_unstructured_grid(nodes,connectivity,cell_type)
|
||||
string = v.__repr__()
|
||||
v.save(tmp_path/'unstructuredGrid',False)
|
||||
vtu = VTK.load(tmp_path/'unstructuredGrid.vtu')
|
||||
|
@ -72,7 +72,7 @@ class TestVTK:
|
|||
|
||||
def test_parallel_out(self,tmp_path):
|
||||
points = np.random.rand(102,3)
|
||||
v = VTK.from_polyData(points)
|
||||
v = VTK.from_poly_data(points)
|
||||
fname_s = tmp_path/'single.vtp'
|
||||
fname_p = tmp_path/'parallel.vtp'
|
||||
v.save(fname_s,False)
|
||||
|
@ -121,7 +121,7 @@ class TestVTK:
|
|||
|
||||
def test_compare_reference_polyData(self,update,reference_dir,tmp_path):
|
||||
points=np.dstack((np.linspace(0.,1.,10),np.linspace(0.,2.,10),np.linspace(-1.,1.,10))).squeeze()
|
||||
polyData = VTK.from_polyData(points)
|
||||
polyData = VTK.from_poly_data(points)
|
||||
polyData.add(points,'coordinates')
|
||||
if update:
|
||||
polyData.save(reference_dir/'polyData')
|
||||
|
@ -133,7 +133,7 @@ class TestVTK:
|
|||
def test_compare_reference_rectilinearGrid(self,update,reference_dir,tmp_path):
|
||||
grid = np.array([5,6,7],int)
|
||||
size = np.array([.6,1.,.5])
|
||||
rectilinearGrid = VTK.from_rectilinearGrid(grid,size)
|
||||
rectilinearGrid = VTK.from_rectilinear_grid(grid,size)
|
||||
c = grid_filters.cell_coord0(grid,size).reshape(-1,3,order='F')
|
||||
n = grid_filters.node_coord0(grid,size).reshape(-1,3,order='F')
|
||||
rectilinearGrid.add(c,'cell')
|
||||
|
|
Loading…
Reference in New Issue