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)
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
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
|
2019-12-03 15:57:14 +05:30
|
|
|
field = field.reshape(np.append(grid[::-1],shape))
|
2019-12-05 18:05:06 +05:30
|
|
|
table.add('gradFFT({})'.format(label),
|
|
|
|
damask.grid_filters.gradient(size[::-1],field).reshape((-1,np.prod(shape)*3)),
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
2019-11-28 20:16:22 +05:30
|
|
|
|
|
|
|
table.to_ASCII(sys.stdout if name is None else name)
|