2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2016-04-15 03:13:19 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-12-04 00:00:55 +05:30
|
|
|
from io import StringIO
|
2019-06-14 16:33:30 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
|
2016-04-15 03:13:19 +05:30
|
|
|
import numpy as np
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-04-15 03:13:19 +05:30
|
|
|
import damask
|
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-04-15 03:13:19 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2016-04-16 03:57:23 +05:30
|
|
|
Add displacments resulting from deformation gradient field.
|
2016-04-15 03:13:19 +05:30
|
|
|
Operates on periodic three-dimensional x,y,z-ordered data sets.
|
2016-04-16 03:57:23 +05:30
|
|
|
Outputs at cell centers or cell nodes (into separate file).
|
2016-04-15 03:13:19 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2016-04-23 00:50:36 +05:30
|
|
|
parser.add_option('-f',
|
|
|
|
'--defgrad',
|
2019-12-04 00:00:55 +05:30
|
|
|
dest = 'f',
|
2016-04-15 03:13:19 +05:30
|
|
|
metavar = 'string',
|
2016-05-17 14:35:50 +05:30
|
|
|
help = 'label of deformation gradient [%default]')
|
2016-04-23 00:50:36 +05:30
|
|
|
parser.add_option('-p',
|
|
|
|
'--pos', '--position',
|
2016-04-27 18:58:43 +05:30
|
|
|
dest = 'pos',
|
2016-04-15 03:13:19 +05:30
|
|
|
metavar = 'string',
|
2016-04-23 00:50:36 +05:30
|
|
|
help = 'label of coordinates [%default]')
|
2016-04-15 03:13:19 +05:30
|
|
|
parser.add_option('--nodal',
|
|
|
|
dest = 'nodal',
|
|
|
|
action = 'store_true',
|
2016-07-25 10:16:11 +05:30
|
|
|
help = 'output nodal (instead of cell-centered) displacements')
|
2016-04-15 03:13:19 +05:30
|
|
|
|
2019-12-04 00:00:55 +05:30
|
|
|
parser.set_defaults(f = 'f',
|
|
|
|
pos = 'pos',
|
2016-04-15 03:13:19 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
for name in filenames:
|
2019-12-04 00:00:55 +05:30
|
|
|
damask.util.report(scriptName,name)
|
|
|
|
|
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
grid,size = damask.util.coordGridAndSize(table.get_array(options.pos))
|
|
|
|
|
2019-12-05 18:05:06 +05:30
|
|
|
F = table.get(options.f).reshape(np.append(grid[::-1],(3,3)))
|
2019-12-04 00:00:55 +05:30
|
|
|
if options.nodal:
|
|
|
|
table = damask.Table(damask.grid_filters.coord0_node(grid[::-1],size[::-1]).reshape((-1,3)),
|
|
|
|
{'pos':(3,)})
|
2019-12-05 18:05:06 +05:30
|
|
|
table.add('avg({}).{}'.format(options.f,options.pos),
|
|
|
|
damask.grid_filters.displacement_avg_node(size[::-1],F).reshape((-1,3)),
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
table.add('fluct({}).{}'.format(options.f,options.pos),
|
|
|
|
damask.grid_filters.displacement_fluct_node(size[::-1],F).reshape((-1,3)),
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
2019-12-04 00:00:55 +05:30
|
|
|
table.to_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'_nodal.txt')
|
|
|
|
else:
|
2019-12-05 18:05:06 +05:30
|
|
|
table.add('avg({}).{}'.format(options.f,options.pos),
|
|
|
|
damask.grid_filters.displacement_avg_cell(size[::-1],F).reshape((-1,3)),
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
table.add('fluct({}).{}'.format(options.f,options.pos),
|
|
|
|
damask.grid_filters.displacement_fluct_cell(size[::-1],F).reshape((-1,3)),
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
2019-12-04 00:00:55 +05:30
|
|
|
table.to_ASCII(sys.stdout if name is None else name)
|