2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2016-03-17 00:32:38 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-11-28 20:16:22 +05:30
|
|
|
from io import StringIO
|
2016-03-17 00:32:38 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2016-03-17 00:32:38 +05:30
|
|
|
import damask
|
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-03-17 00:32:38 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-05-27 01:00:38 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2016-03-17 00:32:38 +05:30
|
|
|
Add column(s) containing gradient of requested column(s).
|
2019-11-28 20:16:22 +05:30
|
|
|
Operates on periodic ordered three-dimensional data sets of scalar and vector fields.
|
2016-03-17 00:32:38 +05:30
|
|
|
""", version = scriptID)
|
|
|
|
|
2016-04-25 16:52:34 +05:30
|
|
|
parser.add_option('-p','--pos','--periodiccellcenter',
|
2016-04-27 02:19:58 +05:30
|
|
|
dest = 'pos',
|
2016-04-25 16:27:38 +05:30
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'label of coordinates [%default]')
|
2018-01-30 07:57:05 +05:30
|
|
|
parser.add_option('-l','--label',
|
2019-11-28 20:16:22 +05:30
|
|
|
dest = 'labels',
|
2016-03-17 00:32:38 +05:30
|
|
|
action = 'extend', metavar = '<string LIST>',
|
2018-01-29 04:32:35 +05:30
|
|
|
help = 'label(s) of field values')
|
2016-03-17 00:32:38 +05:30
|
|
|
|
2016-04-27 02:19:58 +05:30
|
|
|
parser.set_defaults(pos = 'pos',
|
2016-03-17 00:32:38 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
2019-11-28 20:16:22 +05:30
|
|
|
if options.labels is None: parser.error('no data column specified.')
|
2016-03-17 00:32:38 +05:30
|
|
|
|
2019-11-28 20:16:22 +05:30
|
|
|
for name in filenames:
|
|
|
|
damask.util.report(scriptName,name)
|
|
|
|
|
2020-09-21 00:15:06 +05:30
|
|
|
table = damask.Table.load(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))
|
2019-11-28 20:16:22 +05:30
|
|
|
|
|
|
|
for label in options.labels:
|
2019-12-05 18:05:06 +05:30
|
|
|
field = table.get(label)
|
2019-11-28 20:16:22 +05:30
|
|
|
shape = (1,) if np.prod(field.shape)//np.prod(grid) == 1 else (3,) # scalar or vector
|
2020-04-22 21:56:10 +05:30
|
|
|
field = field.reshape(tuple(grid)+(-1,),order='F')
|
2020-04-20 16:11:03 +05:30
|
|
|
grad = damask.grid_filters.gradient(size,field)
|
2020-09-14 10:34:01 +05:30
|
|
|
table = table.add('gradFFT({})'.format(label),
|
|
|
|
grad.reshape(tuple(grid)+(-1,)).reshape(-1,np.prod(shape)*3,order='F'),
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
2020-04-20 16:11:03 +05:30
|
|
|
|
2020-11-24 01:45:00 +05:30
|
|
|
table.save((sys.stdout if name is None else name))
|