diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 6366f06ab..f7ac6c437 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -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() diff --git a/python/damask/_result.py b/python/damask/_result.py index 5e8a9a9d0..3f4ca735c 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -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'][()], - f['/geometry/T_c'][()]-1, - f['/geometry/T_c'].attrs['VTK_TYPE'].decode()) + 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 diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index c1fe52f38..10f3b482b 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -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): diff --git a/python/tests/reference/Result/12grains6x7x8.geom b/python/tests/reference/Result/12grains6x7x8.geom deleted file mode 100644 index 4e6836bb8..000000000 --- a/python/tests/reference/Result/12grains6x7x8.geom +++ /dev/null @@ -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 diff --git a/python/tests/reference/Result/12grains6x7x8.vtr b/python/tests/reference/Result/12grains6x7x8.vtr new file mode 100644 index 000000000..02ba9d4e6 --- /dev/null +++ b/python/tests/reference/Result/12grains6x7x8.vtr @@ -0,0 +1,30 @@ + + + + + + AQAAAACAAAARAAAAGQAAAA==eF7LyM/NT0/Ny6xKLMnMz1MwZAAAPsIGPQ== + + + + + + + + AQAAAACAAACACgAA2wAAAA==eF6tlssOgkAQBNcHiPj//2uM25eOZc8oc6kYagzdISzbeM/ZeJ/cgDTk7x/c16zm6fduXAOr/mOS8rqXfDH5mqP6pKHcVY9yJN/ziv5/R/k+8lI/GnnLV2uMm1G5tefXnZ6j6v3bD/nXyQWokU8e5a96tJc8z9H1aY88MfWZek3Xf6XnuBhTr+6fgPKpH9oj3/eS5+/bap/yPafo54buJ/mek3zqJeXu+tRP8vycp15E8tNe6rPaf7fPrk/9eO6q598/1GO1/67v53V6nul8T3n9Oy758p47Sgdl + + + + + AQAAAACAAAA4AAAAHAAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0C3sAisIGjw== + + + AQAAAACAAABAAAAAHwAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0Cyj9xh4AwVEHug== + + + AQAAAACAAABIAAAAIgAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0Cyj9Bkp/sAcAAU8I6Q== + + + + + diff --git a/python/tests/reference/Result/6grains6x7x8_single_phase.geom b/python/tests/reference/Result/6grains6x7x8_single_phase.geom deleted file mode 100644 index 14cae0973..000000000 --- a/python/tests/reference/Result/6grains6x7x8_single_phase.geom +++ /dev/null @@ -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 diff --git a/python/tests/reference/Result/6grains6x7x8_single_phase.vtr b/python/tests/reference/Result/6grains6x7x8_single_phase.vtr new file mode 100644 index 000000000..9a7b7dd7d --- /dev/null +++ b/python/tests/reference/Result/6grains6x7x8_single_phase.vtr @@ -0,0 +1,30 @@ + + + + + + AQAAAACAAAARAAAAGQAAAA==eF7LyM/NT0/Ny6xKLMnMz1MwZAAAPsIGPQ== + + + + + + + + AQAAAACAAACACgAAwAAAAA==eF69lcsOwjAQA6GU//9lDsUSGjHyBgq+WGpm09jqY7sc2uA3uR43Gb+/YV/FfXd405S/P93ykmt8vPHRWX3+SpbDZHnj3O8snpqeN+L9TFd4lDmu05ljyn3bj/F5P2yfyNZbnilnc1MuOVZ5mzMu3vpsvbb1T5057Ltk/ZBvfVo/qzznGsdzTvvknO3D8zS+9fjvPlsu4/ifn87bf7DNNf7sPlf59rxYbuPircdp/6s81Z5navoeRav9PACxsANv + + + + + AQAAAACAAAA4AAAAHAAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0C3sAisIGjw== + + + AQAAAACAAABAAAAAHwAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0Cyj9xh4AwVEHug== + + + AQAAAACAAABIAAAAIgAAAA==eF5jYEAGB+wh9AUofQNKP4DST6D0Cyj9Bkp/sAcAAU8I6Q== + + + + + diff --git a/python/tests/reference/VTK/polyData.vtp b/python/tests/reference/VTK/polyData.vtp index 6ed05f67f..dc4b5f149 100644 --- a/python/tests/reference/VTK/polyData.vtp +++ b/python/tests/reference/VTK/polyData.vtp @@ -1,7 +1,7 @@ - + AQAAAACAAAB4AAAAVgAAAA==eF5jYICBhv2WfY9tLfuS7Ypk3PeDaCDf7okF3/7Vq1bZrV6lZQ+k94HEgHL2QHovUM7+iUUfiG0LlQdhkH77Ipnj9iB5qFp7kBjQDiBmcADRANsaLXM= @@ -31,11 +31,11 @@ - - AAAAAACAAAAAAAAA + + AQAAAACAAABQAAAAIgAAAA==eF4txbcBACAIADAsiP7/sAPJkog2PL28nT4uXz9/BXgALg== - - AAAAAACAAAAAAAAA + + AQAAAACAAABQAAAAIgAAAA==eF4txbcBACAIADA76v8HM5As6a0MTy9vH4evn78TBzAAOA== diff --git a/python/tests/test_Geom.py b/python/tests/test_Geom.py index 0f4c1a952..368d8ec8f 100644 --- a/python/tests/test_Geom.py +++ b/python/tests/test_Geom.py @@ -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') diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index 68b72badf..5ef17cd26 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -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() diff --git a/python/tests/test_VTK.py b/python/tests/test_VTK.py index 81c9eb772..63adb6454 100644 --- a/python/tests/test_VTK.py +++ b/python/tests/test_VTK.py @@ -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')