From ef0c78745a1b7146bac19c71fd285608da47c194 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 30 Jun 2020 22:33:58 +0200 Subject: [PATCH] fix for vectorized in_SST + test --- python/damask/_lattice.py | 14 +++++++++----- python/damask/_orientation.py | 1 - python/tests/test_Lattice.py | 19 ++++++++++++++----- python/tests/test_Result.py | 2 +- python/tests/test_Rotation.py | 2 +- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/python/damask/_lattice.py b/python/damask/_lattice.py index 74ef61a50..a337aa1a1 100644 --- a/python/damask/_lattice.py +++ b/python/damask/_lattice.py @@ -160,7 +160,7 @@ class Symmetry: Fundamental zone in Rodrigues space is point symmetric around origin. """ if(rho.shape[-1] != 3): - raise ValueError('Input is not a Rodrigues-Frank vector.') + raise ValueError('Input is not a Rodrigues-Frank vector field.') rho_abs = np.abs(rho) @@ -195,7 +195,7 @@ class Symmetry: """ if(rho.shape[-1] != 3): - raise ValueError('Input is not a Rodrigues-Frank vector.') + raise ValueError('Input is not a Rodrigues-Frank vector field.') with np.errstate(invalid='ignore'): # using '*' for 'and' @@ -242,6 +242,9 @@ class Symmetry: ... } """ + if(vector.shape[-1] != 3): + raise ValueError('Input is not a 3D vector field.') + if self.system == 'cubic': basis = {'improper':np.array([ [-1. , 0. , 1. ], [ np.sqrt(2.) , -np.sqrt(2.) , 0. ], @@ -280,16 +283,17 @@ class Symmetry: else: return np.ones_like(vector[...,0],bool) - b_p = np.broadcast_to(basis['proper'], vector.shape+(3,)) + + b_i = np.broadcast_to(basis['improper'],vector.shape+(3,)) if proper: - b_i = np.broadcast_to(basis['improper'],vector.shape+(3,)) + b_p = np.broadcast_to(basis['proper'], vector.shape+(3,)) improper = np.all(np.around(np.einsum('...ji,...i',b_i,vector),12)>=0.0,axis=-1,keepdims=True) theComponents = np.where(np.broadcast_to(improper,vector.shape), np.around(np.einsum('...ji,...i',b_i,vector),12), np.around(np.einsum('...ji,...i',b_p,vector),12)) else: vector_ = np.block([vector[...,0:2],np.abs(vector[...,2:3])]) # z component projects identical - theComponents = np.around(np.einsum('...ji,...i',b_p,vector_),12) + theComponents = np.around(np.einsum('...ji,...i',b_i,vector_),12) in_SST = np.all(theComponents >= 0.0,axis=-1) diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index b6b24e951..c59ababda 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -79,7 +79,6 @@ class Orientation: # ToDo: make subclass of lattice and Rotation # ... own sym, other sym, # self-->other: True, self<--other: False - def in_FZ(self): """Check if orientations fall into Fundamental Zone.""" return self.lattice.in_FZ(self.rotation.as_Rodrigues(vector=True)) diff --git a/python/tests/test_Lattice.py b/python/tests/test_Lattice.py index 8e4616660..f53c3ad03 100644 --- a/python/tests/test_Lattice.py +++ b/python/tests/test_Lattice.py @@ -106,14 +106,23 @@ class TestSymmetry: @pytest.mark.parametrize('system',Symmetry.crystal_systems) def test_in_FZ_vectorize(self,set_of_rodrigues,system): - for i,in_FZ_ in enumerate(Symmetry(system).in_FZ(set_of_rodrigues)): - assert in_FZ_ == in_FZ(system,set_of_rodrigues[i]) + result = Symmetry(system).in_FZ(set_of_rodrigues.reshape(50,4,3)).reshape(200) + for i,r in enumerate(result): + assert r == in_FZ(system,set_of_rodrigues[i]) @pytest.mark.parametrize('system',Symmetry.crystal_systems) def test_in_disorientation_SST_vectorize(self,set_of_rodrigues,system): - for i,in_disorientation_SST_ in enumerate(Symmetry(system).in_disorientation_SST(set_of_rodrigues)): - assert in_disorientation_SST_ == in_disorientation_SST(system,set_of_rodrigues[i]) + result = Symmetry(system).in_disorientation_SST(set_of_rodrigues.reshape(50,4,3)).reshape(200) + for i,r in enumerate(result): + assert r == in_disorientation_SST(system,set_of_rodrigues[i]) + @pytest.mark.parametrize('proper',[True,False]) + @pytest.mark.parametrize('system',Symmetry.crystal_systems) + def test_in_SST_vectorize(self,system,proper): + vecs = np.random.rand(20,4,3) + result = Symmetry(system).in_SST(vecs,proper).reshape(20*4) + for i,r in enumerate(result): + assert r == in_SST(system,vecs.reshape(20*4,3)[i],proper) @pytest.mark.parametrize('invalid_symmetry',['fcc','bcc','hello']) def test_invalid_symmetry(self,invalid_symmetry): @@ -142,7 +151,7 @@ class TestSymmetry: def test_in_SST(self,system,proper): assert Symmetry(system).in_SST(np.zeros(3),proper) - @pytest.mark.parametrize('function',['in_FZ','in_disorientation_SST']) + @pytest.mark.parametrize('function',['in_FZ','in_disorientation_SST','in_SST']) def test_invalid_argument(self,function): s = Symmetry() # noqa with pytest.raises(ValueError): diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index aec91db9f..b27a3d5f3 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -319,4 +319,4 @@ class TestResult: def test_XDMF(self,tmp_path,single_phase): os.chdir(tmp_path) - single_phase.write_XDMF + single_phase.write_XDMF() diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index 20d01af4a..b4166bf1b 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -20,7 +20,7 @@ def set_of_rotations(set_of_quaternions): #################################################################################################### -# Code below available according to the following conditions on https://github.com/MarDiehl/3Drotations +# Code below available according to the following conditions #################################################################################################### # Copyright (c) 2017-2019, Martin Diehl/Max-Planck-Institut für Eisenforschung GmbH # Copyright (c) 2013-2014, Marc De Graef/Carnegie Mellon University