From b5be4c3fa51ef1a2bd5b521d62bbd2c23946b532 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 4 Aug 2021 17:45:25 +0200 Subject: [PATCH] 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])