2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2012-06-12 19:39:16 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2014-07-25 03:12:13 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-07-25 03:12:13 +05:30
|
|
|
import damask
|
2012-06-12 19:39:16 +05:30
|
|
|
|
2019-06-14 16:33:30 +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-06-12 19:39:16 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:55:41 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2016-03-03 15:13:43 +05:30
|
|
|
Add column(s) containing Second Piola--Kirchhoff stress based on given column(s) of deformation
|
|
|
|
gradient and first Piola--Kirchhoff stress.
|
2012-06-12 19:39:16 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2012-06-12 19:39:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
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',
|
|
|
|
)
|
2012-06-12 19:39:16 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
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 ------------------------------------------
|
2012-06-12 19:39:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.head_read()
|
|
|
|
|
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
|
|
|
|
|
|
|
errors = []
|
|
|
|
column = {}
|
|
|
|
|
|
|
|
for tensor in [options.defgrad,options.stress]:
|
|
|
|
dim = table.label_dimension(tensor)
|
|
|
|
if dim < 0: errors.append('column {} not found.'.format(tensor))
|
|
|
|
elif dim != 9: errors.append('column {} is not a tensor.'.format(tensor))
|
|
|
|
else:
|
|
|
|
column[tensor] = table.label_index(tensor)
|
|
|
|
|
|
|
|
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
|
2012-06-12 19:39:16 +05:30
|
|
|
|
2015-05-10 03:02:23 +05:30
|
|
|
# ------------------------------------------ assemble header --------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2016-10-31 20:10:58 +05:30
|
|
|
table.labels_append(['{}_S'.format(i+1) for i in range(9)]) # extend ASCII header with new labels
|
2012-06-12 19:39:16 +05:30
|
|
|
table.head_write()
|
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
2014-07-25 03:12:13 +05:30
|
|
|
outputAlive = True
|
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
2018-07-19 20:23:48 +05:30
|
|
|
F = np.array(list(map(float,table.data[column[options.defgrad]:column[options.defgrad]+9])),'d').reshape(3,3)
|
|
|
|
P = np.array(list(map(float,table.data[column[options.stress ]:column[options.stress ]+9])),'d').reshape(3,3)
|
2014-07-25 03:12:13 +05:30
|
|
|
table.data_append(list(np.dot(np.linalg.inv(F),P).reshape(9))) # [S] =[P].[F-1]
|
|
|
|
outputAlive = table.data_write() # output processed line
|
2012-06-12 19:39:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2012-06-12 19:39:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close() # close input ASCII table (works for stdin)
|