From 4bcbcb34d00790844d4c00a1b86e1df284af825e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 9 Feb 2021 23:34:51 +0100 Subject: [PATCH] ensures that at least one orientation in the FZ is found --- python/damask/_orientation.py | 24 ++++++++++++------------ python/tests/test_Orientation.py | 11 +++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index cf31f4089..184315111 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -481,26 +481,26 @@ class Orientation(Rotation): if self.family is None: raise ValueError('Missing crystal symmetry') - rho_abs = np.abs(self.as_Rodrigues_vector(compact=True)) + rho_abs = np.abs(self.as_Rodrigues_vector(compact=True))*(1.-1.e-9) with np.errstate(invalid='ignore'): # using '*'/prod for 'and' if self.family == 'cubic': return (np.prod(np.sqrt(2)-1. >= rho_abs,axis=-1) * - (1. >= np.sum(rho_abs,axis=-1))).astype(np.bool) + (1. >= np.sum(rho_abs,axis=-1))).astype(bool) elif self.family == 'hexagonal': return (np.prod(1. >= rho_abs,axis=-1) * (2. >= np.sqrt(3)*rho_abs[...,0] + rho_abs[...,1]) * (2. >= np.sqrt(3)*rho_abs[...,1] + rho_abs[...,0]) * - (2. >= np.sqrt(3) + rho_abs[...,2])).astype(np.bool) + (2. >= np.sqrt(3) + rho_abs[...,2])).astype(bool) elif self.family == 'tetragonal': return (np.prod(1. >= rho_abs[...,:2],axis=-1) * (np.sqrt(2) >= rho_abs[...,0] + rho_abs[...,1]) * - (np.sqrt(2) >= rho_abs[...,2] + 1.)).astype(np.bool) + (np.sqrt(2) >= rho_abs[...,2] + 1.)).astype(bool) elif self.family == 'orthorhombic': - return (np.prod(1. >= rho_abs,axis=-1)).astype(np.bool) + return (np.prod(1. >= rho_abs,axis=-1)).astype(bool) elif self.family == 'monoclinic': - return (1. >= rho_abs[...,1]).astype(np.bool) + return (1. >= rho_abs[...,1]).astype(bool) else: return np.all(np.isfinite(rho_abs),axis=-1) @@ -524,28 +524,28 @@ class Orientation(Rotation): if self.family is None: raise ValueError('Missing crystal symmetry') - rho = self.as_Rodrigues_vector(compact=True) + rho = self.as_Rodrigues_vector(compact=True)*(1.0-1.0e-9) with np.errstate(invalid='ignore'): if self.family == 'cubic': return ((rho[...,0] >= rho[...,1]) & (rho[...,1] >= rho[...,2]) & - (rho[...,2] >= 0)).astype(np.bool) + (rho[...,2] >= 0)).astype(bool) elif self.family == 'hexagonal': return ((rho[...,0] >= rho[...,1]*np.sqrt(3)) & (rho[...,1] >= 0) & - (rho[...,2] >= 0)).astype(np.bool) + (rho[...,2] >= 0)).astype(bool) elif self.family == 'tetragonal': return ((rho[...,0] >= rho[...,1]) & (rho[...,1] >= 0) & - (rho[...,2] >= 0)).astype(np.bool) + (rho[...,2] >= 0)).astype(bool) elif self.family == 'orthorhombic': return ((rho[...,0] >= 0) & (rho[...,1] >= 0) & - (rho[...,2] >= 0)).astype(np.bool) + (rho[...,2] >= 0)).astype(bool) elif self.family == 'monoclinic': return ((rho[...,1] >= 0) & - (rho[...,2] >= 0)).astype(np.bool) + (rho[...,2] >= 0)).astype(bool) else: return np.ones_like(rho[...,0],dtype=bool) diff --git a/python/tests/test_Orientation.py b/python/tests/test_Orientation.py index 436b73c04..4d1f958e2 100644 --- a/python/tests/test_Orientation.py +++ b/python/tests/test_Orientation.py @@ -7,6 +7,7 @@ from damask import Orientation from damask import Table from damask import lattice from damask import util +from damask import grid_filters @pytest.fixture @@ -220,6 +221,16 @@ class TestOrientation: o = Orientation.from_random(lattice=lattice,shape=shape) for r, theO in zip(o.reduced.flatten(),o.flatten()): assert r == theO.reduced + + @pytest.mark.parametrize('lattice',Orientation.crystal_families) + def test_reduced_corner_cases(self,lattice): + # test whether there is always a sym-eq rotation that falls into the FZ + N = np.random.randint(10,40) + size = np.ones(3)*np.pi**(2./3.) + grid = grid_filters.coordinates0_node([N+1,N+1,N+1],size,-size*.5) + evenly_distributed = Orientation.from_cubochoric(c=grid[:-2,:-2,:-2],lattice=lattice) + assert evenly_distributed.shape == evenly_distributed.reduced.shape + @pytest.mark.parametrize('lattice',Orientation.crystal_families) @pytest.mark.parametrize('shape',[(1),(2,3),(4,3,2)])