From d1f9e98e3ce071c9e24488675bc6ed9b579fb524 Mon Sep 17 00:00:00 2001 From: Daniel Otto de Mentock Date: Thu, 3 Feb 2022 16:11:09 +0100 Subject: [PATCH] moved typecheck of __ne__ functions to __eq__ added initial empty runtimeerror to Schmid function minor corrections --- python/damask/_orientation.py | 13 ++++++++----- python/damask/_rotation.py | 7 ++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index dff380dcf..780a5929e 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -165,8 +165,10 @@ class Orientation(Rotation,Crystal): Orientation to check for equality. """ - if not isinstance(other, Orientation): - raise TypeError + + eq = self.__eq__(other) + if not isinstance(eq, bool): + return eq return np.logical_not(self==other) @@ -557,7 +559,7 @@ class Orientation(Rotation,Crystal): if self.family != other.family: raise NotImplementedError('disorientation between different crystal families') - blend: Tuple[int, ...] = util.shapeblender(self.shape,other.shape) + blend = util.shapeblender(self.shape,other.shape) s = self.equivalent o = other.equivalent @@ -764,7 +766,7 @@ class Orientation(Rotation,Crystal): np.broadcast_to(self.standard_triangle['improper'], vector_.shape+(3,)), vector_), 12) in_SST_ = np.all(components_proper >= 0.0,axis=-1) \ - | np.all(components_improper >= 0.0,axis=-1) + | np.all(components_improper >= 0.0,axis=-1) components = np.where((in_SST_ & np.all(components_proper >= 0.0,axis=-1))[...,np.newaxis], components_proper,components_improper) else: @@ -928,7 +930,8 @@ class Orientation(Rotation,Crystal): (self.kinematics('twin'),N_twin) if active == '*': active = [len(a) for a in kinematics['direction']] - assert active + if not active: + raise RuntimeError 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), diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index d919c9029..c3f6407f2 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -85,7 +85,7 @@ class Rotation: elif np.array(rotation).shape[-1] == 4: self.quaternion = np.array(rotation) else: - raise TypeError('Rotation is neither a Rotation nor a quaternion') + raise TypeError('"rotation" is neither a Rotation nor a quaternion') def __repr__(self) -> str: @@ -139,8 +139,9 @@ class Rotation: Rotation to check for inequality. """ - if not isinstance(other, Rotation): - raise TypeError + eq = self.__eq__(other) + if not isinstance(eq, bool): + return eq return np.logical_not(self==other)