support for unstructured grid (FEM)
This commit is contained in:
parent
dcbd7624dd
commit
d73e653f50
|
@ -3,6 +3,7 @@
|
|||
import os
|
||||
import argparse
|
||||
|
||||
import h5py
|
||||
import numpy as np
|
||||
import vtk
|
||||
from vtk.util import numpy_support
|
||||
|
@ -41,20 +42,29 @@ for filename in options.filenames:
|
|||
results = damask.DADF5(filename)
|
||||
|
||||
if results.structured: # for grid solvers use rectilinear grid
|
||||
rGrid = vtk.vtkRectilinearGrid()
|
||||
grid = vtk.vtkRectilineagrid()
|
||||
coordArray = [vtk.vtkDoubleArray(),
|
||||
vtk.vtkDoubleArray(),
|
||||
vtk.vtkDoubleArray(),
|
||||
]
|
||||
|
||||
rGrid.SetDimensions(*(results.grid+1))
|
||||
grid.SetDimensions(*(results.grid+1))
|
||||
for dim in [0,1,2]:
|
||||
for c in np.linspace(0,results.size[dim],1+results.grid[dim]):
|
||||
coordArray[dim].InsertNextValue(c)
|
||||
|
||||
rGrid.SetXCoordinates(coordArray[0])
|
||||
rGrid.SetYCoordinates(coordArray[1])
|
||||
rGrid.SetZCoordinates(coordArray[2])
|
||||
grid.SetXCoordinates(coordArray[0])
|
||||
grid.SetYCoordinates(coordArray[1])
|
||||
grid.SetZCoordinates(coordArray[2])
|
||||
else:
|
||||
nodes = vtk.vtkPoints()
|
||||
with h5py.File(filename) as f:
|
||||
nodes.SetData(numpy_support.numpy_to_vtk(f['/geometry/x_n'][()],deep=True))
|
||||
grid = vtk.vtkUnstructuredGrid()
|
||||
grid.SetPoints(nodes)
|
||||
grid.Allocate(f['/geometry/T_c'].shape[0])
|
||||
for i in f['/geometry/T_c']:
|
||||
grid.InsertNextCell(vtk.VTK_HEXAHEDRON,8,i-1)
|
||||
|
||||
|
||||
for i,inc in enumerate(results.iter_visible('increments')):
|
||||
|
@ -75,7 +85,7 @@ for filename in options.filenames:
|
|||
shape = [array.shape[0],np.product(array.shape[1:])]
|
||||
vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE))
|
||||
vtk_data[-1].SetName('1_'+x[0].split('/',1)[1])
|
||||
rGrid.GetCellData().AddArray(vtk_data[-1])
|
||||
grid.GetCellData().AddArray(vtk_data[-1])
|
||||
else:
|
||||
x = results.get_dataset_location(label)
|
||||
if len(x) == 0:
|
||||
|
@ -84,7 +94,7 @@ for filename in options.filenames:
|
|||
shape = [array.shape[0],np.product(array.shape[1:])]
|
||||
vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE))
|
||||
vtk_data[-1].SetName('1_'+x[0].split('/',1)[1])
|
||||
rGrid.GetCellData().AddArray(vtk_data[-1])
|
||||
grid.GetCellData().AddArray(vtk_data[-1])
|
||||
|
||||
results.set_visible('constituents', False)
|
||||
results.set_visible('materialpoints',True)
|
||||
|
@ -99,7 +109,7 @@ for filename in options.filenames:
|
|||
shape = [array.shape[0],np.product(array.shape[1:])]
|
||||
vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE))
|
||||
vtk_data[-1].SetName('1_'+x[0].split('/',1)[1])
|
||||
rGrid.GetCellData().AddArray(vtk_data[-1])
|
||||
grid.GetCellData().AddArray(vtk_data[-1])
|
||||
else:
|
||||
x = results.get_dataset_location(label)
|
||||
if len(x) == 0:
|
||||
|
@ -108,10 +118,10 @@ for filename in options.filenames:
|
|||
shape = [array.shape[0],np.product(array.shape[1:])]
|
||||
vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE))
|
||||
vtk_data[-1].SetName('1_'+x[0].split('/',1)[1])
|
||||
rGrid.GetCellData().AddArray(vtk_data[-1])
|
||||
grid.GetCellData().AddArray(vtk_data[-1])
|
||||
|
||||
if results.structured:
|
||||
writer = vtk.vtkXMLRectilinearGridWriter()
|
||||
writer = vtk.vtkXMLRectilineagridWriter() if results.structured else \
|
||||
vtk.vtkXMLUnstructuredGridWriter()
|
||||
|
||||
|
||||
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
||||
|
@ -122,7 +132,6 @@ for filename in options.filenames:
|
|||
writer.SetCompressorTypeToZLib()
|
||||
writer.SetDataModeToBinary()
|
||||
writer.SetFileName(os.path.join(dirname,file_out))
|
||||
if results.structured:
|
||||
writer.SetInputData(rGrid)
|
||||
writer.SetInputData(grid)
|
||||
|
||||
writer.Write()
|
||||
|
|
Loading…
Reference in New Issue