From 9a43c2e4c5102101026dfc2e973e167c0b5509b4 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 19 Apr 2019 01:05:48 +0200 Subject: [PATCH] fixed return values - homomorph, standardize, etc. are silent in-place operations (return None) - homomorphed, standardized, etc. are out-of place operations that report --- python/damask/orientation.py | 23 ++++++++++++++++------- python/damask/quaternion.py | 12 +++++++++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/python/damask/orientation.py b/python/damask/orientation.py index 26e926357..dc3389977 100644 --- a/python/damask/orientation.py +++ b/python/damask/orientation.py @@ -44,6 +44,12 @@ class Rotation: self.quaternion = quaternion.copy() else: self.quaternion = Quaternion(q=quaternion[0],p=quaternion[1:4]) + + def __copy__(self): + """Copy""" + return self.__class__(self.quaternion) + + copy = __copy__ def __repr__(self): @@ -61,9 +67,9 @@ class Rotation: Rotation: Details needed (active/passive), rotation of (3,3,3,3)-matrix should be considered """ if isinstance(other, Rotation): # rotate a rotation - qu = self.quaternion * other.quaternion - if qu.q < 0: qu.homomorph() - return self.__class__(qu) + qu = self.__class__(self.quaternion * other.quaternion) + qu.standardize() + return qu elif isinstance(other, np.ndarray): if other.shape == (3,): # rotate a single (3)-vector ( x, y, z) = self.quaternion.p @@ -102,11 +108,12 @@ class Rotation: def inverse(self): """In-place inverse rotation/backward rotation""" self.quaternion.conjugate() - return self def inversed(self): """Inverse rotation/backward rotation""" - return self.__class__(self.quaternion.conjugated()) + c = self.copy() + c.inverse() + return c def standardize(self): @@ -115,7 +122,9 @@ class Rotation: def standardized(self): """Ensure quaternion representation with positive q""" - return self.__class__(self.quaternion.homomorphed() if self.quaternion.q < 0.0 else self.quaternion) + c = self.copy() + c.standardize() + return c def misorientation(self,other): @@ -929,7 +938,7 @@ class Orientation: if breaker: break if breaker: break - return (Orientation(r,self.symmetry), i,j, k == 1) if symmetries else r # disorientation ... + return (Orientation(r,self.lattice), i,j, k == 1) if symmetries else r # disorientation ... # ... own sym, other sym, # self-->other: True, self<--other: False diff --git a/python/damask/quaternion.py b/python/damask/quaternion.py index 1bb6f5f0d..69f4e6ef0 100644 --- a/python/damask/quaternion.py +++ b/python/damask/quaternion.py @@ -192,7 +192,9 @@ class Quaternion: def normalized(self): """Returns normalized copy""" - return self.copy().normalize() + c = self.copy() + c.normalize() + return c def conjugate(self): @@ -201,7 +203,9 @@ class Quaternion: def conjugated(self): """Returns conjugated copy""" - return self.copy().conjugate() + c = self.copy() + c.conjugate() + return c def homomorph(self): @@ -211,4 +215,6 @@ class Quaternion: def homomorphed(self): """Returns homomorphed copy""" - return self.copy().homomorph() + c = self.copy() + c.homomorph() + return c