DAMASK_EICMD/processing/post/addMises.py

57 lines
2.0 KiB
Python
Raw Normal View History

2018-12-09 18:39:26 +05:30
#!/usr/bin/env python3
import os
import sys
2019-11-27 13:15:01 +05:30
from io import StringIO
from optparse import OptionParser
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
Add vonMises equivalent values for symmetric part of requested strains and/or stresses.
""", version = scriptID)
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')
parser.set_defaults(strain = [],
stress = [],
)
(options,filenames) = parser.parse_args()
if options.stress is [] and options.strain is []:
2019-11-27 13:15:01 +05:30
parser.error('no data column specified...')
if filenames == []: filenames = [None]
for name in filenames:
2019-11-27 13:15:01 +05:30
damask.util.report(scriptName,name)
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
for strain in options.strain:
2019-12-05 10:40:27 +05:30
table.add('Mises({})'.format(strain),
damask.mechanics.Mises_strain(damask.mechanics.symmetric(table.get(strain).reshape(-1,3,3))),
scriptID+' '+' '.join(sys.argv[1:]))
2019-11-27 13:15:01 +05:30
for stress in options.stress:
2019-12-05 10:40:27 +05:30
table.add('Mises({})'.format(stress),
damask.mechanics.Mises_stress(damask.mechanics.symmetric(table.get(stress).reshape(-1,3,3))),
scriptID+' '+' '.join(sys.argv[1:]))
2019-11-27 13:15:01 +05:30
table.to_ASCII(sys.stdout if name is None else name)