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
|
2014-07-22 01:25:05 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2014-07-22 01:25:05 +05:30
|
|
|
import damask
|
2011-06-21 21:55:48 +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])
|
2011-06-21 21:55:48 +05:30
|
|
|
|
|
|
|
def determinant(m):
|
|
|
|
return +m[0]*m[4]*m[8] \
|
|
|
|
+m[1]*m[5]*m[6] \
|
|
|
|
+m[2]*m[3]*m[7] \
|
|
|
|
-m[2]*m[4]*m[6] \
|
|
|
|
-m[1]*m[3]*m[8] \
|
2014-07-22 01:25:05 +05:30
|
|
|
-m[0]*m[5]*m[7]
|
2011-06-21 21:55:48 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2011-06-21 21:55:48 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2011-06-21 21:55:48 +05:30
|
|
|
Add column(s) containing determinant of requested tensor column(s).
|
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2011-06-21 21:55:48 +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')
|
2011-06-21 21:55:48 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
if options.tensor is None:
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.error('no data column specified.')
|
|
|
|
|
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +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)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
2011-06-21 21:55:48 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
|
|
|
|
|
|
|
items = {
|
|
|
|
'tensor': {'dim': 9, 'shape': [3,3], 'labels':options.tensor, 'column': []},
|
|
|
|
}
|
|
|
|
errors = []
|
|
|
|
remarks = []
|
|
|
|
|
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))
|
|
|
|
table.labels_append('det({})'.format(what)) # extend ASCII header with new labels
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# ------------------------------------------ assemble header --------------------------------------
|
|
|
|
|
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2011-11-24 22:40:50 +05:30
|
|
|
table.head_write()
|
2011-06-21 21:55:48 +05:30
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2014-07-22 01:25:05 +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 19:56:30 +05:30
|
|
|
table.data_append(determinant(list(map(float,table.data[column: column+data['dim']]))))
|
2014-07-22 01:25:05 +05:30
|
|
|
outputAlive = table.data_write() # output processed line
|
2011-06-21 21:55:48 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2011-06-21 21:55:48 +05:30
|
|
|
|
2018-07-19 19:56:30 +05:30
|
|
|
table.close() # close input ASCII table (works for stdin)
|