compatible with material.yaml

This commit is contained in:
Martin Diehl 2021-08-04 17:45:25 +02:00
parent bb5db3e79c
commit b5be4c3fa5
2 changed files with 19 additions and 11 deletions

View File

@ -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))

View File

@ -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])