DAMASK_EICMD/processing/post/addPK2.py

51 lines
1.8 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import sys
2019-11-27 16:49:37 +05:30
from io import StringIO
2014-07-25 03:12:13 +05:30
from optparse import OptionParser
2014-07-25 03:12:13 +05:30
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
2019-02-16 22:55:41 +05:30
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
Add column(s) containing Second Piola--Kirchhoff stress based on given column(s) of deformation
gradient and first Piola--Kirchhoff stress.
""", version = scriptID)
parser.add_option('-f','--defgrad',
dest = 'defgrad',
type = 'string', metavar = 'string',
help = 'heading of columns containing deformation gradient [%default]')
parser.add_option('-p','--stress',
dest = 'stress',
type = 'string', metavar = 'string',
help = 'heading of columns containing first Piola--Kirchhoff stress [%default]')
parser.set_defaults(defgrad = 'f',
stress = 'p',
)
(options,filenames) = parser.parse_args()
if filenames == []: filenames = [None]
for name in filenames:
2019-11-27 16:49:37 +05:30
damask.util.report(scriptName,name)
2019-11-27 16:49:37 +05:30
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
2019-11-27 16:49:37 +05:30
table.add_array('S',
damask.mechanics.PK2(table.get_array(options.defgrad).reshape(-1,3,3),
table.get_array(options.stress).reshape(-1,3,3)).reshape(-1,9),
scriptID+' '+' '.join(sys.argv[1:]))
2019-11-27 16:49:37 +05:30
table.to_ASCII(sys.stdout if name is None else name)