2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2020-05-21 20:46:27 +05:30
|
|
|
from io import StringIO
|
2013-06-04 18:26:57 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-08-05 01:37:20 +05:30
|
|
|
import damask
|
2013-06-04 18:26:57 +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])
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2016-03-23 06:22:02 +05:30
|
|
|
slipSystems = {
|
|
|
|
'fcc':
|
|
|
|
np.array([
|
2020-05-21 19:12:05 +05:30
|
|
|
[+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],
|
|
|
|
],'d'),
|
2016-03-23 06:22:02 +05:30
|
|
|
'bcc':
|
|
|
|
np.array([
|
2020-05-21 19:12:05 +05:30
|
|
|
[+1,-1,+1 , +0,+1,+1],
|
|
|
|
[-1,-1,+1 , +0,+1,+1],
|
|
|
|
[+1,+1,+1 , +0,-1,+1],
|
|
|
|
[-1,+1,+1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|
[-2,+1,+1,+0 , +0,+1,-1,+1],
|
|
|
|
[-1,-1,+2,+0 , -1,+1,+0,+1],
|
|
|
|
[+1,-2,+1,+0 , -1,+0,+1,+1],
|
|
|
|
[+2,-1,-1,+0 , +0,-1,+1,+1],
|
|
|
|
[+1,+1,-2,+0 , +1,-1,+0,+1],
|
|
|
|
[-2,+1,+1,+3 , +1,+0,-1,+1],
|
|
|
|
[-1,-1,+2,+3 , +1,+0,-1,+1],
|
|
|
|
[-1,-1,+2,+3 , +0,+1,-1,+1],
|
|
|
|
[+1,-2,+1,+3 , +0,+1,-1,+1],
|
|
|
|
[+1,-2,+1,+3 , -1,+1,+0,+1],
|
|
|
|
[+2,-1,-1,+3 , -1,+1,+0,+1],
|
|
|
|
[+2,-1,-1,+3 , -1,+0,+1,+1],
|
|
|
|
[+1,+1,-2,+3 , -1,+0,+1,+1],
|
|
|
|
[+1,+1,-2,+3 , +0,-1,+1,+1],
|
|
|
|
[-1,+2,-1,+3 , +0,-1,+1,+1],
|
|
|
|
[-1,+2,-1,+3 , +1,-1,+0,+1],
|
|
|
|
[-2,+1,+1,+3 , +1,-1,+0,+1],
|
|
|
|
[-1,-1,+2,+3 , +1,+1,-2,+2],
|
|
|
|
[+1,-2,+1,+3 , -1,+2,-1,+2],
|
|
|
|
[+2,-1,-1,+3 , -2,+1,+1,+2],
|
|
|
|
[+1,+1,-2,+3 , -1,-1,+2,+2],
|
|
|
|
[-1,+2,-1,+3 , +1,-2,+1,+2],
|
|
|
|
[-2,+1,+1,+3 , +2,-1,-1,+2],
|
|
|
|
],'d'),
|
2016-03-23 06:22:02 +05:30
|
|
|
}
|
2013-06-04 18:26:57 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2019-02-16 22:55:41 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(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
|
|
|
|
2020-05-21 20:46:27 +05:30
|
|
|
lattice_choices = list(slipSystems.keys())
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('-l',
|
|
|
|
'--lattice',
|
2020-05-21 20:46:27 +05:30
|
|
|
dest = 'lattice', type = 'choice', choices = lattice_choices, metavar='string',
|
|
|
|
help = 'type of lattice structure [%default] {}'.format(lattice_choices))
|
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',
|
2019-02-16 19:23:56 +05:30
|
|
|
help = 'C over A ratio for hexagonal systems [%default]')
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('-f',
|
|
|
|
'--force',
|
2016-03-23 06:22:02 +05:30
|
|
|
dest = 'force',
|
|
|
|
type = 'float', nargs = 3, metavar = 'float float float',
|
|
|
|
help = 'force direction in lab frame [%default]')
|
2018-12-10 13:57:39 +05:30
|
|
|
parser.add_option('-n',
|
|
|
|
'--normal',
|
2016-03-23 06:22:02 +05:30
|
|
|
dest = 'normal',
|
|
|
|
type = 'float', nargs = 3, metavar = 'float float float',
|
2018-12-10 13:57:39 +05:30
|
|
|
help = 'stress plane normal in lab frame, per default perpendicular to the force')
|
|
|
|
parser.add_option('-o',
|
|
|
|
'--orientation',
|
2016-03-23 06:22:02 +05:30
|
|
|
dest = 'quaternion',
|
2018-12-09 15:23:53 +05:30
|
|
|
metavar = 'string',
|
2018-12-10 13:57:39 +05:30
|
|
|
help = 'label of crystal orientation given as unit quaternion [%default]')
|
2016-03-23 06:22:02 +05:30
|
|
|
|
2016-03-23 21:32:51 +05:30
|
|
|
parser.set_defaults(force = (0.0,0.0,1.0),
|
2018-12-10 13:57:39 +05:30
|
|
|
quaternion='orientation',
|
2016-03-23 06:22:02 +05:30
|
|
|
normal = None,
|
2020-05-21 20:46:27 +05:30
|
|
|
lattice = lattice_choices[0],
|
2019-06-14 16:33:30 +05:30
|
|
|
CoverA = np.sqrt(8./3.),
|
2016-03-23 06:22:02 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
2020-05-21 20:46:27 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2016-03-23 06:22:02 +05:30
|
|
|
|
2020-05-21 20:46:27 +05:30
|
|
|
force = np.array(options.force)/np.linalg.norm(options.force)
|
2016-03-23 06:22:02 +05:30
|
|
|
|
2018-12-10 13:57:39 +05:30
|
|
|
if options.normal is not None:
|
2020-05-21 20:46:27 +05:30
|
|
|
normal = np.array(options.normal)/np.linalg.norm(options.ormal)
|
|
|
|
if abs(np.dot(force,normal)) > 1e-3:
|
|
|
|
parser.error('stress plane normal not orthogonal to force direction')
|
2013-06-04 18:26:57 +05:30
|
|
|
else:
|
2020-05-21 20:46:27 +05:30
|
|
|
normal = force
|
|
|
|
|
|
|
|
|
|
|
|
if options.lattice in ['bcc','fcc']:
|
|
|
|
slip_direction = slipSystems[options.lattice][:,:3]
|
|
|
|
slip_normal = slipSystems[options.lattice][:,3:]
|
|
|
|
elif options.lattice == 'hex':
|
|
|
|
slip_direction = np.zeros((len(slipSystems['hex']),3),'d')
|
|
|
|
slip_normal = np.zeros_like(slip_direction)
|
|
|
|
# convert 4 Miller index notation of hex to orthogonal 3 Miller index notation
|
|
|
|
for i in range(len(slip_direction)):
|
|
|
|
slip_direction[i] = np.array([slipSystems['hex'][i,0]*1.5,
|
|
|
|
(slipSystems['hex'][i,0] + 2.*slipSystems['hex'][i,1])*0.5*np.sqrt(3),
|
|
|
|
slipSystems['hex'][i,3]*options.CoverA,
|
|
|
|
])
|
|
|
|
slip_normal[i] = np.array([slipSystems['hex'][i,4],
|
|
|
|
(slipSystems['hex'][i,4] + 2.*slipSystems['hex'][i,5])/np.sqrt(3),
|
|
|
|
slipSystems['hex'][i,7]/options.CoverA,
|
|
|
|
])
|
|
|
|
|
|
|
|
slip_direction /= np.linalg.norm(slip_direction,axis=1,keepdims=True)
|
|
|
|
slip_normal /= np.linalg.norm(slip_normal, axis=1,keepdims=True)
|
|
|
|
|
|
|
|
labels = ['S[{direction[0]:.1g}_{direction[1]:.1g}_{direction[2]:.1g}]'
|
|
|
|
'({normal[0]:.1g}_{normal[1]:.1g}_{normal[2]:.1g})'\
|
|
|
|
.format(normal = theNormal, direction = theDirection,
|
|
|
|
) for theNormal,theDirection in zip(slip_normal,slip_direction)]
|
2015-08-31 16:30:45 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2020-05-21 20:46:27 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2013-06-04 18:26:57 +05:30
|
|
|
|
2020-05-21 20:46:27 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2016-03-23 06:22:02 +05:30
|
|
|
|
2020-05-21 20:46:27 +05:30
|
|
|
o = damask.Rotation.from_quaternion(table.get(options.quaternion))
|
2018-11-22 23:15:01 +05:30
|
|
|
|
2020-05-21 20:46:27 +05:30
|
|
|
force = np.broadcast_to(force, o.shape+(3,))
|
|
|
|
normal = np.broadcast_to(normal,o.shape+(3,))
|
|
|
|
slip_direction = np.broadcast_to(slip_direction,o.shape+slip_direction.shape)
|
|
|
|
slip_normal = np.broadcast_to(slip_normal, o.shape+slip_normal.shape)
|
|
|
|
S = np.abs(np.einsum('ijk,ik->ij',slip_direction,(o@force))*
|
|
|
|
np.einsum('ijk,ik->ij',slip_normal, (o@normal)))
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2020-05-21 20:46:27 +05:30
|
|
|
for i,label in enumerate(labels):
|
2020-09-14 10:34:01 +05:30
|
|
|
table = table.add(label,S[:,i],scriptID+' '+' '.join(sys.argv[1:]))
|
2014-08-05 01:37:20 +05:30
|
|
|
|
2020-09-03 20:49:19 +05:30
|
|
|
table.to_file(sys.stdout if name is None else name)
|