fix for vectorized in_SST + test

This commit is contained in:
Martin Diehl 2020-06-30 22:33:58 +02:00
parent 49d448dced
commit ef0c78745a
5 changed files with 25 additions and 13 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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):

View File

@ -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()

View File

@ -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