From bb5db3e79cdf1618fbb0cf9818bdf13ae71b7227 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 4 Aug 2021 16:06:28 +0200 Subject: [PATCH 1/2] structured according to family --- python/damask/_crystal.py | 331 +++++++++++++++++----------------- python/damask/_orientation.py | 4 +- 2 files changed, 170 insertions(+), 165 deletions(-) diff --git a/python/damask/_crystal.py b/python/damask/_crystal.py index 6caa51fec..7fc2e39b6 100644 --- a/python/damask/_crystal.py +++ b/python/damask/_crystal.py @@ -340,178 +340,183 @@ class Crystal(): """ _kinematics = { 'cF': { - 'slip' : np.array([ - [+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], - [+1,+1,+0, +1,-1,+0], - [+1,-1,+0, +1,+1,+0], - [+1,+0,+1, +1,+0,-1], - [+1,+0,-1, +1,+0,+1], - [+0,+1,+1, +0,+1,-1], - [+0,+1,-1, +0,+1,+1], - ],dtype=float), - 'twin' : np.array([ - [-2, 1, 1, 1, 1, 1], - [ 1,-2, 1, 1, 1, 1], - [ 1, 1,-2, 1, 1, 1], - [ 2,-1, 1, -1,-1, 1], - [-1, 2, 1, -1,-1, 1], - [-1,-1,-2, -1,-1, 1], - [-2,-1,-1, 1,-1,-1], - [ 1, 2,-1, 1,-1,-1], - [ 1,-1, 2, 1,-1,-1], - [ 2, 1,-1, -1, 1,-1], - [-1,-2,-1, -1, 1,-1], - [-1, 1, 2, -1, 1,-1], - ],dtype=float), + 'slip' :[np.array([ + [+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]]), + np.array([ + [+1,+1,+0, +1,-1,+0], + [+1,-1,+0, +1,+1,+0], + [+1,+0,+1, +1,+0,-1], + [+1,+0,-1, +1,+0,+1], + [+0,+1,+1, +0,+1,-1], + [+0,+1,-1, +0,+1,+1]])], + 'twin' :[np.array([ + [-2, 1, 1, 1, 1, 1], + [ 1,-2, 1, 1, 1, 1], + [ 1, 1,-2, 1, 1, 1], + [ 2,-1, 1, -1,-1, 1], + [-1, 2, 1, -1,-1, 1], + [-1,-1,-2, -1,-1, 1], + [-2,-1,-1, 1,-1,-1], + [ 1, 2,-1, 1,-1,-1], + [ 1,-1, 2, 1,-1,-1], + [ 2, 1,-1, -1, 1,-1], + [-1,-2,-1, -1, 1,-1], + [-1, 1, 2, -1, 1,-1]])] }, 'cI': { - 'slip' : np.array([ - [+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], - [-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], - [+1,+1,-1, +1,+2,+3], - [+1,-1,+1, -1,+2,+3], - [-1,+1,+1, +1,-2,+3], - [+1,+1,+1, +1,+2,-3], - [+1,-1,+1, +1,+3,+2], - [+1,+1,-1, -1,+3,+2], - [+1,+1,+1, +1,-3,+2], - [-1,+1,+1, +1,+3,-2], - [+1,+1,-1, +2,+1,+3], - [+1,-1,+1, -2,+1,+3], - [-1,+1,+1, +2,-1,+3], - [+1,+1,+1, +2,+1,-3], - [+1,-1,+1, +2,+3,+1], - [+1,+1,-1, -2,+3,+1], - [+1,+1,+1, +2,-3,+1], - [-1,+1,+1, +2,+3,-1], - [-1,+1,+1, +3,+1,+2], - [+1,+1,+1, -3,+1,+2], - [+1,+1,-1, +3,-1,+2], - [+1,-1,+1, +3,+1,-2], - [-1,+1,+1, +3,+2,+1], - [+1,+1,+1, -3,+2,+1], - [+1,+1,-1, +3,-2,+1], - [+1,-1,+1, +3,+2,-1], - ],dtype=float), - 'twin' : np.array([ - [-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], - ],dtype=float), + 'slip' :[np.array([ + [+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]]), + np.array([ + [-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]]), + np.array([ + [+1,+1,-1, +1,+2,+3], + [+1,-1,+1, -1,+2,+3], + [-1,+1,+1, +1,-2,+3], + [+1,+1,+1, +1,+2,-3], + [+1,-1,+1, +1,+3,+2], + [+1,+1,-1, -1,+3,+2], + [+1,+1,+1, +1,-3,+2], + [-1,+1,+1, +1,+3,-2], + [+1,+1,-1, +2,+1,+3], + [+1,-1,+1, -2,+1,+3], + [-1,+1,+1, +2,-1,+3], + [+1,+1,+1, +2,+1,-3], + [+1,-1,+1, +2,+3,+1], + [+1,+1,-1, -2,+3,+1], + [+1,+1,+1, +2,-3,+1], + [-1,+1,+1, +2,+3,-1], + [-1,+1,+1, +3,+1,+2], + [+1,+1,+1, -3,+1,+2], + [+1,+1,-1, +3,-1,+2], + [+1,-1,+1, +3,+1,-2], + [-1,+1,+1, +3,+2,+1], + [+1,+1,+1, -3,+2,+1], + [+1,+1,-1, +3,-2,+1], + [+1,-1,+1, +3,+2,-1]])], + 'twin' :[np.array([ + [-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]])] }, 'hP': { - 'slip' : np.array([ - [+2,-1,-1,+0, +0,+0,+0,+1], - [-1,+2,-1,+0, +0,+0,+0,+1], - [-1,-1,+2,+0, +0,+0,+0,+1], - [+2,-1,-1,+0, +0,+1,-1,+0], - [-1,+2,-1,+0, -1,+0,+1,+0], - [-1,-1,+2,+0, +1,-1,+0,+0], - [-1,+1,+0,+0, +1,+1,-2,+0], - [+0,-1,+1,+0, -2,+1,+1,+0], - [+1,+0,-1,+0, +1,-2,+1,+0], - [-1,+2,-1,+0, +1,+0,-1,+1], - [-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], - ],dtype=float), - 'twin' : np.array([ - [-1, 0, 1, 1, 1, 0,-1, 2], # shear = (3-(c/a)^2)/(sqrt(3) c/a) <-10.1>{10.2} - [ 0,-1, 1, 1, 0, 1,-1, 2], - [ 1,-1, 0, 1, -1, 1, 0, 2], - [ 1, 0,-1, 1, -1, 0, 1, 2], - [ 0, 1,-1, 1, 0,-1, 1, 2], - [-1, 1, 0, 1, 1,-1, 0, 2], - [-1,-1, 2, 6, 1, 1,-2, 1], # shear = 1/(c/a) <11.6>{-1-1.1} - [ 1,-2, 1, 6, -1, 2,-1, 1], - [ 2,-1,-1, 6, -2, 1, 1, 1], - [ 1, 1,-2, 6, -1,-1, 2, 1], - [-1, 2,-1, 6, 1,-2, 1, 1], - [-2, 1, 1, 6, 2,-1,-1, 1], - [ 1, 0,-1,-2, 1, 0,-1, 1], # shear = (4(c/a)^2-9)/(4 sqrt(3) c/a) <10.-2>{10.1} - [ 0, 1,-1,-2, 0, 1,-1, 1], - [-1, 1, 0,-2, -1, 1, 0, 1], - [-1, 0, 1,-2, -1, 0, 1, 1], - [ 0,-1, 1,-2, 0,-1, 1, 1], - [ 1,-1, 0,-2, 1,-1, 0, 1], - [ 1, 1,-2,-3, 1, 1,-2, 2], # shear = 2((c/a)^2-2)/(3 c/a) <11.-3>{11.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], - ],dtype=float), + 'slip' :[np.array([ + [+2,-1,-1,+0, +0,+0,+0,+1], + [-1,+2,-1,+0, +0,+0,+0,+1], + [-1,-1,+2,+0, +0,+0,+0,+1]]), + np.array([ + [+2,-1,-1,+0, +0,+1,-1,+0], + [-1,+2,-1,+0, -1,+0,+1,+0], + [-1,-1,+2,+0, +1,-1,+0,+0]]), + np.array([ + [-1,+1,+0,+0, +1,+1,-2,+0], + [+0,-1,+1,+0, -2,+1,+1,+0], + [+1,+0,-1,+0, +1,-2,+1,+0]]), + np.array([ + [-1,+2,-1,+0, +1,+0,-1,+1], + [-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]]), + np.array([ + [-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]]), + np.array([ + [-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]])], + 'twin' :[np.array([ + [-1, 0, 1, 1, 1, 0,-1, 2], # shear = (3-(c/a)^2)/(sqrt(3) c/a) <-10.1>{10.2} + [ 0,-1, 1, 1, 0, 1,-1, 2], + [ 1,-1, 0, 1, -1, 1, 0, 2], + [ 1, 0,-1, 1, -1, 0, 1, 2], + [ 0, 1,-1, 1, 0,-1, 1, 2], + [-1, 1, 0, 1, 1,-1, 0, 2]]), + np.array([ + [-1,-1, 2, 6, 1, 1,-2, 1], # shear = 1/(c/a) <11.6>{-1-1.1} + [ 1,-2, 1, 6, -1, 2,-1, 1], + [ 2,-1,-1, 6, -2, 1, 1, 1], + [ 1, 1,-2, 6, -1,-1, 2, 1], + [-1, 2,-1, 6, 1,-2, 1, 1], + [-2, 1, 1, 6, 2,-1,-1, 1]]), + np.array([ + [ 1, 0,-1,-2, 1, 0,-1, 1], # shear = (4(c/a)^2-9)/(4 sqrt(3) c/a) <10.-2>{10.1} + [ 0, 1,-1,-2, 0, 1,-1, 1], + [-1, 1, 0,-2, -1, 1, 0, 1], + [-1, 0, 1,-2, -1, 0, 1, 1], + [ 0,-1, 1,-2, 0,-1, 1, 1], + [ 1,-1, 0,-2, 1,-1, 0, 1]]), + np.array([ + [ 1, 1,-2,-3, 1, 1,-2, 2], # shear = 2((c/a)^2-2)/(3 c/a) <11.-3>{11.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]])] }, } master = _kinematics[self.lattice][mode] if self.lattice == 'hP': - return {'direction':util.Bravais_to_Miller(uvtw=master[:,0:4]), - 'plane': util.Bravais_to_Miller(hkil=master[:,4:8])} + return {'direction':[util.Bravais_to_Miller(uvtw=m[:,0:4]) for m in master], + 'plane': [util.Bravais_to_Miller(hkil=m[:,4:8]) for m in master]} else: - return {'direction':master[:,0:3], - 'plane': master[:,3:6]} + return {'direction':[m[:,0:3] for m in master], + 'plane': [m[:,3:6] for m in master]} def relation_operations(self,model): diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index 0c730ac06..80e5d3929 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -882,8 +882,8 @@ class Orientation(Rotation,Crystal): [ 0.000, 0.000, 0.000]]) """ - d = self.to_frame(uvw=self.kinematics(mode)['direction']) - p = self.to_frame(hkl=self.kinematics(mode)['plane']) + d = self.to_frame(uvw=np.vstack(self.kinematics(mode)['direction'])) + p = self.to_frame(hkl=np.vstack(self.kinematics(mode)['plane'])) P = np.einsum('...i,...j',d/np.linalg.norm(d,axis=1,keepdims=True), p/np.linalg.norm(p,axis=1,keepdims=True)) From b5be4c3fa51ef1a2bd5b521d62bbd2c23946b532 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 4 Aug 2021 17:45:25 +0200 Subject: [PATCH 2/2] compatible with material.yaml --- python/damask/_orientation.py | 23 ++++++++++++++++------- python/tests/test_Orientation.py | 7 +++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index 80e5d3929..749115566 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -854,14 +854,15 @@ class Orientation(Rotation,Crystal): @ np.broadcast_to(v,self.shape+v.shape) - def Schmid(self,mode): + def Schmid(self,*,N_slip=None,N_twin=None): u""" - Calculate Schmid matrix P = d ⨂ n in the lab frame for given lattice shear kinematics. + Calculate Schmid matrix P = d ⨂ n in the lab frame for selected deformation systems. Parameters ---------- - mode : {'slip', 'twin'} - Deformation mode. + N_slip|N_twin : iterable of int + Number of deformation systems per deformation system. + Use '*'. to select all. Returns ------- @@ -876,14 +877,22 @@ class Orientation(Rotation,Crystal): >>> import damask >>> import numpy as np >>> np.set_printoptions(3,suppress=True,floatmode='fixed') - >>> damask.Orientation.from_Eulers(phi=[0,45,0],degrees=True,lattice='cF').Schmid('slip')[0] + >>> O = damask.Orientation.from_Euler_angles(phi=[0,45,0],degrees=True,lattice='cF') + >>> O.Schmid(N_slip=[1]) array([[ 0.000, 0.000, 0.000], [ 0.577, -0.000, 0.816], [ 0.000, 0.000, 0.000]]) """ - d = self.to_frame(uvw=np.vstack(self.kinematics(mode)['direction'])) - p = self.to_frame(hkl=np.vstack(self.kinematics(mode)['plane'])) + if (N_slip is not None) ^ (N_twin is None): + raise KeyError('Specify either "N_slip" or "N_twin"') + + kinematics = self.kinematics('slip' if N_twin is None else 'twin') + active = N_slip if N_twin is None else N_twin + if active == '*': active = [len(a) for a in kinematics] + + d = self.to_frame(uvw=np.vstack([kinematics['direction'][i][:n] for i,n in enumerate(active)])) + p = self.to_frame(hkl=np.vstack([kinematics['plane'][i][:n] for i,n in enumerate(active)])) P = np.einsum('...i,...j',d/np.linalg.norm(d,axis=1,keepdims=True), p/np.linalg.norm(p,axis=1,keepdims=True)) diff --git a/python/tests/test_Orientation.py b/python/tests/test_Orientation.py index aa9897312..7d820b2bf 100644 --- a/python/tests/test_Orientation.py +++ b/python/tests/test_Orientation.py @@ -440,10 +440,10 @@ class TestOrientation: @pytest.mark.parametrize('lattice',['hP','cI','cF']) #tI not included yet def test_Schmid(self,update,ref_path,lattice): - L = Orientation(lattice=lattice) + O = Orientation(lattice=lattice) # noqa for mode in ['slip','twin']: reference = ref_path/f'{lattice}_{mode}.txt' - P = L.Schmid(mode) + P = O.Schmid(N_slip='*') if mode == 'slip' else O.Schmid(N_twin='*') if update: table = Table(P.reshape(-1,9),{'Schmid':(3,3,)}) table.save(reference) @@ -453,7 +453,6 @@ class TestOrientation: def test_Schmid_vectorize(self,lattice): O = Orientation.from_random(shape=4,lattice=lattice) # noqa for mode in ['slip','twin']: - P = O.Schmid(mode) - print(P.shape) + P = O.Schmid(N_slip='*') if mode == 'slip' else O.Schmid(N_twin='*') for i in range(4): assert np.allclose(Orientation(rotation=O[i],lattice=lattice).Schmid(mode),P[:,i])