2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2011-06-21 21:55:48 +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
|
2014-07-16 22:11:04 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-07-16 22:11:04 +05:30
|
|
|
import damask
|
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-07-25 00:17:09 +05:30
|
|
|
|
2015-04-24 13:37:13 +05:30
|
|
|
|
2011-06-21 21:55:48 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-11-28 20:16:22 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
|
|
|
Add column(s) containing divergence of requested column(s).
|
|
|
|
Operates on periodic ordered three-dimensional data sets of vector and tensor fields.
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2011-06-21 21:55:48 +05:30
|
|
|
|
2016-04-25 16:52:34 +05:30
|
|
|
parser.add_option('-p','--pos','--periodiccellcenter',
|
2016-04-27 02:19:58 +05:30
|
|
|
dest = 'pos',
|
2015-08-08 00:33:26 +05:30
|
|
|
type = 'string', metavar = 'string',
|
2016-04-25 16:27:38 +05:30
|
|
|
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',
|
2015-08-08 00:33:26 +05:30
|
|
|
action = 'extend', metavar = '<string LIST>',
|
2018-01-30 07:57:05 +05:30
|
|
|
help = 'label(s) of field values')
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2016-04-27 02:19:58 +05:30
|
|
|
parser.set_defaults(pos = 'pos',
|
2015-08-08 00:33:26 +05:30
|
|
|
)
|
2011-06-21 21:55:48 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
2015-08-13 14:02:09 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2019-11-28 20:16:22 +05:30
|
|
|
if options.labels is None: parser.error('no data column specified.')
|
2015-08-08 00:33:26 +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 = (3,) if np.prod(field.shape)//np.prod(grid) == 3 else (3,3) # vector or tensor
|
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('divFFT({})'.format(label),
|
|
|
|
damask.grid_filters.divergence(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)
|