From 0805445ea89e587b946e5d54d5ae0fb332710655 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Fri, 18 Jun 2021 10:17:39 -0400 Subject: [PATCH 1/3] exchanged x/z dimension in XDMF writing --- python/damask/_result.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index d90a87f14..9801c13a8 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -1437,7 +1437,7 @@ class Result: topology = ET.SubElement(grid, 'Topology') topology.attrib = {'TopologyType': '3DCoRectMesh', - 'Dimensions': '{} {} {}'.format(*(self.cells+1))} + 'Dimensions': '{} {} {}'.format(*(self.cells[::-1]+1))} geometry = ET.SubElement(grid, 'Geometry') geometry.attrib = {'GeometryType':'Origin_DxDyDz'} @@ -1446,13 +1446,13 @@ class Result: origin.attrib = {'Format': 'XML', 'NumberType': 'Float', 'Dimensions': '3'} - origin.text = "{} {} {}".format(*self.origin) + origin.text = "{} {} {}".format(*self.origin[::-1]) delta = ET.SubElement(geometry, 'DataItem') delta.attrib = {'Format': 'XML', 'NumberType': 'Float', 'Dimensions': '3'} - delta.text="{} {} {}".format(*(self.size/self.cells)) + delta.text="{} {} {}".format(*(self.size/self.cells)[::-1]) attributes.append(ET.SubElement(grid, 'Attribute')) attributes[-1].attrib = {'Name': 'u / m', @@ -1461,7 +1461,7 @@ class Result: data_items.append(ET.SubElement(attributes[-1], 'DataItem')) data_items[-1].attrib = {'Format': 'HDF', 'Precision': '8', - 'Dimensions': '{} {} {} 3'.format(*(self.cells+1))} + 'Dimensions': '{} {} {} 3'.format(*(self.cells[::-1]+1))} data_items[-1].text = f'{os.path.split(self.fname)[1]}:/{inc}/geometry/u_n' for ty in ['phase','homogenization']: @@ -1483,7 +1483,7 @@ class Result: data_items[-1].attrib = {'Format': 'HDF', 'NumberType': number_type_map(dtype), 'Precision': f'{dtype.itemsize}', - 'Dimensions': '{} {} {} {}'.format(*self.cells,1 if shape == () else + 'Dimensions': '{} {} {} {}'.format(*self.cells[::-1],1 if shape == () else np.prod(shape))} data_items[-1].text = f'{os.path.split(self.fname)[1]}:{name}' @@ -1516,10 +1516,9 @@ class Result: Export to VTK cell/point data. One VTK file per visible increment is created. - For cell data, the VTK format is a image data (.vti) for - grid-based simulations and an unstructured grid (.vtu) for - mesh-baed simulations. For point data, the VTK format is poly - data (.vtp). + For point data, the VTK format is poly data (.vtp). + For cell data, either a rectilinear (.vtr) or unstructured (.vtu) dataset + is written for grid-based or mesh-based simulations, respectively. Parameters ---------- @@ -1539,7 +1538,7 @@ class Result: Fill value for non-existent entries of integer type. Defaults to 0. parallel : bool - Write out VTK files in parallel in a separate background process. + Write VTK files in parallel in a separate background process. Defaults to True. """ From 56b011aa547daa43644fb0e52baa52fb641a5deb Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 18 Jun 2021 21:11:01 +0200 Subject: [PATCH 2/3] better have tests --- python/damask/_result.py | 2 +- python/tests/test_Result.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index 9801c13a8..9bd16be0e 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -1517,7 +1517,7 @@ class Result: One VTK file per visible increment is created. For point data, the VTK format is poly data (.vtp). - For cell data, either a rectilinear (.vtr) or unstructured (.vtu) dataset + For cell data, either an image (.vti) or unstructured (.vtu) dataset is written for grid-based or mesh-based simulations, respectively. Parameters diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index d7f1bc3d1..b0648c67b 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -8,6 +8,7 @@ import hashlib from datetime import datetime import pytest +import vtk import numpy as np from damask import Result @@ -410,10 +411,27 @@ class TestResult: single_phase.add_calculation(f"np.ones(np.shape(#F#)[0:1]+{shape[1]},'{dtype}')",f'{shape[0]}_{dtype}') fname = os.path.splitext(os.path.basename(single_phase.fname))[0]+'.xdmf' os.chdir(tmp_path) + single_phase.save_XDMF() + single_phase.view('increments',0).save_VTK() + + reader_xdmf = vtk.vtkXdmfReader() + reader_xdmf.SetFileName(fname) + reader_xdmf.Update() + dim_xdmf = reader_xdmf.GetOutput().GetDimensions() + bounds_xdmf = reader_xdmf.GetOutput().GetBounds() + + reader_vti = vtk.vtkXMLImageDataReader() + reader_vti.SetFileName(os.path.splitext(fname)[0]+'_inc00.vti') + reader_vti.Update() + dim_vti = reader_vti.GetOutput().GetDimensions() + bounds_vti = reader_vti.GetOutput().GetBounds() + if update: shutil.copy(tmp_path/fname,ref_path/fname) - assert sorted(open(tmp_path/fname).read()) == sorted(open(ref_path/fname).read()) # XML is not ordered + + assert dim_vti == dim_xdmf and bounds_vti == bounds_xdmf and \ + sorted(open(tmp_path/fname).read()) == sorted(open(ref_path/fname).read()) # XML is not ordered def test_XDMF_invalid(self,default): with pytest.raises(TypeError): From 71634f6ce948abcc97fc7f764b6c5b082307fcfc Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 19 Jun 2021 08:12:49 +0200 Subject: [PATCH 3/3] split into two tests, one will fail on Ubuntu --- python/tests/test_Result.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index b0648c67b..dbc3caf44 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -405,7 +405,7 @@ class TestResult: os.chdir(tmp_path) single_phase.save_VTK(mode=mode) - def test_XDMF(self,tmp_path,single_phase,update,ref_path): + def test_XDMF_datatypes(self,tmp_path,single_phase,update,ref_path): for shape in [('scalar',()),('vector',(3,)),('tensor',(3,3)),('matrix',(12,))]: for dtype in ['f4','f8','i1','i2','i4','i8','u1','u2','u4','u8']: single_phase.add_calculation(f"np.ones(np.shape(#F#)[0:1]+{shape[1]},'{dtype}')",f'{shape[0]}_{dtype}') @@ -413,25 +413,37 @@ class TestResult: os.chdir(tmp_path) single_phase.save_XDMF() - single_phase.view('increments',0).save_VTK() + if update: + shutil.copy(tmp_path/fname,ref_path/fname) + + assert sorted(open(tmp_path/fname).read()) == sorted(open(ref_path/fname).read()) # XML is not ordered + + @pytest.mark.skipif(not hasattr(vtk,'vtkXdmfReader'),reason='https://discourse.vtk.org/t/2450') + def test_XDMF_shape(self,tmp_path,single_phase): + os.chdir(tmp_path) + + single_phase.save_XDMF() + fname = os.path.splitext(os.path.basename(single_phase.fname))[0]+'.xdmf' reader_xdmf = vtk.vtkXdmfReader() reader_xdmf.SetFileName(fname) reader_xdmf.Update() dim_xdmf = reader_xdmf.GetOutput().GetDimensions() bounds_xdmf = reader_xdmf.GetOutput().GetBounds() - reader_vti = vtk.vtkXMLImageDataReader() - reader_vti.SetFileName(os.path.splitext(fname)[0]+'_inc00.vti') - reader_vti.Update() - dim_vti = reader_vti.GetOutput().GetDimensions() - bounds_vti = reader_vti.GetOutput().GetBounds() + single_phase.view('increments',0).save_VTK() + fname = os.path.splitext(os.path.basename(single_phase.fname))[0]+'_inc00.vti' + for i in range(10): # waiting for parallel IO + reader_vti = vtk.vtkXMLImageDataReader() + reader_vti.SetFileName(fname) + reader_vti.Update() + dim_vti = reader_vti.GetOutput().GetDimensions() + bounds_vti = reader_vti.GetOutput().GetBounds() + if dim_vti == dim_xdmf and bounds_vti == bounds_xdmf: + return + time.sleep(.5) - if update: - shutil.copy(tmp_path/fname,ref_path/fname) - - assert dim_vti == dim_xdmf and bounds_vti == bounds_xdmf and \ - sorted(open(tmp_path/fname).read()) == sorted(open(ref_path/fname).read()) # XML is not ordered + assert False def test_XDMF_invalid(self,default): with pytest.raises(TypeError):