2016-07-18 23:05:35 +05:30
|
|
|
#!/usr/bin/env python2.7
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,sys
|
2014-08-04 23:23:41 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
2012-11-24 03:19: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
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2014-08-04 23:23:41 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[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')
|
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
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
for type, data in items.iteritems():
|
|
|
|
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-08-13 05:44:34 +05:30
|
|
|
table.labels_append(['eigval{}({})'.format(t,what) for t in ['Min','Mid','Max']])
|
|
|
|
table.labels_append(['{}_eigvec{}({})'.format(i+1,t,what) for t in ['Min','Mid','Max'] for i in range(3)])
|
|
|
|
|
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
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
|
2015-08-08 00:33:26 +05:30
|
|
|
for type, data in items.iteritems():
|
|
|
|
for column in data['column']:
|
2015-12-05 04:04:19 +05:30
|
|
|
(u,v) = np.linalg.eigh(np.array(map(float,table.data[column:column+data['dim']])).reshape(data['shape']))
|
2016-09-11 18:11:48 +05:30
|
|
|
if np.dot(np.cross(v[:,0], v[:,1]), v[:,2]) < 0.0 : v[:, 2] *= -1.0 # ensure right-handed coordinate system
|
2015-08-08 00:33:26 +05:30
|
|
|
table.data_append(list(u))
|
|
|
|
table.data_append(list(v.transpose().reshape(data['dim'])))
|
2014-08-04 23:23:41 +05:30
|
|
|
outputAlive = table.data_write() # output processed line
|
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)
|