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
# --------------------------------------------------------------------
2019-02-16 22:11:56 +05:30
parser = OptionParser(option_class=damask.extendableOption, 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.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
2020-01-13 07:21:49 +05:30
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(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:
table = damask.Table(damask.grid_filters.node_coord0(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.node_displacement_avg(size,F).reshape(-1,3,order='F'),
scriptID+' '+' '.join(sys.argv[1:]))\
.add('fluct({}).{}'.format(options.f,options.pos),
damask.grid_filters.node_displacement_fluct(size,F).reshape(-1,3,order='F'),
scriptID+' '+' '.join(sys.argv[1:]))
2020-09-03 20:49:19 +05:30
table.to_file(sys.stdout if name is None else os.path.splitext(name)[0]+'_nodal.txt')
2019-12-04 00:00:55 +05:30
else:
2020-09-14 10:34:01 +05:30
table = table.add('avg({}).{}'.format(options.f,options.pos),
damask.grid_filters.cell_displacement_avg(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.cell_displacement_fluct(size,F).reshape(-1,3,order='F'),
2019-12-05 18:05:06 +05:30
scriptID+' '+' '.join(sys.argv[1:]))
2020-09-03 20:49:19 +05:30
table.to_file(sys.stdout if name is None else name)