2014-04-02 00:11:14 +05:30
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,sys,math
|
2014-08-05 01:37:20 +05:30
|
|
|
import numpy as np
|
2013-06-04 18:26:57 +05:30
|
|
|
from optparse import OptionParser
|
2014-08-05 01:37:20 +05:30
|
|
|
import damask
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-08-05 01:37:20 +05:30
|
|
|
|
|
|
|
slipnormal_temp = [
|
2013-06-04 18:26:57 +05:30
|
|
|
[0,0,0,1],
|
|
|
|
[0,0,0,1],
|
|
|
|
[0,0,0,1],
|
|
|
|
[0,1,-1,0],
|
|
|
|
[-1,0,1,0],
|
|
|
|
[1,-1,0,0],
|
|
|
|
[0,1,-1,1],
|
|
|
|
[-1,1,0,1],
|
|
|
|
[-1,0,1,1],
|
|
|
|
[0,-1,1,1],
|
|
|
|
[1,-1,0,1],
|
|
|
|
[1,0,-1,1],
|
|
|
|
[0,1,-1,1],
|
|
|
|
[0,1,-1,1],
|
|
|
|
[-1,1,0,1],
|
|
|
|
[-1,1,0,1],
|
|
|
|
[-1,0,1,1],
|
|
|
|
[-1,0,1,1],
|
|
|
|
[0,-1,1,1],
|
|
|
|
[0,-1,1,1],
|
|
|
|
[1,-1,0,1],
|
|
|
|
[1,-1,0,1],
|
|
|
|
[1,0,-1,1],
|
|
|
|
[1,0,-1,1],
|
|
|
|
]
|
|
|
|
|
|
|
|
slipdirection_temp = [
|
|
|
|
[2,-1,-1,0],
|
|
|
|
[-1,2,-1,0],
|
|
|
|
[-1,-1,2,0],
|
|
|
|
[2,-1,-1,0],
|
|
|
|
[-1,2,-1,0],
|
|
|
|
[-1,-1,2,0],
|
|
|
|
[2,-1,-1,0],
|
|
|
|
[1,1,-2,0],
|
|
|
|
[-1,2,-1,0],
|
|
|
|
[-2,1,1,0],
|
|
|
|
[-1,-1,2,0],
|
|
|
|
[1,-2,1,0],
|
|
|
|
[-1,2,-1,3],
|
|
|
|
[1,1,-2,3],
|
|
|
|
[-2,1,1,3],
|
|
|
|
[-1,2,-1,3],
|
|
|
|
[-1,-1,2,3],
|
|
|
|
[-2,1,1,3],
|
|
|
|
[1,-2,1,3],
|
|
|
|
[-1,-1,2,3],
|
|
|
|
[2,-1,-1,3],
|
|
|
|
[1,-2,1,3],
|
|
|
|
[1,1,-2,3],
|
|
|
|
[2,-1,-1,3],
|
|
|
|
]
|
|
|
|
|
|
|
|
# slip normals and directions according to cpfem implementation
|
|
|
|
Nslipsystems = {'fcc': 12, 'bcc': 24, 'hex': 24}
|
|
|
|
slipnormal = { \
|
|
|
|
'fcc': [
|
|
|
|
[1,1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[-1,-1,1],
|
|
|
|
[-1,-1,1],
|
|
|
|
[-1,-1,1],
|
|
|
|
[1,-1,-1],
|
|
|
|
[1,-1,-1],
|
|
|
|
[1,-1,-1],
|
|
|
|
[-1,1,-1],
|
|
|
|
[-1,1,-1],
|
|
|
|
[-1,1,-1],
|
|
|
|
],
|
|
|
|
'bcc': [
|
|
|
|
[0,1,1],
|
|
|
|
[0,1,1],
|
|
|
|
[0,-1,1],
|
|
|
|
[0,-1,1],
|
|
|
|
[1,0,1],
|
|
|
|
[1,0,1],
|
|
|
|
[-1,0,1],
|
|
|
|
[-1,0,1],
|
|
|
|
[1,1,0],
|
|
|
|
[1,1,0],
|
|
|
|
[-1,1,0],
|
|
|
|
[-1,1,0],
|
|
|
|
[2,1,1],
|
|
|
|
[-2,1,1],
|
|
|
|
[2,-1,1],
|
|
|
|
[2,1,-1],
|
|
|
|
[1,2,1],
|
|
|
|
[-1,2,1],
|
|
|
|
[1,-2,1],
|
|
|
|
[1,2,-1],
|
|
|
|
[1,1,2],
|
|
|
|
[-1,1,2],
|
|
|
|
[1,-1,2],
|
|
|
|
[1,1,-2],
|
|
|
|
],
|
|
|
|
'hex': [ # these are dummy numbers and are recalculated based on the above hex real slip systems.
|
|
|
|
[1,1,0],
|
|
|
|
[1,1,0],
|
|
|
|
[1,0,1],
|
|
|
|
[1,0,1],
|
|
|
|
[0,1,1],
|
|
|
|
[0,1,1],
|
|
|
|
[1,-1,0],
|
|
|
|
[1,-1,0],
|
|
|
|
[-1,0,1],
|
|
|
|
[-1,0,1],
|
|
|
|
[0,-1,1],
|
|
|
|
[0,-1,1],
|
|
|
|
[2,-1,1],
|
|
|
|
[1,-2,-1],
|
|
|
|
[1,1,2],
|
|
|
|
[2,1,1],
|
|
|
|
[1,2,-1],
|
|
|
|
[1,-1,2],
|
|
|
|
[2,1,-1],
|
|
|
|
[1,2,1],
|
|
|
|
[1,-1,-2],
|
|
|
|
[2,-1,-1],
|
|
|
|
[1,-2,1],
|
|
|
|
[1,1,-2],
|
|
|
|
],
|
|
|
|
}
|
|
|
|
slipdirection = { \
|
|
|
|
'fcc': [
|
|
|
|
[0,1,-1],
|
|
|
|
[-1,0,1],
|
|
|
|
[1,-1,0],
|
|
|
|
[0,-1,-1],
|
|
|
|
[1,0,1],
|
|
|
|
[-1,1,0],
|
|
|
|
[0,-1,1],
|
|
|
|
[-1,0,-1],
|
|
|
|
[1,1,0],
|
|
|
|
[0,1,1],
|
|
|
|
[1,0,-1],
|
|
|
|
[-1,-1,0],
|
|
|
|
],
|
|
|
|
'bcc': [
|
|
|
|
[1,-1,1],
|
|
|
|
[-1,-1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[-1,1,1],
|
|
|
|
[-1,1,1],
|
|
|
|
[-1,-1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[1,-1,1],
|
|
|
|
[-1,1,1],
|
|
|
|
[-1,1,-1],
|
|
|
|
[1,1,1],
|
|
|
|
[1,1,-1],
|
|
|
|
[-1,1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[1,1,-1],
|
|
|
|
[1,-1,1],
|
|
|
|
[1,-1,1],
|
|
|
|
[1,1,-1],
|
|
|
|
[1,1,1],
|
|
|
|
[-1,1,1],
|
|
|
|
[1,1,-1],
|
|
|
|
[1,-1,1],
|
|
|
|
[-1,1,1],
|
|
|
|
[1,1,1],
|
|
|
|
],
|
|
|
|
'hex': [ # these are dummy numbers and are recalculated based on the above hex real slip systems.
|
|
|
|
[-1,1,1],
|
|
|
|
[1,-1,1],
|
|
|
|
[-1,-1,1],
|
|
|
|
[-1,1,1],
|
|
|
|
[-1,-1,1],
|
|
|
|
[1,-1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[-1,-1,1],
|
|
|
|
[1,-1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[-1,1,1],
|
|
|
|
[1,1,-1],
|
|
|
|
[1,1,-1],
|
|
|
|
[1,1,-1],
|
|
|
|
[1,-1,-1],
|
|
|
|
[1,-1,-1],
|
|
|
|
[1,-1,-1],
|
|
|
|
[1,-1,1],
|
|
|
|
[1,-1,1],
|
|
|
|
[1,-1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[1,1,1],
|
|
|
|
[1,1,1],
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
def applyEulers(phi1,Phi,phi2,x):
|
|
|
|
""" transform x given in crystal coordinates to xbar returned in lab coordinates for Euler angles phi1,Phi,phi2 """
|
|
|
|
|
2014-08-05 01:37:20 +05:30
|
|
|
eulerRot = [[ math.cos(phi1)*math.cos(phi2) - math.cos(Phi)*math.sin(phi1)*math.sin(phi2),
|
|
|
|
-math.cos(phi1)*math.sin(phi2) - math.cos(Phi)*math.cos(phi2)*math.sin(phi1),
|
|
|
|
math.sin(Phi)*math.sin(phi1)
|
|
|
|
],
|
|
|
|
[ math.cos(phi2)*math.sin(phi1) + math.cos(Phi)*math.cos(phi1)*math.sin(phi2),
|
|
|
|
math.cos(Phi)*math.cos(phi1)*math.cos(phi2) - math.sin(phi1)*math.sin(phi2),
|
|
|
|
-math.sin(Phi)*math.cos(phi1)
|
|
|
|
],
|
|
|
|
[ math.sin(Phi)*math.sin(phi2),
|
|
|
|
math.sin(Phi)*math.cos(phi2),
|
|
|
|
math.cos(Phi)
|
|
|
|
]]
|
2013-06-04 18:26:57 +05:30
|
|
|
|
|
|
|
xbar = [0,0,0]
|
|
|
|
if len(x) == 3:
|
|
|
|
for i in range(3):
|
|
|
|
xbar[i] = sum([eulerRot[i][j]*x[j] for j in range(3)])
|
|
|
|
return xbar
|
|
|
|
|
|
|
|
def normalize(x):
|
|
|
|
|
|
|
|
norm = math.sqrt(sum([x[i]*x[i] for i in range(len(x))]))
|
|
|
|
|
|
|
|
return [x[i]/norm for i in range(len(x))]
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
2014-08-05 01:37:20 +05:30
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
2013-06-04 18:26:57 +05:30
|
|
|
Add columns listing Schmid factors (and optional trace vector of selected system) for given Euler angles.
|
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2015-05-10 03:02:23 +05:30
|
|
|
parser.add_option('-l','--lattice', dest='lattice', type='choice', choices=('fcc','bcc','hex'), metavar='string',
|
|
|
|
help="type of lattice structure [%default] {fcc,bcc',hex}")
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('--direction', dest='forcedirection', type='int', nargs=3, metavar='int int int',
|
2015-05-22 10:27:05 +05:30
|
|
|
help='force direction in lab coordinates %default')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-n','--normal', dest='stressnormal', type='int', nargs=3, metavar='int int int',
|
2015-05-22 10:27:05 +05:30
|
|
|
help='stress plane normal in lab coordinates ')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('--trace', dest='traceplane', type='int', nargs=3, metavar='int int int',
|
2015-05-22 10:27:05 +05:30
|
|
|
help='normal (in lab coordinates) of plane on which the plane trace of the Schmid factor(s) is reported')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('--covera', dest='CoverA', type='float', metavar='float',
|
2015-05-22 10:27:05 +05:30
|
|
|
help='C over A ratio for hexagonal systems')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-r','--rank', dest='rank', type='int', nargs=3, metavar='int int int',
|
2015-05-22 10:27:05 +05:30
|
|
|
help="report trace of r'th highest Schmid factor [%default]")
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-e', '--eulers', dest='eulers', metavar='string',
|
2015-05-22 10:27:05 +05:30
|
|
|
help='Euler angles label')
|
2014-08-05 01:37:20 +05:30
|
|
|
parser.add_option('-d', '--degrees', dest='degrees', action='store_true',
|
2015-05-22 10:27:05 +05:30
|
|
|
help='Euler angles are given in degrees [%default]')
|
2013-06-04 18:26:57 +05:30
|
|
|
parser.set_defaults(lattice = 'fcc')
|
2015-05-22 10:27:05 +05:30
|
|
|
parser.set_defaults(forcedirection = [0, 0, 1])
|
2013-06-04 18:26:57 +05:30
|
|
|
parser.set_defaults(stressnormal = None)
|
|
|
|
parser.set_defaults(traceplane = None)
|
|
|
|
parser.set_defaults(rank = 0)
|
2015-05-22 10:27:05 +05:30
|
|
|
parser.set_defaults(CoverA = 1.587)
|
2014-08-05 01:37:20 +05:30
|
|
|
parser.set_defaults(eulers = 'eulerangles')
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2014-08-05 01:37:20 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
2013-06-04 18:26:57 +05:30
|
|
|
|
|
|
|
options.forcedirection = normalize(options.forcedirection)
|
|
|
|
if options.stressnormal:
|
|
|
|
if abs(sum([options.forcedirection[i] * options.stressnormal[i] for i in range(3)])) < 1e-3:
|
|
|
|
options.stressnormal = normalize(options.stressnormal)
|
|
|
|
else:
|
|
|
|
parser.error('stress plane normal not orthogonal to force direction')
|
|
|
|
else:
|
|
|
|
options.stressnormal = options.forcedirection
|
|
|
|
if options.traceplane:
|
|
|
|
options.traceplane = normalize(options.traceplane)
|
|
|
|
options.rank = min(options.rank,Nslipsystems[options.lattice])
|
|
|
|
|
2014-08-05 01:37:20 +05:30
|
|
|
datainfo = { # list of requested labels per datatype
|
|
|
|
'vector': {'len':3,
|
|
|
|
'label':[]},
|
|
|
|
}
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2014-08-05 01:37:20 +05:30
|
|
|
datainfo['vector']['label'] += [options.eulers]
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2014-08-05 01:37:20 +05:30
|
|
|
toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale degrees to radians
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2014-08-05 01:37:20 +05:30
|
|
|
if options.lattice=='hex': # Convert 4 Miller indices notation of hex to orthogonal 3 Miller indices notation
|
2013-06-04 18:26:57 +05:30
|
|
|
for i in range(Nslipsystems[options.lattice]):
|
|
|
|
slipnormal[options.lattice][i][0]=slipnormal_temp[i][0]
|
|
|
|
slipnormal[options.lattice][i][1]=(slipnormal_temp[i][0]+2.0*slipnormal_temp[i][1])/math.sqrt(3.0)
|
2014-08-05 01:37:20 +05:30
|
|
|
slipnormal[options.lattice][i][2]=slipnormal_temp[i][3]/options.CoverA
|
|
|
|
slipdirection[options.lattice][i][0]=slipdirection_temp[i][0]*1.5 # direction [uvtw]->[3u/2 (u+2v)*sqrt(3)/2 w*(c/a)] ,
|
2013-06-04 18:26:57 +05:30
|
|
|
slipdirection[options.lattice][i][1]=(slipdirection_temp[i][0]+2.0*slipdirection_temp[i][1])*(0.5*math.sqrt(3.0))
|
2014-08-05 01:37:20 +05:30
|
|
|
slipdirection[options.lattice][i][2]=slipdirection_temp[i][3]*options.CoverA
|
2013-06-04 18:26:57 +05:30
|
|
|
|
|
|
|
for i in range(Nslipsystems[options.lattice]):
|
|
|
|
slipnormal[options.lattice][i]=normalize(slipnormal[options.lattice][i])
|
|
|
|
slipdirection[options.lattice][i]=normalize(slipdirection[options.lattice][i])
|
|
|
|
|
2015-08-31 16:30:45 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2015-08-31 16:30:45 +05:30
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
|
|
|
for name in filenames:
|
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(name = name,buffered = False)
|
|
|
|
except:
|
|
|
|
continue
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2014-08-05 01:37:20 +05:30
|
|
|
|
|
|
|
table.head_read() # read ASCII header info
|
2014-08-06 18:57:09 +05:30
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
key = '1_%s'%datainfo['vector']['label'][0]
|
|
|
|
if key not in table.labels:
|
|
|
|
file['croak'].write('column %s not found...\n'%key)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
column = table.labels.index(key) # remember columns of requested data
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
table.labels_append(['%i_S(%i_%i_%i)[%i_%i_%i]'%(i+1,
|
2014-08-05 01:37:20 +05:30
|
|
|
slipnormal[options.lattice][i][0],
|
|
|
|
slipnormal[options.lattice][i][1],
|
|
|
|
slipnormal[options.lattice][i][2],
|
|
|
|
slipdirection[options.lattice][i][0],
|
|
|
|
slipdirection[options.lattice][i][1],
|
|
|
|
slipdirection[options.lattice][i][2],
|
|
|
|
) for i in range(Nslipsystems[options.lattice])])
|
2013-06-04 18:26:57 +05:30
|
|
|
|
|
|
|
if options.traceplane:
|
2014-08-05 01:37:20 +05:30
|
|
|
if options.rank > 0:
|
|
|
|
table.labels_append('trace_x trace_y trace_z system')
|
|
|
|
else:
|
|
|
|
table.labels_append(['(%i)tx\tty\ttz'%(i+1) for i in range(Nslipsystems[options.lattice])])
|
|
|
|
table.head_write()
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
2014-08-05 01:37:20 +05:30
|
|
|
outputAlive = True
|
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
|
|
|
[phi1,Phi,phi2] = Eulers=toRadians*np.array(map(\
|
2014-08-07 00:36:33 +05:30
|
|
|
float,table.data[column:column+datainfo['vector']['len']]))
|
2014-08-05 01:37:20 +05:30
|
|
|
S = [ sum( [applyEulers(phi1,Phi,phi2,normalize( \
|
|
|
|
slipnormal[options.lattice][slipsystem]))[i]*options.stressnormal[i] for i in range(3)] ) * \
|
|
|
|
sum( [applyEulers(phi1,Phi,phi2,normalize( \
|
|
|
|
slipdirection[options.lattice][slipsystem]))[i]*options.forcedirection[i] for i in range(3)] ) \
|
|
|
|
for slipsystem in range(Nslipsystems[options.lattice]) ]
|
|
|
|
table.data_append(S)
|
|
|
|
if options.traceplane:
|
2015-08-31 16:30:45 +05:30
|
|
|
trace = [np.cross(options.traceplane,applyEulers(phi1,Phi,phi2,normalize(slipnormal[options.lattice][slipsystem]))) \
|
2014-08-05 01:37:20 +05:30
|
|
|
for slipsystem in range(Nslipsystems[options.lattice]) ]
|
|
|
|
if options.rank == 0:
|
|
|
|
table.data_append('\t'.join(map(lambda x:'%f\t%f\t%f'%(x[0],x[1],x[2]),trace)))
|
|
|
|
elif options.rank > 0:
|
|
|
|
SabsSorted = sorted([(abs(S[i]),i) for i in range(len(S))])
|
|
|
|
table.data_append('\t'.join(map(str,trace[SabsSorted[-options.rank][1]])) + '\t%i'%(1+SabsSorted[-options.rank][1]))
|
|
|
|
outputAlive = table.data_write() # output processed line
|
|
|
|
|
2015-08-31 16:30:45 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2015-08-31 16:30:45 +05:30
|
|
|
table.close() # close input ASCII table (works for stdin)
|