From 6ef7410e5a899002ebaf06c6beb2dc8d284c0292 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 31 Mar 2020 11:04:06 +0200 Subject: [PATCH] testing VTK wrappers --- python/damask/_vtk.py | 2 +- python/tests/test_VTK.py | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 python/tests/test_VTK.py diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index c11e07b4d..4505a5ebc 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -72,7 +72,7 @@ class VTK: connectivity : numpy.ndarray of np.dtype = int Cell connectivity (0-based), first dimension determines #Cells, second dimension determines #Nodes/Cell. cell_type : str - Name of the vtk.vtkCell subclass. Tested for TRIANGLE, QUAD, and HEXAHEDRON. + Name of the vtk.vtkCell subclass. Tested for TRIANGLE, QUAD, TETRA, and HEXAHEDRON. """ vtk_nodes = vtk.vtkPoints() diff --git a/python/tests/test_VTK.py b/python/tests/test_VTK.py new file mode 100644 index 000000000..ef4090da5 --- /dev/null +++ b/python/tests/test_VTK.py @@ -0,0 +1,48 @@ +import os +import sys + +import pytest +import numpy as np + +from damask import VTK + +@pytest.fixture +def reference_dir(reference_dir_base): + """Directory containing reference results.""" + return os.path.join(reference_dir_base,'Result') + +class TestVTK: + + def test_rectilinearGrid(self,tmp_path): + 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) + s = v.__repr__() + v.write(os.path.join(tmp_path,'rectilinearGrid')) + v = VTK.from_file(os.path.join(tmp_path,'rectilinearGrid.vtr')) + assert(s == v.__repr__()) + + def test_polyData(self,tmp_path): + points = np.random.rand(3,100) + v = VTK.from_polyData(points) + s = v.__repr__() + v.write(os.path.join(tmp_path,'polyData')) + v = VTK.from_file(os.path.join(tmp_path,'polyData.vtp')) + assert(s == v.__repr__()) + + @pytest.mark.parametrize('cell_type,n',[ + ('VTK_hexahedron',8), + ('TETRA',4), + ('quad',4), + ('VTK_TRIANGLE',3) + ] + ) + 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) + s = v.__repr__() + v.write(os.path.join(tmp_path,'unstructuredGrid')) + v = VTK.from_file(os.path.join(tmp_path,'unstructuredGrid.vtu')) + assert(s == v.__repr__())