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()
|
|
|
|
|
|
|
|
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='+',
|
2020-11-18 19:22:16 +05:30
|
|
|
help='labels for homogenization',dest='mat')
|
2019-05-16 03:57:06 +05:30
|
|
|
parser.add_argument('--con', nargs='+',
|
2020-11-18 19:22:16 +05:30
|
|
|
help='labels for phase',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
|
|
|
|
|
|
|
for filename in options.filenames:
|
2020-03-17 06:19:47 +05:30
|
|
|
results = damask.Result(filename)
|
|
|
|
|
|
|
|
if not results.structured: continue
|
2020-04-21 22:19:50 +05:30
|
|
|
coords = damask.grid_filters.cell_coord0(results.grid,results.size,results.origin).reshape(-1,3,order='F')
|
2020-03-17 06:19:47 +05:30
|
|
|
|
|
|
|
N_digits = int(np.floor(np.log10(int(results.increments[-1][3:]))))+1
|
|
|
|
N_digits = 5 # hack to keep test intact
|
2020-03-19 12:43:13 +05:30
|
|
|
for inc in damask.util.show_progress(results.iterate('increments'),len(results.increments)):
|
2020-09-15 10:28:06 +05:30
|
|
|
table = damask.Table(np.ones(np.product(results.grid),dtype=int)*int(inc[3:]),{'inc':(1,)})\
|
|
|
|
.add('pos',coords.reshape(-1,3))
|
2020-03-17 06:19:47 +05:30
|
|
|
|
2020-11-18 19:22:16 +05:30
|
|
|
results.pick('homogenizations',False)
|
|
|
|
results.pick('phases',True)
|
2020-03-17 06:19:47 +05:30
|
|
|
for label in options.con:
|
|
|
|
x = results.get_dataset_location(label)
|
|
|
|
if len(x) != 0:
|
2020-09-14 15:47:43 +05:30
|
|
|
table = table.add(label,results.read_dataset(x,0,plain=True).reshape(results.grid.prod(),-1))
|
2020-03-17 06:19:47 +05:30
|
|
|
|
2020-11-18 19:22:16 +05:30
|
|
|
results.pick('phases',False)
|
|
|
|
results.pick('homogenizations',True)
|
2020-03-17 06:19:47 +05:30
|
|
|
for label in options.mat:
|
|
|
|
x = results.get_dataset_location(label)
|
|
|
|
if len(x) != 0:
|
2020-09-14 10:34:01 +05:30
|
|
|
table = table.add(label,results.read_dataset(x,0,plain=True).reshape(results.grid.prod(),-1))
|
2020-03-17 06:19:47 +05:30
|
|
|
|
|
|
|
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
|
|
|
|
if not os.path.isdir(dirname):
|
|
|
|
os.mkdir(dirname,0o755)
|
|
|
|
file_out = '{}_inc{}.txt'.format(os.path.splitext(os.path.split(filename)[-1])[0],
|
|
|
|
inc[3:].zfill(N_digits))
|
2020-09-21 00:15:06 +05:30
|
|
|
table.save(os.path.join(dirname,file_out),legacy=True)
|