2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2012-11-14 16:16:51 +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
|
2012-11-14 16:16:51 +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-14 16:16:51 +05:30
|
|
|
|
2014-07-22 01:25:05 +05:30
|
|
|
oneThird = 1.0/3.0
|
2012-11-14 16:16:51 +05:30
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
def deviator(m,spherical = False): # Careful, do not change the value of m, its intent(inout)!
|
2012-11-14 16:16:51 +05:30
|
|
|
sph = oneThird*(m[0]+m[4]+m[8])
|
2015-08-08 00:33:26 +05:30
|
|
|
dev = [
|
|
|
|
m[0]-sph, m[1], m[2],
|
2014-09-12 18:43:05 +05:30
|
|
|
m[3], m[4]-sph, m[5],
|
2015-08-08 00:33:26 +05:30
|
|
|
m[6], m[7], m[8]-sph,
|
|
|
|
]
|
|
|
|
return dev,sph if spherical else dev
|
2012-11-14 16:16:51 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2012-11-14 16:16:51 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(2)]', description = """
|
2012-11-14 16:16:51 +05:30
|
|
|
Add column(s) containing deviator of requested tensor column(s).
|
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2012-11-14 16:16:51 +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')
|
|
|
|
parser.add_option('-s','--spherical',
|
|
|
|
dest = 'spherical',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'report spherical part of tensor (hydrostatic component, pressure)')
|
2012-11-14 16:16:51 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
if options.tensor is None:
|
2012-11-14 16:16:51 +05:30
|
|
|
parser.error('no data column specified...')
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
|
2015-08-18 22:54:15 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2015-08-18 22:54:15 +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()
|
|
|
|
|
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
2012-11-14 16:16:51 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
items = {
|
|
|
|
'tensor': {'dim': 9, 'shape': [3,3], 'labels':options.tensor, 'active':[], 'column': []},
|
|
|
|
}
|
|
|
|
errors = []
|
|
|
|
remarks = []
|
|
|
|
column = {}
|
|
|
|
|
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]['active'].append(what)
|
|
|
|
items[type]['column'].append(table.label_index(what))
|
|
|
|
|
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:]))
|
2018-07-19 19:46:10 +05:30
|
|
|
for type, data in items.items():
|
2015-08-08 00:33:26 +05:30
|
|
|
for label in data['active']:
|
2016-10-25 00:46:29 +05:30
|
|
|
table.labels_append(['{}_dev({})'.format(i+1,label) for i in range(data['dim'])] + \
|
2015-08-08 00:33:26 +05:30
|
|
|
(['sph({})'.format(label)] if options.spherical else [])) # extend ASCII header with new labels
|
2012-11-14 16:16:51 +05:30
|
|
|
table.head_write()
|
|
|
|
|
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(deviator(list(map(float,table.data[column:
|
|
|
|
column+data['dim']])),options.spherical))
|
2014-07-22 01:25:05 +05:30
|
|
|
outputAlive = table.data_write() # output processed line
|
2012-11-14 16:16:51 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2012-11-14 16:16:51 +05:30
|
|
|
|
2016-10-25 00:46:29 +05:30
|
|
|
table.close() # close input ASCII table (works for stdin)
|