2018-12-09 18:39:26 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2011-06-21 21:55:48 +05:30
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,sys,math
|
2014-06-17 12:40:10 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
2018-12-30 16:11:22 +05:30
|
|
|
from collections import OrderedDict
|
2014-06-17 12:40:10 +05:30
|
|
|
import damask
|
2011-06-21 21:55:48 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-03-10 19:31:39 +05:30
|
|
|
|
2011-06-21 21:55:48 +05:30
|
|
|
def Mises(what,tensor):
|
|
|
|
|
2014-06-17 12:40:10 +05:30
|
|
|
dev = tensor - np.trace(tensor)/3.0*np.eye(3)
|
2014-03-10 19:31:39 +05:30
|
|
|
symdev = 0.5*(dev+dev.T)
|
2014-06-17 12:40:10 +05:30
|
|
|
return math.sqrt(np.sum(symdev*symdev.T)*
|
2014-03-10 19:31:39 +05:30
|
|
|
{
|
|
|
|
'stress': 3.0/2.0,
|
|
|
|
'strain': 2.0/3.0,
|
|
|
|
}[what.lower()])
|
2011-06-21 21:55:48 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-17 02:50:10 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2011-06-21 21:55:48 +05:30
|
|
|
Add vonMises equivalent values for symmetric part of requested strains and/or stresses.
|
|
|
|
|
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('-e','--strain',
|
|
|
|
dest = 'strain',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'heading(s) of columns containing strain tensors')
|
|
|
|
parser.add_option('-s','--stress',
|
|
|
|
dest = 'stress',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'heading(s) of columns containing stress tensors')
|
|
|
|
|
2019-02-26 05:59:12 +05:30
|
|
|
parser.set_defaults(strain = [],
|
|
|
|
stress = [],
|
|
|
|
)
|
2011-06-21 21:55:48 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2019-02-26 05:59:12 +05:30
|
|
|
if options.stress is [] and options.strain is []:
|
2011-06-21 21:55:48 +05:30
|
|
|
parser.error('no data column specified...')
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- 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 ----------------------------------------
|
2011-06-21 21:55:48 +05:30
|
|
|
|
2018-12-31 11:48:45 +05:30
|
|
|
items = OrderedDict([
|
|
|
|
('strain', {'dim': 9, 'shape': [3,3], 'labels':options.strain, 'active':[], 'column': []}),
|
|
|
|
('stress', {'dim': 9, 'shape': [3,3], 'labels':options.stress, 'active':[], 'column': []})
|
|
|
|
])
|
2015-08-08 00:33:26 +05:30
|
|
|
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))
|
2011-06-21 21:55:48 +05:30
|
|
|
else:
|
2015-08-08 00:33:26 +05:30
|
|
|
items[type]['active'].append(what)
|
|
|
|
items[type]['column'].append(table.label_index(what))
|
|
|
|
table.labels_append('Mises({})'.format(what)) # extend ASCII header with new labels
|
2011-06-21 21:55:48 +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
|
|
|
|
|
|
|
|
# ------------------------------------------ assemble header --------------------------------------
|
|
|
|
|
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2011-12-15 14:23:18 +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-25 01:51:18 +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']:
|
|
|
|
table.data_append(Mises(type,
|
|
|
|
np.array(table.data[column:column+data['dim']],'d').reshape(data['shape'])))
|
2014-07-25 01:51:18 +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
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close() # close input ASCII table (works for stdin)
|