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
|
2020-02-15 20:41:57 +05:30
|
|
|
from io import StringIO
|
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,
|
|
|
|
)
|
2020-02-15 20:41:57 +05:30
|
|
|
|
2012-11-24 03:19:30 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
2020-02-15 20:41:57 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2020-02-15 20:41:57 +05:30
|
|
|
for name in filenames:
|
|
|
|
damask.util.report(scriptName,name)
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2020-02-15 20:41:57 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2020-02-15 20:41:57 +05:30
|
|
|
for tensor in options.tensor:
|
2012-11-24 03:19:30 +05:30
|
|
|
|
2020-02-15 20:41:57 +05:30
|
|
|
t = table.get(tensor).reshape(-1,3,3)
|
|
|
|
(u,v) = np.linalg.eigh(damask.mechanics.symmetric(t))
|
|
|
|
if options.rh: v[np.linalg.det(v) < 0.0,:,2] *= -1.0
|
|
|
|
|
|
|
|
for i,o in enumerate(['Min','Mid','Max']):
|
|
|
|
table.add('eigval{}({})'.format(o,tensor),u[:,i],
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
|
|
|
|
for i,o in enumerate(['Min','Mid','Max']):
|
|
|
|
table.add('eigvec{}({})'.format(o,tensor),v[:,:,i],
|
|
|
|
scriptID+' '+' '.join(sys.argv[1:]))
|
|
|
|
|
|
|
|
table.to_ASCII(sys.stdout if name is None else name)
|