2019-04-13 14:41:32 +05:30
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
|
|
|
import os,vtk
|
|
|
|
import numpy as np
|
|
|
|
import argparse
|
|
|
|
import damask
|
2019-04-17 23:27:16 +05:30
|
|
|
from vtk.util import numpy_support
|
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',
|
|
|
|
help='name of subdirectory to hold output')
|
2019-04-13 14:41:32 +05:30
|
|
|
|
|
|
|
options = parser.parse_args()
|
|
|
|
|
2019-04-18 15:28:17 +05:30
|
|
|
options.labels = ['Fe','Fp','xi_sl']
|
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-04-18 15:28:17 +05:30
|
|
|
if results.structured: # for grid solvers use rectilinear grid
|
2019-04-13 14:41:32 +05:30
|
|
|
rGrid = vtk.vtkRectilinearGrid()
|
|
|
|
coordArray = [vtk.vtkDoubleArray(),
|
|
|
|
vtk.vtkDoubleArray(),
|
|
|
|
vtk.vtkDoubleArray(),
|
|
|
|
]
|
|
|
|
|
2019-04-18 15:28:17 +05:30
|
|
|
rGrid.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)
|
|
|
|
|
|
|
|
rGrid.SetXCoordinates(coordArray[0])
|
|
|
|
rGrid.SetYCoordinates(coordArray[1])
|
|
|
|
rGrid.SetZCoordinates(coordArray[2])
|
|
|
|
|
|
|
|
|
2019-04-18 15:28:17 +05:30
|
|
|
for i,inc in enumerate(results.increments):
|
|
|
|
print('Output step {}/{}'.format(i+1,len(results.increments)))
|
|
|
|
vtk_data = []
|
|
|
|
results.active['increments'] = [inc]
|
|
|
|
for label in options.labels:
|
|
|
|
for o in results.c_output_types:
|
|
|
|
results.active['c_output_types'] = [o]
|
|
|
|
if o != 'generic':
|
|
|
|
for c in results.constituents:
|
|
|
|
results.active['constituents'] = [c]
|
|
|
|
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])
|
|
|
|
rGrid.GetCellData().AddArray(vtk_data[-1])
|
|
|
|
else:
|
|
|
|
results.active['constituents'] = results.constituents
|
|
|
|
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]+'/generic/'+label)
|
|
|
|
rGrid.GetCellData().AddArray(vtk_data[-1])
|
|
|
|
|
|
|
|
if results.structured:
|
2019-04-13 14:41:32 +05:30
|
|
|
writer = vtk.vtkXMLRectilinearGridWriter()
|
|
|
|
|
2019-05-07 17:00:05 +05:30
|
|
|
|
|
|
|
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
|
|
|
try:
|
|
|
|
os.mkdir(dirname)
|
|
|
|
except FileExistsError:
|
|
|
|
pass
|
|
|
|
file_out = '{}_inc{:04d}.{}'.format(filename.split('.')[0],i,writer.GetDefaultFileExtension())
|
|
|
|
|
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-04-18 15:28:17 +05:30
|
|
|
if results.structured:
|
2019-04-13 14:41:32 +05:30
|
|
|
writer.SetInputData(rGrid)
|
|
|
|
|
|
|
|
writer.Write()
|