2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- 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
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
slipSystems = {
|
|
|
|
'fcc':
|
|
|
|
np.array([
|
|
|
|
# Slip direction Plane normal
|
|
|
|
[ 0, 1,-1, 1, 1, 1, ],
|
|
|
|
[-1, 0, 1, 1, 1, 1, ],
|
|
|
|
[ 1,-1, 0, 1, 1, 1, ],
|
|
|
|
[ 0,-1,-1, -1,-1, 1, ],
|
|
|
|
[ 1, 0, 1, -1,-1, 1, ],
|
|
|
|
[-1, 1, 0, -1,-1, 1, ],
|
|
|
|
[ 0,-1, 1, 1,-1,-1, ],
|
|
|
|
[-1, 0,-1, 1,-1,-1, ],
|
|
|
|
[ 1, 1, 0, 1,-1,-1, ],
|
|
|
|
[ 0, 1, 1, -1, 1,-1, ],
|
|
|
|
[ 1, 0,-1, -1, 1,-1, ],
|
|
|
|
[-1,-1, 0, -1, 1,-1, ],
|
|
|
|
],'f'),
|
|
|
|
'bcc':
|
|
|
|
np.array([
|
|
|
|
# Slip system <111>{110}
|
|
|
|
[ 1,-1, 1, 0, 1, 1, ],
|
|
|
|
[-1,-1, 1, 0, 1, 1, ],
|
|
|
|
[ 1, 1, 1, 0,-1, 1, ],
|
|
|
|
[-1, 1, 1, 0,-1, 1, ],
|
|
|
|
[-1, 1, 1, 1, 0, 1, ],
|
|
|
|
[-1,-1, 1, 1, 0, 1, ],
|
|
|
|
[ 1, 1, 1, -1, 0, 1, ],
|
|
|
|
[ 1,-1, 1, -1, 0, 1, ],
|
|
|
|
[-1, 1, 1, 1, 1, 0, ],
|
|
|
|
[-1, 1,-1, 1, 1, 0, ],
|
|
|
|
[ 1, 1, 1, -1, 1, 0, ],
|
|
|
|
[ 1, 1,-1, -1, 1, 0, ],
|
|
|
|
# Slip system <111>{112}
|
|
|
|
[-1, 1, 1, 2, 1, 1, ],
|
|
|
|
[ 1, 1, 1, -2, 1, 1, ],
|
|
|
|
[ 1, 1,-1, 2,-1, 1, ],
|
|
|
|
[ 1,-1, 1, 2, 1,-1, ],
|
|
|
|
[ 1,-1, 1, 1, 2, 1, ],
|
|
|
|
[ 1, 1,-1, -1, 2, 1, ],
|
|
|
|
[ 1, 1, 1, 1,-2, 1, ],
|
|
|
|
[-1, 1, 1, 1, 2,-1, ],
|
|
|
|
[ 1, 1,-1, 1, 1, 2, ],
|
|
|
|
[ 1,-1, 1, -1, 1, 2, ],
|
|
|
|
[-1, 1, 1, 1,-1, 2, ],
|
|
|
|
[ 1, 1, 1, 1, 1,-2, ],
|
|
|
|
],'f'),
|
|
|
|
'hex':
|
|
|
|
np.array([
|
|
|
|
# Basal systems <11.0>{00.1} (independent of c/a-ratio, Bravais notation (4 coordinate base))
|
|
|
|
[ 2, -1, -1, 0, 0, 0, 0, 1, ],
|
|
|
|
[-1, 2, -1, 0, 0, 0, 0, 1, ],
|
|
|
|
[-1, -1, 2, 0, 0, 0, 0, 1, ],
|
|
|
|
# 1st type prismatic systems <11.0>{10.0} (independent of c/a-ratio)
|
|
|
|
[ 2, -1, -1, 0, 0, 1, -1, 0, ],
|
|
|
|
[-1, 2, -1, 0, -1, 0, 1, 0, ],
|
|
|
|
[-1, -1, 2, 0, 1, -1, 0, 0, ],
|
|
|
|
# 2nd type prismatic systems <10.0>{11.0} -- a slip; plane normals independent of c/a-ratio
|
|
|
|
[ 0, 1, -1, 0, 2, -1, -1, 0, ],
|
|
|
|
[-1, 0, 1, 0, -1, 2, -1, 0, ],
|
|
|
|
[ 1, -1, 0, 0, -1, -1, 2, 0, ],
|
|
|
|
# 1st type 1st order pyramidal systems <11.0>{-11.1} -- plane normals depend on the c/a-ratio
|
|
|
|
[ 2, -1, -1, 0, 0, 1, -1, 1, ],
|
|
|
|
[-1, 2, -1, 0, -1, 0, 1, 1, ],
|
|
|
|
[-1, -1, 2, 0, 1, -1, 0, 1, ],
|
|
|
|
[ 1, 1, -2, 0, -1, 1, 0, 1, ],
|
|
|
|
[-2, 1, 1, 0, 0, -1, 1, 1, ],
|
|
|
|
[ 1, -2, 1, 0, 1, 0, -1, 1, ],
|
|
|
|
# pyramidal system: c+a slip <11.3>{-10.1} -- plane normals depend on the c/a-ratio
|
|
|
|
[ 2, -1, -1, 3, -1, 1, 0, 1, ],
|
|
|
|
[ 1, -2, 1, 3, -1, 1, 0, 1, ],
|
|
|
|
[-1, -1, 2, 3, 1, 0, -1, 1, ],
|
|
|
|
[-2, 1, 1, 3, 1, 0, -1, 1, ],
|
|
|
|
[-1, 2, -1, 3, 0, -1, 1, 1, ],
|
|
|
|
[ 1, 1, -2, 3, 0, -1, 1, 1, ],
|
|
|
|
[-2, 1, 1, 3, 1, -1, 0, 1, ],
|
|
|
|
[-1, 2, -1, 3, 1, -1, 0, 1, ],
|
|
|
|
[ 1, 1, -2, 3, -1, 0, 1, 1, ],
|
|
|
|
[ 2, -1, -1, 3, -1, 0, 1, 1, ],
|
|
|
|
[ 1, -2, 1, 3, 0, 1, -1, 1, ],
|
|
|
|
[-1, -1, 2, 3, 0, 1, -1, 1, ],
|
|
|
|
# pyramidal system: c+a slip <11.3>{-1-1.2} -- as for hexagonal ice (Castelnau et al. 1996, similar to twin system found below)
|
|
|
|
[ 2, -1, -1, 3, -2, 1, 1, 2, ], # sorted according to similar twin system
|
|
|
|
[-1, 2, -1, 3, 1, -2, 1, 2, ], # <11.3>{-1-1.2} shear = 2((c/a)^2-2)/(3 c/a)
|
|
|
|
[-1, -1, 2, 3, 1, 1, -2, 2, ],
|
|
|
|
[-2, 1, 1, 3, 2, -1, -1, 2, ],
|
|
|
|
[ 1, -2, 1, 3, -1, 2, -1, 2, ],
|
|
|
|
[ 1, 1, -2, 3, -1, -1, 2, 2, ],
|
|
|
|
],'f'),
|
|
|
|
}
|
2013-06-04 18:26:57 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
2014-08-05 01:37:20 +05:30
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
2016-03-23 21:32:51 +05:30
|
|
|
Add columns listing Schmid factors (and optional trace vector of selected system) for given Euler angles.
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
latticeChoices = ('fcc','bcc','hex')
|
2016-03-02 01:44:06 +05:30
|
|
|
parser.add_option('-l','--lattice',
|
2016-03-23 06:22:02 +05:30
|
|
|
dest = 'lattice', type = 'choice', choices = latticeChoices, metavar='string',
|
|
|
|
help = 'type of lattice structure [%default] {}'.format(latticeChoices))
|
2016-03-02 01:44:06 +05:30
|
|
|
parser.add_option('--covera',
|
2016-03-23 06:22:02 +05:30
|
|
|
dest = 'CoverA', type = 'float', metavar = 'float',
|
|
|
|
help = 'C over A ratio for hexagonal systems')
|
|
|
|
parser.add_option('-f', '--force',
|
|
|
|
dest = 'force',
|
|
|
|
type = 'float', nargs = 3, metavar = 'float float float',
|
|
|
|
help = 'force direction in lab frame [%default]')
|
|
|
|
parser.add_option('-n', '--normal',
|
|
|
|
dest = 'normal',
|
|
|
|
type = 'float', nargs = 3, metavar = 'float float float',
|
|
|
|
help = 'stress plane normal in lab frame [%default]')
|
2016-03-02 01:44:06 +05:30
|
|
|
parser.add_option('-e', '--eulers',
|
2016-03-23 06:22:02 +05:30
|
|
|
dest = 'eulers',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'Euler angles label')
|
2016-03-02 01:44:06 +05:30
|
|
|
parser.add_option('-d', '--degrees',
|
2016-03-23 06:22:02 +05:30
|
|
|
dest = 'degrees',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'Euler angles are given in degrees [%default]')
|
|
|
|
parser.add_option('-m', '--matrix',
|
|
|
|
dest = 'matrix',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'orientation matrix label')
|
|
|
|
parser.add_option('-a',
|
|
|
|
dest = 'a',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'crystal frame a vector label')
|
|
|
|
parser.add_option('-b',
|
|
|
|
dest = 'b',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'crystal frame b vector label')
|
|
|
|
parser.add_option('-c',
|
|
|
|
dest = 'c',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'crystal frame c vector label')
|
|
|
|
parser.add_option('-q', '--quaternion',
|
|
|
|
dest = 'quaternion',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'quaternion label')
|
|
|
|
|
2016-03-23 21:32:51 +05:30
|
|
|
parser.set_defaults(force = (0.0,0.0,1.0),
|
2016-03-23 06:22:02 +05:30
|
|
|
normal = None,
|
|
|
|
lattice = latticeChoices[0],
|
|
|
|
CoverA = math.sqrt(8./3.),
|
|
|
|
degrees = False,
|
|
|
|
)
|
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale degrees to radians
|
|
|
|
|
|
|
|
force = np.array(options.force)
|
|
|
|
force /= np.linalg.norm(force)
|
|
|
|
|
|
|
|
if options.normal:
|
|
|
|
normal = np.array(options.normal)
|
|
|
|
normal /= np.linalg.norm(normal)
|
|
|
|
if abs(np.dot(force,normal)) > 1e-3:
|
2013-06-04 18:26:57 +05:30
|
|
|
parser.error('stress plane normal not orthogonal to force direction')
|
|
|
|
else:
|
2016-03-23 06:22:02 +05:30
|
|
|
normal = force
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
input = [options.eulers is not None,
|
|
|
|
options.a is not None and \
|
|
|
|
options.b is not None and \
|
|
|
|
options.c is not None,
|
|
|
|
options.matrix is not None,
|
|
|
|
options.quaternion is not None,
|
|
|
|
]
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
if np.sum(input) != 1: parser.error('needs exactly one input format.')
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
(label,dim,inputtype) = [(options.eulers,3,'eulers'),
|
|
|
|
([options.a,options.b,options.c],[3,3,3],'frame'),
|
|
|
|
(options.matrix,9,'matrix'),
|
|
|
|
(options.quaternion,4,'quaternion'),
|
|
|
|
][np.where(input)[0][0]] # select input label that was requested
|
|
|
|
|
2018-11-22 23:15:01 +05:30
|
|
|
slip_direction = np.zeros((len(slipSystems[options.lattice]),3),'f')
|
|
|
|
slip_normal = np.zeros_like(slip_direction)
|
2016-03-23 06:22:02 +05:30
|
|
|
|
|
|
|
|
|
|
|
if options.lattice in latticeChoices[:2]:
|
2018-11-22 23:15:01 +05:30
|
|
|
slip_direction = slipSystems[options.lattice][:,:3]
|
|
|
|
slip_normal = slipSystems[options.lattice][:,3:]
|
2016-03-23 06:22:02 +05:30
|
|
|
elif options.lattice == latticeChoices[2]:
|
|
|
|
# convert 4 Miller index notation of hex to orthogonal 3 Miller index notation
|
2018-11-22 23:15:01 +05:30
|
|
|
for i in range(len(slip_direction)):
|
|
|
|
slip_direction[i] = np.array([slipSystems['hex'][i,0]*1.5,
|
2016-03-23 06:22:02 +05:30
|
|
|
(slipSystems['hex'][i,0] + 2.*slipSystems['hex'][i,1])*0.5*np.sqrt(3),
|
|
|
|
slipSystems['hex'][i,3]*options.CoverA,
|
|
|
|
])
|
2018-11-22 23:15:01 +05:30
|
|
|
slip_normal[i] = np.array([slipSystems['hex'][i,4],
|
2016-03-23 06:22:02 +05:30
|
|
|
(slipSystems['hex'][i,4] + 2.*slipSystems['hex'][i,5])/np.sqrt(3),
|
|
|
|
slipSystems['hex'][i,7]/options.CoverA,
|
|
|
|
])
|
|
|
|
|
2018-11-22 23:15:01 +05:30
|
|
|
slip_direction /= np.tile(np.linalg.norm(slip_direction,axis=1),(3,1)).T
|
|
|
|
slip_normal /= np.tile(np.linalg.norm(slip_normal ,axis=1),(3,1)).T
|
2016-03-23 06:22:02 +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:
|
2016-03-23 06:22:02 +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)
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
|
|
|
|
|
|
|
if not np.all(table.label_dimension(label) == dim):
|
|
|
|
damask.util.croak('input {} does not have dimension {}.'.format(label,dim))
|
|
|
|
table.close(dismiss = True) # close ASCIItable and remove empty file
|
2014-08-07 00:36:33 +05:30
|
|
|
continue
|
2016-03-23 06:22:02 +05:30
|
|
|
|
|
|
|
column = table.label_index(label)
|
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
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2016-04-11 16:54:43 +05:30
|
|
|
table.labels_append(['{id}_'
|
|
|
|
'S[{direction[0]:.1g}_{direction[1]:.1g}_{direction[2]:.1g}]'
|
|
|
|
'({normal[0]:.1g}_{normal[1]:.1g}_{normal[2]:.1g})'\
|
2016-03-23 06:22:02 +05:30
|
|
|
.format( id = i+1,
|
|
|
|
normal = theNormal,
|
|
|
|
direction = theDirection,
|
2018-11-22 23:15:01 +05:30
|
|
|
) for i,(theNormal,theDirection) in enumerate(zip(slip_normal,slip_direction))])
|
2014-08-05 01:37:20 +05:30
|
|
|
table.head_write()
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
2016-03-23 06:22:02 +05:30
|
|
|
|
2014-08-05 01:37:20 +05:30
|
|
|
outputAlive = True
|
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
2016-03-23 06:22:02 +05:30
|
|
|
if inputtype == 'eulers':
|
2018-07-19 20:23:48 +05:30
|
|
|
o = damask.Orientation(Eulers = np.array(list(map(float,table.data[column:column+3])))*toRadians,)
|
2016-03-23 06:22:02 +05:30
|
|
|
elif inputtype == 'matrix':
|
2018-07-19 20:23:48 +05:30
|
|
|
o = damask.Orientation(matrix = np.array(list(map(float,table.data[column:column+9]))).reshape(3,3).transpose(),)
|
2016-03-23 06:22:02 +05:30
|
|
|
elif inputtype == 'frame':
|
2018-07-19 20:23:48 +05:30
|
|
|
o = damask.Orientation(matrix = np.array(list(map(float,table.data[column[0]:column[0]+3] + \
|
|
|
|
table.data[column[1]:column[1]+3] + \
|
|
|
|
table.data[column[2]:column[2]+3]))).reshape(3,3),)
|
2016-03-23 06:22:02 +05:30
|
|
|
elif inputtype == 'quaternion':
|
2018-07-19 20:23:48 +05:30
|
|
|
o = damask.Orientation(quaternion = np.array(list(map(float,table.data[column:column+4]))),)
|
2016-03-23 06:22:02 +05:30
|
|
|
|
2018-11-22 23:15:01 +05:30
|
|
|
|
|
|
|
table.data_append( np.abs( np.sum(slip_direction * (o.quaternion * force) ,axis=1) \
|
|
|
|
* np.sum(slip_normal * (o.quaternion * normal),axis=1)))
|
2014-08-05 01:37:20 +05:30
|
|
|
outputAlive = table.data_write() # output processed line
|
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
table.close() # close ASCII tables
|