generalized addCurl with --data instead of --tensor and --vector

This commit is contained in:
Philip Eisenlohr 2018-01-28 18:25:50 -05:00
parent 8fb127f31c
commit 30272fc355
2 changed files with 37 additions and 40 deletions

@ -1 +1 @@
Subproject commit 3341e5973bda63fe03ace6490dc6b010e188c3f3 Subproject commit 1c1e8008489d81773a13a247604144a8d7ee3723

View File

@ -4,6 +4,7 @@
import os,sys,math import os,sys,math
import numpy as np import numpy as np
from optparse import OptionParser from optparse import OptionParser
from collections import defaultdict
import damask import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptName = os.path.splitext(os.path.basename(__file__))[0]
@ -52,31 +53,25 @@ def curlFFT(geomdim,field):
parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [ASCIItable(s)]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [ASCIItable(s)]', description = """
Add column(s) containing curl of requested column(s). Add column(s) containing curl of requested column(s).
Operates on periodic ordered three-dimensional data sets. Operates on periodic ordered three-dimensional data sets
Deals with both vector- and tensor fields. of vector and tensor fields.
""", version = scriptID) """, version = scriptID)
parser.add_option('-p','--pos','--periodiccellcenter', parser.add_option('-p','--pos','--periodiccellcenter',
dest = 'pos', dest = 'pos',
type = 'string', metavar = 'string', type = 'string', metavar = 'string',
help = 'label of coordinates [%default]') help = 'label of coordinates [%default]')
parser.add_option('-v','--vector', parser.add_option('-d','--data',
dest = 'vector', dest = 'data',
action = 'extend', metavar = '<string LIST>', action = 'extend', metavar = '<string LIST>',
help = 'label(s) of vector field values') help = 'label(s) of field values')
parser.add_option('-t','--tensor',
dest = 'tensor',
action = 'extend', metavar = '<string LIST>',
help = 'label(s) of tensor field values')
parser.set_defaults(pos = 'pos', parser.set_defaults(pos = 'pos',
) )
(options,filenames) = parser.parse_args() (options,filenames) = parser.parse_args()
if options.vector is None and options.tensor is None: if options.data is None: parser.error('no data column specified.')
parser.error('no data column specified.')
# --- loop over input files ------------------------------------------------------------------------ # --- loop over input files ------------------------------------------------------------------------
@ -87,30 +82,31 @@ for name in filenames:
except: continue except: continue
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
# ------------------------------------------ read header ------------------------------------------ # --- interpret header ----------------------------------------------------------------------------
table.head_read() table.head_read()
# ------------------------------------------ sanity checks ----------------------------------------
items = {
'tensor': {'dim': 9, 'shape': [3,3], 'labels':options.tensor, 'active':[], 'column': []},
'vector': {'dim': 3, 'shape': [3], 'labels':options.vector, 'active':[], 'column': []},
}
errors = []
remarks = [] remarks = []
column = {} errors = []
active = defaultdict(list)
if table.label_dimension(options.pos) != 3: errors.append('coordinates {} are not a vector.'.format(options.pos))
else: colCoord = table.label_index(options.pos)
for type, data in items.iteritems(): coordDim = table.label_dimension(options.pos)
for what in (data['labels'] if data['labels'] is not None else []): if coordDim != 3:
dim = table.label_dimension(what) errors.append('coordinates "{}" must be three-dimensional.'.format(options.pos))
if dim != data['dim']: remarks.append('column {} is not a {}.'.format(what,type)) else: coordCol = table.label_index(options.pos)
else:
items[type]['active'].append(what) for i,dim in enumerate(table.label_dimension(options.data)):
items[type]['column'].append(table.label_index(what)) me = options.data[i]
if dim == -1:
remarks.append('"{}" not found...'.format(me))
elif dim == 9:
active['tensor'].append(me)
remarks.append('differentiating tensor "{}"...'.format(me))
elif dim == 3:
active['vector'].append(me)
remarks.append('differentiating vector "{}"...'.format(me))
else:
remarks.append('skipping "{}" of dimension {}...'.format(me,dim))
if remarks != []: damask.util.croak(remarks) if remarks != []: damask.util.croak(remarks)
if errors != []: if errors != []:
@ -118,19 +114,20 @@ for name in filenames:
table.close(dismiss = True) table.close(dismiss = True)
continue continue
# ------------------------------------------ assemble header -------------------------------------- # ------------------------------------------ assemble header --------------------------------------
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:])) table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
for type, data in items.iteritems(): for type, data in active.iteritems():
for label in data['active']: for label in data:
table.labels_append(['{}_curlFFT({})'.format(i+1,label) for i in range(data['dim'])]) # extend ASCII header with new labels table.labels_append(['{}_curlFFT({})'.format(i+1,label) for i in range(table.label_dimension(label))]) # extend ASCII header with new labels
table.head_write() table.head_write()
# --------------- figure out size and grid --------------------------------------------------------- # --------------- figure out size and grid ---------------------------------------------------------
table.data_readArray() table.data_readArray()
coords = [np.unique(table.data[:,colCoord+i]) for i in range(3)] coords = [np.unique(table.data[:,coordCol+i]) for i in range(3)]
mincorner = np.array(map(min,coords)) mincorner = np.array(map(min,coords))
maxcorner = np.array(map(max,coords)) maxcorner = np.array(map(max,coords))
grid = np.array(map(len,coords),'i') grid = np.array(map(len,coords),'i')
@ -140,12 +137,12 @@ for name in filenames:
# ------------------------------------------ process value field ----------------------------------- # ------------------------------------------ process value field -----------------------------------
stack = [table.data] stack = [table.data]
for type, data in items.iteritems(): for type, data in active.iteritems():
for i,label in enumerate(data['active']): for i,label in enumerate(data):
# we need to reverse order here, because x is fastest,ie rightmost, but leftmost in our x,y,z notation # we need to reverse order here, because x is fastest,ie rightmost, but leftmost in our x,y,z notation
stack.append(curlFFT(size[::-1], stack.append(curlFFT(size[::-1],
table.data[:,data['column'][i]:data['column'][i]+data['dim']]. table.data[:,table.label_indexrange(label)].
reshape(grid[::-1].tolist()+data['shape']))) reshape(grid[::-1].tolist()+[table.label_dimension(label)])))
# ------------------------------------------ output result ----------------------------------------- # ------------------------------------------ output result -----------------------------------------