2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2014-07-22 01:25:05 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-07-22 01:25:05 +05:30
|
|
|
import damask
|
2012-12-03 18:40: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-12-03 18:40:16 +05:30
|
|
|
|
|
|
|
def normalize(vec):
|
2014-07-22 01:25:05 +05:30
|
|
|
return vec/np.sqrt(np.inner(vec,vec))
|
2012-12-03 18:40:16 +05:30
|
|
|
|
|
|
|
def E_hkl(stiffness,vec): # stiffness = (c11,c12,c44)
|
|
|
|
v = normalize(vec)
|
|
|
|
S11 = (stiffness[0]+stiffness[1])/(stiffness[0]*stiffness[0]+stiffness[0]*stiffness[1]-2.0*stiffness[1]*stiffness[1])
|
|
|
|
S12 = ( -stiffness[1])/(stiffness[0]*stiffness[0]+stiffness[0]*stiffness[1]-2.0*stiffness[1]*stiffness[1])
|
|
|
|
S44 = 1.0/stiffness[2]
|
|
|
|
|
|
|
|
invE = S11-(S11-S12-0.5*S44)* (1.0 - \
|
2015-08-08 00:33:26 +05:30
|
|
|
(v[0]**4+v[1]**4+v[2]**4) \
|
|
|
|
/#------------------------------------
|
|
|
|
np.inner(v,v)**2 \
|
|
|
|
)
|
2012-12-03 18:40:16 +05:30
|
|
|
|
|
|
|
return 1.0/invE
|
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2012-12-03 18:40:16 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2014-08-06 18:57:09 +05:30
|
|
|
Add column(s) containing directional stiffness based on given cubic stiffness values C11, C12, and C44 in consecutive columns.
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-c','--stiffness',
|
|
|
|
dest = 'stiffness',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'heading of column containing C11 (followed by C12, C44) field values')
|
|
|
|
parser.add_option('-d','--direction','--hkl',
|
|
|
|
dest = 'hkl',
|
|
|
|
type = 'int', nargs = 3, metavar = 'int int int',
|
|
|
|
help = 'direction of elastic modulus [%default]')
|
|
|
|
parser.set_defaults(hkl = (1,1,1),
|
|
|
|
)
|
2012-12-03 18:40:16 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
if options.stiffness is None:
|
2012-12-03 18:40:16 +05:30
|
|
|
parser.error('no data column specified...')
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2015-08-18 22:54:15 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
for name in filenames:
|
2015-08-18 22:54:15 +05:30
|
|
|
try:
|
2020-02-20 19:35:38 +05:30
|
|
|
table = damask.ASCIItable(name = name)
|
|
|
|
except IOError:
|
2015-08-18 22:54:15 +05:30
|
|
|
continue
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.head_read()
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
remarks = []
|
|
|
|
columns = []
|
|
|
|
|
|
|
|
for i,column in enumerate(table.label_index(options.stiffness)):
|
|
|
|
if column < 0: remarks.append('column {} not found.'.format(options.stiffness[i]))
|
2014-08-04 23:23:41 +05:30
|
|
|
else:
|
2015-08-08 00:33:26 +05:30
|
|
|
columns.append(column)
|
2015-08-18 22:54:15 +05:30
|
|
|
table.labels_append(['E{}{}{}({arg2})'.format(*options.hkl,arg2=options.stiffness[i])]) # extend ASCII header with new labels
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-09-24 14:54:42 +05:30
|
|
|
if remarks != []: damask.util.croak(remarks)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ assemble header --------------------------------------
|
|
|
|
|
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2012-12-03 18:40:16 +05:30
|
|
|
table.head_write()
|
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
2014-07-22 01:25:05 +05:30
|
|
|
outputAlive = True
|
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
2015-08-08 00:33:26 +05:30
|
|
|
for column in columns:
|
2018-07-19 19:56:30 +05:30
|
|
|
table.data_append(E_hkl(list(map(float,table.data[column:column+3])),options.hkl))
|
2014-07-22 01:25:05 +05:30
|
|
|
outputAlive = table.data_write() # output processed line
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2012-12-03 18:40:16 +05:30
|
|
|
|
2018-07-19 19:56:30 +05:30
|
|
|
table.close() # close ASCII tables
|