2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2014-08-04 23:23:41 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-08-04 23:23:41 +05:30
|
|
|
import damask
|
2012-11-24 03:19:30 +05:30
|
|
|
|
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])
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2012-11-24 03:19:30 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-17 02:50:10 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2015-12-05 04:04:19 +05:30
|
|
|
Add column(s) containing eigenvalues and eigenvectors of requested symmetric tensor column(s).
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-t','--tensor',
|
|
|
|
dest = 'tensor',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'heading of columns containing tensor field values')
|
2017-07-28 23:14:17 +05:30
|
|
|
parser.add_option('--no-check',
|
|
|
|
dest = 'rh',
|
|
|
|
action = 'store_false',
|
|
|
|
help = 'skip check for right-handed eigenvector basis')
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2017-07-28 23:14:17 +05:30
|
|
|
parser.set_defaults(rh = True,
|
|
|
|
)
|
2012-11-24 03:19:30 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2016-03-02 01:41:43 +05:30
|
|
|
if options.tensor is None:
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.error('no data column specified.')
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2014-08-04 23:23:41 +05:30
|
|
|
for name in filenames:
|
2015-08-21 01:12:05 +05:30
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(name = name,
|
|
|
|
buffered = False)
|
|
|
|
except: continue
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.head_read()
|
|
|
|
|
2017-08-13 05:44:34 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ assemble header 1 ------------------------------------
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
items = {
|
|
|
|
'tensor': {'dim': 9, 'shape': [3,3], 'labels':options.tensor, 'column': []},
|
|
|
|
}
|
|
|
|
errors = []
|
|
|
|
remarks = []
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2018-07-19 19:46:10 +05:30
|
|
|
for type, data in items.items():
|
2015-08-08 00:33:26 +05:30
|
|
|
for what in data['labels']:
|
|
|
|
dim = table.label_dimension(what)
|
|
|
|
if dim != data['dim']: remarks.append('column {} is not a {}...'.format(what,type))
|
|
|
|
else:
|
|
|
|
items[type]['column'].append(table.label_index(what))
|
2017-07-28 23:14:17 +05:30
|
|
|
for order in ['Min','Mid','Max']:
|
|
|
|
table.labels_append(['eigval{}({})'.format(order,what)]) # extend ASCII header with new labels
|
|
|
|
for order in ['Min','Mid','Max']:
|
|
|
|
table.labels_append(['{}_eigvec{}({})'.format(i+1,order,what) for i in range(3)]) # extend ASCII header with new labels
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-09-24 14:54:42 +05:30
|
|
|
if remarks != []: damask.util.croak(remarks)
|
2015-08-08 00:33:26 +05:30
|
|
|
if errors != []:
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.croak(errors)
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close(dismiss = True)
|
|
|
|
continue
|
|
|
|
|
2017-08-13 05:44:34 +05:30
|
|
|
# ------------------------------------------ assemble header 2 ------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2014-08-04 23:23:41 +05:30
|
|
|
table.head_write()
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2017-08-13 05:44:34 +05:30
|
|
|
# ------------------------------------------ process data -----------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2014-08-04 23:23:41 +05:30
|
|
|
outputAlive = True
|
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
2018-07-19 19:46:10 +05:30
|
|
|
for type, data in items.items():
|
2015-08-08 00:33:26 +05:30
|
|
|
for column in data['column']:
|
2018-07-19 20:23:48 +05:30
|
|
|
(u,v) = np.linalg.eigh(np.array(list(map(float,table.data[column:column+data['dim']]))).reshape(data['shape']))
|
2017-07-28 23:14:17 +05:30
|
|
|
if options.rh and np.dot(np.cross(v[:,0], v[:,1]), v[:,2]) < 0.0 : v[:, 2] *= -1.0 # ensure right-handed eigenvector basis
|
|
|
|
table.data_append(list(u)) # vector of max,mid,min eigval
|
|
|
|
table.data_append(list(v.transpose().reshape(data['dim']))) # 3x3=9 combo vector of max,mid,min eigvec coordinates
|
|
|
|
outputAlive = table.data_write() # output processed line in accordance with column labeling
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close() # close input ASCII table (works for stdin)
|