DAMASK_EICMD/processing/post/addStrainTensors.py

99 lines
3.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import sys
2020-01-12 04:44:35 +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])
2019-12-23 14:49:38 +05:30
def parameters(stretch,strain):
2019-09-13 19:19:25 +05:30
"""Albrecht Bertram: Elasticity and Plasticity of Large Deformations An Introduction (3rd Edition, 2012), p. 102."""
return {
2019-12-23 14:49:38 +05:30
'V#ln': ('V',0.0),
'U#ln': ('U',0.0),
'V#Biot': ('V',-.5),
'U#Biot': ('U',+.5),
'V#Green': ('V',-1.),
'U#Green': ('U',+1.),
}[stretch+'#'+strain]
2011-12-04 15:27:13 +05:30
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
Add column(s) containing given strains based on given stretches of requested deformation gradient column(s).
""", version = scriptID)
parser.add_option('-u','--right',
dest = 'right',
action = 'store_true',
help = 'material strains based on right Cauchy--Green deformation, i.e., C and U')
parser.add_option('-v','--left',
dest = 'left',
action = 'store_true',
help = 'spatial strains based on left Cauchy--Green deformation, i.e., B and V')
parser.add_option('-0','--logarithmic',
dest = 'logarithmic',
action = 'store_true',
help = 'calculate logarithmic strain tensor')
parser.add_option('-1','--biot',
dest = 'biot',
action = 'store_true',
help = 'calculate biot strain tensor')
parser.add_option('-2','--green',
dest = 'green',
action = 'store_true',
help = 'calculate green strain tensor')
parser.add_option('-f','--defgrad',
dest = 'defgrad',
action = 'extend',
metavar = '<string LIST>',
help = 'heading(s) of columns containing deformation tensor values [%default]')
2019-02-16 19:23:56 +05:30
parser.set_defaults(
defgrad = ['f'],
)
(options,filenames) = parser.parse_args()
2019-12-23 14:49:38 +05:30
if filenames == []: filenames = [None]
2019-02-16 19:23:56 +05:30
if len(options.defgrad) > 1:
2019-12-23 14:49:38 +05:30
options.defgrad = options.defgrad[1:]
2019-02-16 19:23:56 +05:30
stretches = []
strains = []
if options.right: stretches.append('U')
if options.left: stretches.append('V')
if options.logarithmic: strains.append('ln')
if options.biot: strains.append('Biot')
if options.green: strains.append('Green')
if options.defgrad is None:
2019-12-23 14:49:38 +05:30
parser.error('no data column specified.')
for name in filenames:
2019-12-23 14:49:38 +05:30
damask.util.report(scriptName,name)
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
2019-12-23 14:49:38 +05:30
for defgrad in options.defgrad:
2020-03-17 16:52:48 +05:30
F = table.get(defgrad).reshape(-1,3,3)
2019-12-23 14:49:38 +05:30
for theStretch in stretches:
for theStrain in strains:
(t,m) = parameters(theStretch,theStrain)
label = '{}({}){}'.format(theStrain,theStretch,defgrad if defgrad != 'f' else '')
table.add(label,
2020-03-17 16:52:48 +05:30
damask.mechanics.strain_tensor(F,t,m).reshape(-1,9),
2019-12-23 14:49:38 +05:30
scriptID+' '+' '.join(sys.argv[1:]))
table.to_ASCII(sys.stdout if name is None else name)