equivalent,related and inFZ vectorized + pytest
This commit is contained in:
parent
ac09a2912a
commit
eae9698d22
|
@ -77,25 +77,37 @@ class Orientation:
|
||||||
return (Orientation(r,self.lattice), 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,
|
# ... own sym, other sym,
|
||||||
# self-->other: True, self<--other: False
|
# self-->other: True, self<--other: False
|
||||||
|
|
||||||
|
def inFZ_vec(self):
|
||||||
|
"""
|
||||||
|
Check if orientations falls into Fundamental Zone
|
||||||
|
|
||||||
|
self.rotation.as_Rodrigues() working fine
|
||||||
|
self.rotation.as_Rodrigues(vector=True) doesn't work for several rotations
|
||||||
|
i apply dirty fix
|
||||||
|
|
||||||
|
"""
|
||||||
|
if not self.rotation.shape:
|
||||||
|
return self.lattice.symmetry.inFZ(self.rotation.as_Rodrigues(vector=True))
|
||||||
|
else:
|
||||||
|
return [self.lattice.symmetry.inFZ(\
|
||||||
|
Rotation._qu2ro(self.rotation.as_quaternion())[l][...,:3]\
|
||||||
|
*Rotation._qu2ro(self.rotation.as_quaternion())[l][...,3])\
|
||||||
|
for l in range(self.rotation.shape[0])]
|
||||||
|
|
||||||
def inFZ(self):
|
def inFZ(self):
|
||||||
return self.lattice.symmetry.inFZ(self.rotation.as_Rodrigues(vector=True))
|
return self.lattice.symmetry.inFZ(self.rotation.as_Rodrigues(vector=True))
|
||||||
|
|
||||||
def equivalent(self):
|
def equivalent_vec(self):
|
||||||
"""
|
"""List of orientations which are symmetrically equivalent."""
|
||||||
List of orientations which are symmetrically equivalent.
|
|
||||||
|
|
||||||
Supported for multiple rotation with same lattice
|
|
||||||
Returns list [i] being i=range(24)
|
|
||||||
Returns list [i, num_rot] for multiple rotations
|
|
||||||
|
|
||||||
"""
|
|
||||||
if not self.rotation.shape:
|
if not self.rotation.shape:
|
||||||
return [self.__class__(q*self.rotation,self.lattice) \
|
return [self.__class__(q*self.rotation,self.lattice) \
|
||||||
for q in self.lattice.symmetry.symmetryOperations()]
|
for q in self.lattice.symmetry.symmetryOperations()]
|
||||||
else:
|
else:
|
||||||
return np.reshape([self.__class__(q*Rotation.from_quaternion(self.rotation.as_quaternion()[l]),self.lattice) \
|
return np.reshape([self.__class__(q*Rotation.from_quaternion(self.rotation.as_quaternion()[l]),self.lattice) \
|
||||||
for q in self.lattice.symmetry.symmetryOperations() \
|
for q in self.lattice.symmetry.symmetryOperations() \
|
||||||
for l in range(self.rotation.shape[0])], (24,self.rotation.shape[0]))
|
for l in range(self.rotation.shape[0])], \
|
||||||
|
(len(self.lattice.symmetry.symmetryOperations()),self.rotation.shape[0]))
|
||||||
|
|
||||||
|
|
||||||
def equivalentOrientations(self,members=[]):
|
def equivalentOrientations(self,members=[]):
|
||||||
|
@ -108,6 +120,18 @@ class Orientation:
|
||||||
return [self.__class__(q*self.rotation,self.lattice) \
|
return [self.__class__(q*self.rotation,self.lattice) \
|
||||||
for q in self.lattice.symmetry.symmetryOperations(members)] # yes, return list of rotations
|
for q in self.lattice.symmetry.symmetryOperations(members)] # yes, return list of rotations
|
||||||
|
|
||||||
|
def relatedOrientations_vec(self,model):
|
||||||
|
"""List of orientations related by the given orientation relationship."""
|
||||||
|
r = self.lattice.relationOperations(model)
|
||||||
|
if not self.rotation.shape:
|
||||||
|
return [self.__class__(o*self.rotation,r['lattice']) for o in r['rotations']]
|
||||||
|
else:
|
||||||
|
return np.reshape(\
|
||||||
|
[self.__class__(o*Rotation.from_quaternion(self.rotation.as_quaternion()[l])\
|
||||||
|
,r['lattice']) for o in r['rotations'] for l in range(self.rotation.shape[0])]
|
||||||
|
,(len(r['rotations']),self.rotation.shape[0]))
|
||||||
|
|
||||||
|
|
||||||
def relatedOrientations(self,model):
|
def relatedOrientations(self,model):
|
||||||
"""List of orientations related by the given orientation relationship."""
|
"""List of orientations related by the given orientation relationship."""
|
||||||
r = self.lattice.relationOperations(model)
|
r = self.lattice.relationOperations(model)
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
import damask
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
|
|
||||||
rot0= damask.Rotation.from_random()
|
|
||||||
rot1= damask.Rotation.from_random()
|
|
||||||
rot2= damask.Rotation.from_random()
|
|
||||||
|
|
||||||
ori0=damask.Orientation(rot0,'fcc')
|
|
||||||
ori1=damask.Orientation(rot1,'fcc')
|
|
||||||
ori2=damask.Orientation(rot2,'fcc')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
quat=np.array([rot0.as_quaternion(),rot1.as_quaternion(),rot2.as_quaternion()])
|
|
||||||
rot=damask.Rotation.from_quaternion(quat)
|
|
||||||
|
|
||||||
ori=damask.Orientation(rot,'fcc')
|
|
||||||
|
|
||||||
ori.equivalent()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# doesn't work this way, don't know why
|
|
||||||
#ori.equivalent()[:,0][0] == ori0.equivalentOrientations()[0]
|
|
||||||
|
|
||||||
for s in range(24):
|
|
||||||
print(ori.equivalent()[s,0].rotation.as_Eulers() == ori0.equivalentOrientations()[s].rotation.as_Eulers())
|
|
||||||
print(ori.equivalent()[s,1].rotation.as_Eulers() == ori1.equivalentOrientations()[s].rotation.as_Eulers())
|
|
||||||
print(ori.equivalent()[s,2].rotation.as_Eulers() == ori2.equivalentOrientations()[s].rotation.as_Eulers())
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
import os
|
||||||
|
from itertools import permutations
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
import damask
|
||||||
|
from damask import Rotation
|
||||||
|
from damask import Orientation
|
||||||
|
from damask import Lattice
|
||||||
|
|
||||||
|
rot0= damask.Rotation.from_random()
|
||||||
|
rot1= damask.Rotation.from_random()
|
||||||
|
rot2= damask.Rotation.from_random()
|
||||||
|
rot3= damask.Rotation.from_random()
|
||||||
|
|
||||||
|
class TestOrientation_vec:
|
||||||
|
@pytest.mark.parametrize('lattice',Lattice.lattices)
|
||||||
|
def test_equivalentOrientations_vec(self,lattice):
|
||||||
|
ori0=damask.Orientation(rot0,lattice)
|
||||||
|
ori1=damask.Orientation(rot1,lattice)
|
||||||
|
ori2=damask.Orientation(rot2,lattice)
|
||||||
|
ori3=damask.Orientation(rot3,lattice)
|
||||||
|
|
||||||
|
quat=np.array([rot0.as_quaternion(),rot1.as_quaternion(),rot2.as_quaternion(),rot3.as_quaternion()])
|
||||||
|
rot_vec=damask.Rotation.from_quaternion(quat)
|
||||||
|
ori_vec=damask.Orientation(rot_vec,lattice)
|
||||||
|
|
||||||
|
for s in range(len(ori_vec.lattice.symmetry.symmetryOperations())):
|
||||||
|
assert all(ori_vec.equivalent_vec()[s,0].rotation.as_Eulers() == \
|
||||||
|
ori0.equivalentOrientations()[s].rotation.as_Eulers())
|
||||||
|
assert all(ori_vec.equivalent_vec()[s,1].rotation.as_quaternion() == \
|
||||||
|
ori1.equivalentOrientations()[s].rotation.as_quaternion())
|
||||||
|
assert all(ori_vec.equivalent_vec()[s,2].rotation.as_Rodrigues() == \
|
||||||
|
ori2.equivalentOrientations()[s].rotation.as_Rodrigues())
|
||||||
|
assert all(ori_vec.equivalent_vec()[s,3].rotation.as_cubochoric() == \
|
||||||
|
ori3.equivalentOrientations()[s].rotation.as_cubochoric())
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('lattice',Lattice.lattices)
|
||||||
|
def test_inFZ_vec(self,lattice):
|
||||||
|
ori0=damask.Orientation(rot0,lattice)
|
||||||
|
ori1=damask.Orientation(rot1,lattice)
|
||||||
|
ori2=damask.Orientation(rot2,lattice)
|
||||||
|
ori3=damask.Orientation(rot3,lattice)
|
||||||
|
#ensure 1 of them is in FZ
|
||||||
|
ori4=ori0.reduced()
|
||||||
|
rot4=ori4.rotation
|
||||||
|
|
||||||
|
quat=np.array([rot0.as_quaternion(),rot1.as_quaternion(),\
|
||||||
|
rot2.as_quaternion(),rot3.as_quaternion(), rot4.as_quaternion()])
|
||||||
|
rot_vec=damask.Rotation.from_quaternion(quat)
|
||||||
|
ori_vec=damask.Orientation(rot_vec,lattice)
|
||||||
|
|
||||||
|
assert ori_vec.inFZ_vec()[0] == ori0.inFZ()
|
||||||
|
assert ori_vec.inFZ_vec()[1] == ori1.inFZ()
|
||||||
|
assert ori_vec.inFZ_vec()[2] == ori2.inFZ()
|
||||||
|
assert ori_vec.inFZ_vec()[3] == ori3.inFZ()
|
||||||
|
assert ori_vec.inFZ_vec()[4] == ori4.inFZ()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('model',['Bain','KS','GT','GT_prime','NW','Pitsch'])
|
||||||
|
@pytest.mark.parametrize('lattice',['fcc','bcc'])
|
||||||
|
def test_relatedOrientations_vec(self,model,lattice):
|
||||||
|
ori0=damask.Orientation(rot0,lattice)
|
||||||
|
ori1=damask.Orientation(rot1,lattice)
|
||||||
|
ori2=damask.Orientation(rot2,lattice)
|
||||||
|
ori3=damask.Orientation(rot3,lattice)
|
||||||
|
|
||||||
|
quat=np.array([rot0.as_quaternion(),rot1.as_quaternion(),rot2.as_quaternion(),rot3.as_quaternion()])
|
||||||
|
rot_vec=damask.Rotation.from_quaternion(quat)
|
||||||
|
ori_vec=damask.Orientation(rot_vec,lattice)
|
||||||
|
|
||||||
|
for s in range(len(ori1.lattice.relationOperations(model)['rotations'])):
|
||||||
|
assert all(ori_vec.relatedOrientations_vec(model)[s,0].rotation.as_Eulers() == \
|
||||||
|
ori0.relatedOrientations(model)[s].rotation.as_Eulers())
|
||||||
|
assert all(ori_vec.relatedOrientations_vec(model)[s,1].rotation.as_quaternion() == \
|
||||||
|
ori1.relatedOrientations(model)[s].rotation.as_quaternion())
|
||||||
|
assert all(ori_vec.relatedOrientations_vec(model)[s,2].rotation.as_Rodrigues() == \
|
||||||
|
ori2.relatedOrientations(model)[s].rotation.as_Rodrigues())
|
||||||
|
assert all(ori_vec.relatedOrientations_vec(model)[s,3].rotation.as_cubochoric() == \
|
||||||
|
ori3.relatedOrientations(model)[s].rotation.as_cubochoric())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue