This commit is contained in:
Martin Diehl 2020-05-17 08:01:34 +02:00
parent 743e91a78d
commit a25dd1c438
2 changed files with 11 additions and 11 deletions

View File

@ -35,8 +35,8 @@ class Rotation:
----- -----
Vector "a" (defined in coordinate system "A") is passively rotated Vector "a" (defined in coordinate system "A") is passively rotated
resulting in new coordinates "b" when expressed in system "B". resulting in new coordinates "b" when expressed in system "B".
b = Q * a b = Q @ a
b = np.dot(Q.asMatrix(),a) b = np.dot(Q.as_matrix(),a)
""" """
@ -73,8 +73,8 @@ class Rotation:
raise NotImplementedError('Support for multiple rotations missing') raise NotImplementedError('Support for multiple rotations missing')
return '\n'.join([ return '\n'.join([
'Quaternion: (real={:.3f}, imag=<{:+.3f}, {:+.3f}, {:+.3f}>)'.format(*(self.quaternion)), 'Quaternion: (real={:.3f}, imag=<{:+.3f}, {:+.3f}, {:+.3f}>)'.format(*(self.quaternion)),
'Matrix:\n{}'.format(self.asMatrix()), 'Matrix:\n{}'.format(self.as_matrix()),
'Bunge Eulers / deg: ({:3.2f}, {:3.2f}, {:3.2f})'.format(*self.asEulers(degrees=True)), 'Bunge Eulers / deg: ({:3.2f}, {:3.2f}, {:3.2f})'.format(*self.as_Eulers(degrees=True)),
]) ])
@ -112,9 +112,9 @@ class Rotation:
return A*other + B*self.quaternion[1:] + C * np.cross(self.quaternion[1:],other) return A*other + B*self.quaternion[1:] + C * np.cross(self.quaternion[1:],other)
elif other.shape == (3,3,): elif other.shape == (3,3,):
return np.dot(self.asMatrix(),np.dot(other,self.asMatrix().T)) return np.dot(self.as_matrix(),np.dot(other,self.as_matrix().T))
elif other.shape == (3,3,3,3,): elif other.shape == (3,3,3,3,):
R = self.asMatrix() R = self.as_matrix()
return np.einsum('...im,...jn,...ko,...lp,...mnop',R,R,R,R,other) return np.einsum('...im,...jn,...ko,...lp,...mnop',R,R,R,R,other)
else: else:
raise ValueError('Can only rotate vectors, 2nd order ternsors, and 4th order tensors') raise ValueError('Can only rotate vectors, 2nd order ternsors, and 4th order tensors')
@ -150,10 +150,10 @@ class Rotation:
- p_m[...,(i+2)%3]*other[...,(i+1)%3])).reshape(self.shape+(1,)) - p_m[...,(i+2)%3]*other[...,(i+1)%3])).reshape(self.shape+(1,))
for i in [0,1,2]]) for i in [0,1,2]])
if self.shape + (3,3) == other.shape: if self.shape + (3,3) == other.shape:
R = self.asMatrix() R = self.as_matrix()
return np.einsum('...im,...jn,...mn',R,R,other) return np.einsum('...im,...jn,...mn',R,R,other)
if self.shape + (3,3,3,3) == other.shape: if self.shape + (3,3,3,3) == other.shape:
R = self.asMatrix() R = self.as_matrix()
return np.einsum('...im,...jn,...ko,...lp,...mnop',R,R,R,R,other) return np.einsum('...im,...jn,...ko,...lp,...mnop',R,R,R,R,other)
else: else:
raise ValueError('Can only rotate vectors, 2nd order ternsors, and 4th order tensors') raise ValueError('Can only rotate vectors, 2nd order ternsors, and 4th order tensors')

View File

@ -51,7 +51,7 @@ class TestOrientation:
def test_relationship_reference(self,update,reference_dir,model,lattice): def test_relationship_reference(self,update,reference_dir,model,lattice):
reference = os.path.join(reference_dir,'{}_{}.txt'.format(lattice,model)) reference = os.path.join(reference_dir,'{}_{}.txt'.format(lattice,model))
ori = Orientation(Rotation(),lattice) ori = Orientation(Rotation(),lattice)
eu = np.array([o.rotation.asEulers(degrees=True) for o in ori.relatedOrientations(model)]) eu = np.array([o.rotation.as_Eulers(degrees=True) for o in ori.relatedOrientations(model)])
if update: if update:
coords = np.array([(1,i+1) for i,x in enumerate(eu)]) coords = np.array([(1,i+1) for i,x in enumerate(eu)])
table = damask.Table(eu,{'Eulers':(3,)}) table = damask.Table(eu,{'Eulers':(3,)})