DAMASK_EICMD/processing/post/addDisplacement.py

72 lines
2.9 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import sys
2019-12-04 00:00:55 +05:30
from io import StringIO
from optparse import OptionParser
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
parser = OptionParser(usage='%prog options [ASCIItable(s)]', description = """
Add displacments resulting from deformation gradient field.
Operates on periodic three-dimensional x,y,z-ordered data sets.
Outputs at cell centers or cell nodes (into separate file).
""", 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',
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',
dest = 'pos',
metavar = 'string',
2016-04-23 00:50:36 +05:30
help = 'label of coordinates [%default]')
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')
2019-12-04 00:00:55 +05:30
parser.set_defaults(f = 'f',
pos = 'pos',
)
(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.load(StringIO(''.join(sys.stdin.read())) if name is None else name)
2020-12-08 05:06:41 +05:30
grid,size,origin = damask.grid_filters.cellsSizeOrigin_coordinates0_point(table.get(options.pos))
F = table.get(options.f).reshape(tuple(grid)+(-1,),order='F').reshape(tuple(grid)+(3,3))
2019-12-04 00:00:55 +05:30
if options.nodal:
damask.Table(damask.grid_filters.coordinates0_node(grid,size).reshape(-1,3,order='F'),
2020-09-14 10:34:01 +05:30
{'pos':(3,)})\
.add('avg({}).{}'.format(options.f,options.pos),
damask.grid_filters.displacement_avg_node(size,F).reshape(-1,3,order='F'),
2020-09-14 10:34:01 +05:30
scriptID+' '+' '.join(sys.argv[1:]))\
.add('fluct({}).{}'.format(options.f,options.pos),
damask.grid_filters.displacement_fluct_node(size,F).reshape(-1,3,order='F'),
scriptID+' '+' '.join(sys.argv[1:]))\
2020-11-24 01:24:07 +05:30
.save((sys.stdout if name is None else os.path.splitext(name)[0]+'_nodal.txt'))
2019-12-04 00:00:55 +05:30
else:
table.add('avg({}).{}'.format(options.f,options.pos),
damask.grid_filters.displacement_avg_point(size,F).reshape(-1,3,order='F'),
2020-09-14 10:34:01 +05:30
scriptID+' '+' '.join(sys.argv[1:]))\
.add('fluct({}).{}'.format(options.f,options.pos),
damask.grid_filters.displacement_fluct_point(size,F).reshape(-1,3,order='F'),
scriptID+' '+' '.join(sys.argv[1:]))\
2020-11-24 01:24:07 +05:30
.save((sys.stdout if name is None else name))