2019-04-13 14:41:32 +05:30
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2019-09-14 04:31:30 +05:30
|
|
|
import os
|
2019-04-13 14:41:32 +05:30
|
|
|
import argparse
|
2019-09-14 04:31:30 +05:30
|
|
|
|
2019-10-14 17:43:03 +05:30
|
|
|
import h5py
|
2019-09-14 04:31:30 +05:30
|
|
|
import numpy as np
|
|
|
|
import vtk
|
2019-04-17 23:27:16 +05:30
|
|
|
from vtk.util import numpy_support
|
2019-04-13 14:41:32 +05:30
|
|
|
|
2019-09-14 04:31:30 +05:30
|
|
|
import damask
|
|
|
|
|
2019-04-13 14:41:32 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
#ToDo: We need to decide on a way of handling arguments of variable lentght
|
|
|
|
#https://stackoverflow.com/questions/15459997/passing-integer-lists-to-python
|
|
|
|
|
|
|
|
#parser.add_argument('--version', action='version', version='%(prog)s {}'.format(scriptID))
|
|
|
|
parser.add_argument('filenames', nargs='+',
|
|
|
|
help='DADF5 files')
|
2019-05-07 17:00:05 +05:30
|
|
|
parser.add_argument('-d','--dir', dest='dir',default='postProc',metavar='string',
|
2019-09-20 04:40:07 +05:30
|
|
|
help='name of subdirectory relative to the location of the DADF5 file to hold output')
|
2019-05-16 03:57:06 +05:30
|
|
|
parser.add_argument('--mat', nargs='+',
|
2019-09-16 03:32:16 +05:30
|
|
|
help='labels for materialpoint',dest='mat')
|
2019-05-16 03:57:06 +05:30
|
|
|
parser.add_argument('--con', nargs='+',
|
2019-09-16 03:32:16 +05:30
|
|
|
help='labels for constituent',dest='con')
|
2019-04-13 14:41:32 +05:30
|
|
|
|
|
|
|
options = parser.parse_args()
|
|
|
|
|
2019-05-16 03:57:06 +05:30
|
|
|
if options.mat is None: options.mat=[]
|
|
|
|
if options.con is None: options.con=[]
|
2019-04-13 14:41:32 +05:30
|
|
|
|
|
|
|
# --- loop over input files ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
for filename in options.filenames:
|
2019-04-18 15:28:17 +05:30
|
|
|
results = damask.DADF5(filename)
|
2019-04-13 14:41:32 +05:30
|
|
|
|
2019-10-12 16:04:37 +05:30
|
|
|
if results.structured: # for grid solvers use rectilinear grid
|
2019-10-19 01:33:31 +05:30
|
|
|
grid = vtk.vtkRectilinearGrid()
|
2019-04-13 14:41:32 +05:30
|
|
|
coordArray = [vtk.vtkDoubleArray(),
|
|
|
|
vtk.vtkDoubleArray(),
|
|
|
|
vtk.vtkDoubleArray(),
|
|
|
|
]
|
|
|
|
|
2019-10-14 17:43:03 +05:30
|
|
|
grid.SetDimensions(*(results.grid+1))
|
2019-04-13 14:41:32 +05:30
|
|
|
for dim in [0,1,2]:
|
2019-04-18 15:28:17 +05:30
|
|
|
for c in np.linspace(0,results.size[dim],1+results.grid[dim]):
|
2019-04-13 14:41:32 +05:30
|
|
|
coordArray[dim].InsertNextValue(c)
|
|
|
|
|
2019-10-14 17:43:03 +05:30
|
|
|
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)
|
2019-04-13 14:41:32 +05:30
|
|
|
|
|
|
|
|
2019-09-16 05:38:03 +05:30
|
|
|
for i,inc in enumerate(results.iter_visible('increments')):
|
2019-04-18 15:28:17 +05:30
|
|
|
print('Output step {}/{}'.format(i+1,len(results.increments)))
|
|
|
|
vtk_data = []
|
2019-05-16 15:14:03 +05:30
|
|
|
|
2019-09-16 04:30:19 +05:30
|
|
|
results.set_visible('materialpoints',False)
|
|
|
|
results.set_visible('constituents', True)
|
2019-05-16 03:57:06 +05:30
|
|
|
for label in options.con:
|
2019-09-16 05:38:03 +05:30
|
|
|
for p in results.iter_visible('con_physics'):
|
|
|
|
if p != 'generic':
|
2019-09-16 04:30:19 +05:30
|
|
|
for c in results.iter_visible('constituents'):
|
2019-04-18 15:28:17 +05:30
|
|
|
x = results.get_dataset_location(label)
|
|
|
|
if len(x) == 0:
|
|
|
|
continue
|
|
|
|
array = results.read_dataset(x,0)
|
|
|
|
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])
|
2019-10-14 17:43:03 +05:30
|
|
|
grid.GetCellData().AddArray(vtk_data[-1])
|
2019-04-18 15:28:17 +05:30
|
|
|
else:
|
2019-07-16 05:37:04 +05:30
|
|
|
x = results.get_dataset_location(label)
|
|
|
|
if len(x) == 0:
|
|
|
|
continue
|
|
|
|
array = results.read_dataset(x,0)
|
|
|
|
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))
|
2019-09-16 04:30:19 +05:30
|
|
|
vtk_data[-1].SetName('1_'+x[0].split('/',1)[1])
|
2019-10-14 17:43:03 +05:30
|
|
|
grid.GetCellData().AddArray(vtk_data[-1])
|
2019-07-16 05:37:04 +05:30
|
|
|
|
2019-09-16 04:30:19 +05:30
|
|
|
results.set_visible('constituents', False)
|
|
|
|
results.set_visible('materialpoints',True)
|
2019-09-28 09:08:02 +05:30
|
|
|
for label in options.mat:
|
2019-09-16 05:38:03 +05:30
|
|
|
for p in results.iter_visible('mat_physics'):
|
|
|
|
if p != 'generic':
|
2019-09-16 04:30:19 +05:30
|
|
|
for m in results.iter_visible('materialpoints'):
|
2019-07-16 05:37:04 +05:30
|
|
|
x = results.get_dataset_location(label)
|
|
|
|
if len(x) == 0:
|
|
|
|
continue
|
|
|
|
array = results.read_dataset(x,0)
|
|
|
|
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])
|
2019-10-14 17:43:03 +05:30
|
|
|
grid.GetCellData().AddArray(vtk_data[-1])
|
2019-07-16 05:37:04 +05:30
|
|
|
else:
|
2019-04-18 15:28:17 +05:30
|
|
|
x = results.get_dataset_location(label)
|
|
|
|
if len(x) == 0:
|
|
|
|
continue
|
|
|
|
array = results.read_dataset(x,0)
|
|
|
|
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))
|
2019-09-16 04:30:19 +05:30
|
|
|
vtk_data[-1].SetName('1_'+x[0].split('/',1)[1])
|
2019-10-14 17:43:03 +05:30
|
|
|
grid.GetCellData().AddArray(vtk_data[-1])
|
2019-04-18 15:28:17 +05:30
|
|
|
|
2019-10-19 01:33:31 +05:30
|
|
|
writer = vtk.vtkXMLRectilinearGridWriter() if results.structured else \
|
2019-10-14 17:43:03 +05:30
|
|
|
vtk.vtkXMLUnstructuredGridWriter()
|
2019-04-13 14:41:32 +05:30
|
|
|
|
2019-09-28 09:08:02 +05:30
|
|
|
results.set_visible('constituents', False)
|
|
|
|
results.set_visible('materialpoints',False)
|
|
|
|
x = results.get_dataset_location('u_n')
|
|
|
|
vtk_data.append(numpy_support.numpy_to_vtk(num_array=results.read_dataset(x,0),deep=True,array_type=vtk.VTK_DOUBLE))
|
|
|
|
vtk_data[-1].SetName('u')
|
2019-10-18 16:25:15 +05:30
|
|
|
grid.GetPointData().AddArray(vtk_data[-1])
|
2019-09-28 09:08:02 +05:30
|
|
|
|
2019-05-07 17:00:05 +05:30
|
|
|
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
2019-09-20 04:40:07 +05:30
|
|
|
if not os.path.isdir(dirname):
|
|
|
|
os.mkdir(dirname,0o755)
|
|
|
|
file_out = '{}_{}.{}'.format(os.path.splitext(os.path.split(filename)[-1])[0],inc,writer.GetDefaultFileExtension())
|
2019-05-07 17:00:05 +05:30
|
|
|
|
2019-04-13 14:41:32 +05:30
|
|
|
writer.SetCompressorTypeToZLib()
|
|
|
|
writer.SetDataModeToBinary()
|
2019-05-07 17:00:05 +05:30
|
|
|
writer.SetFileName(os.path.join(dirname,file_out))
|
2019-10-14 17:43:03 +05:30
|
|
|
writer.SetInputData(grid)
|
2019-04-13 14:41:32 +05:30
|
|
|
|
|
|
|
writer.Write()
|