2019-05-05 13:39:23 +05:30
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
2019-09-14 04:31:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2019-05-05 13:39:23 +05:30
|
|
|
import damask
|
|
|
|
|
|
|
|
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-14 21:22:07 +05:30
|
|
|
help='labels for materialpoint',dest='mat')
|
2019-05-16 03:57:06 +05:30
|
|
|
parser.add_argument('--con', nargs='+',
|
2019-09-14 21:22:07 +05:30
|
|
|
help='labels for constituent',dest='con')
|
2019-05-05 13:39:23 +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-05-05 13:39:23 +05:30
|
|
|
|
|
|
|
# --- loop over input files ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
for filename in options.filenames:
|
|
|
|
results = damask.DADF5(filename)
|
|
|
|
|
|
|
|
if not results.structured: continue
|
|
|
|
delta = results.size/results.grid*0.5
|
|
|
|
x, y, z = np.meshgrid(np.linspace(delta[2],results.size[2]-delta[2],results.grid[2]),
|
|
|
|
np.linspace(delta[1],results.size[1]-delta[1],results.grid[1]),
|
|
|
|
np.linspace(delta[0],results.size[0]-delta[0],results.grid[0]),
|
|
|
|
indexing = 'ij')
|
|
|
|
|
|
|
|
coords = np.concatenate((z[:,:,:,None],y[:,:,:,None],x[:,:,:,None]),axis = 3)
|
|
|
|
|
2019-11-29 21:23:40 +05:30
|
|
|
N_digits = int(np.floor(np.log10(int(results.increments[-1][3:]))))+1
|
|
|
|
N_digits = 5 # hack to keep test intact
|
2019-09-16 05:38:03 +05:30
|
|
|
for i,inc in enumerate(results.iter_visible('increments')):
|
2019-05-05 13:39:23 +05:30
|
|
|
print('Output step {}/{}'.format(i+1,len(results.increments)))
|
|
|
|
|
|
|
|
header = '1 header\n'
|
|
|
|
|
2019-09-16 05:38:03 +05:30
|
|
|
data = np.array([int(inc[3:]) for j in range(np.product(results.grid))]).reshape([np.product(results.grid),1])
|
2019-05-05 13:39:23 +05:30
|
|
|
header+= 'inc'
|
|
|
|
|
|
|
|
coords = coords.reshape([np.product(results.grid),3])
|
|
|
|
data = np.concatenate((data,coords),1)
|
|
|
|
header+=' 1_pos 2_pos 3_pos'
|
2019-09-14 10:11:35 +05:30
|
|
|
|
2019-11-25 01:53:43 +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-11-25 01:53:43 +05:30
|
|
|
x = results.get_dataset_location(label)
|
|
|
|
if len(x) == 0:
|
|
|
|
continue
|
|
|
|
array = results.read_dataset(x,0,plain=True)
|
|
|
|
d = np.product(np.shape(array)[1:])
|
|
|
|
data = np.concatenate((data,np.reshape(array,[np.product(results.grid),d])),1)
|
2019-05-16 13:01:13 +05:30
|
|
|
|
2019-11-25 01:53:43 +05:30
|
|
|
if d>1:
|
|
|
|
header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)])
|
|
|
|
else:
|
|
|
|
header+=' '+label
|
|
|
|
|
|
|
|
results.set_visible('constituents', False)
|
|
|
|
results.set_visible('materialpoints',True)
|
2019-05-16 15:14:03 +05:30
|
|
|
for label in options.mat:
|
2019-11-25 01:53:43 +05:30
|
|
|
x = results.get_dataset_location(label)
|
|
|
|
if len(x) == 0:
|
|
|
|
continue
|
|
|
|
array = results.read_dataset(x,0,plain=True)
|
|
|
|
d = np.product(np.shape(array)[1:])
|
|
|
|
data = np.concatenate((data,np.reshape(array,[np.product(results.grid),d])),1)
|
2019-05-07 18:48:12 +05:30
|
|
|
|
2019-11-25 01:53:43 +05:30
|
|
|
if d>1:
|
|
|
|
header+= ''.join([' {}_{}'.format(j+1,label) for j in range(d)])
|
|
|
|
else:
|
|
|
|
header+=' '+label
|
2019-05-07 18:48:12 +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)
|
2019-11-30 00:02:18 +05:30
|
|
|
file_out = '{}_inc{}.txt'.format(os.path.splitext(os.path.split(filename)[-1])[0],
|
|
|
|
inc[3:].zfill(N_digits))
|
2019-05-07 18:48:12 +05:30
|
|
|
np.savetxt(os.path.join(dirname,file_out),data,header=header,comments='')
|