testing IPF color (vectorization)

This commit is contained in:
Martin Diehl 2020-06-30 18:41:59 +02:00
parent bdb461a553
commit 9a83b11a99
4 changed files with 27 additions and 28 deletions

View File

@ -103,6 +103,6 @@ def set_of_quaternions():
specials_scatter /= np.linalg.norm(specials_scatter,axis=1).reshape(-1,1)
specials_scatter[specials_scatter[:,0]<0]*=-1
return [s for s in specials] + \
return np.array([s for s in specials] + \
[s for s in specials_scatter] + \
[s for s in random_quaternions(n-2*len(specials))]
[s for s in random_quaternions(n-2*len(specials))])

View File

@ -11,6 +11,15 @@ from damask import Lattice
n = 1000
def IPF_color(orientation,direction):
"""TSL color of inverse pole figure for given axis (non-vectorized)."""
for o in orientation.equivalent:
pole = o.rotation@direction
inSST,color = orientation.lattice.in_SST(pole,color=True)
if inSST: break
return color
@pytest.fixture
def reference_dir(reference_dir_base):
"""Directory containing reference results."""
@ -26,16 +35,23 @@ class TestOrientation:
def test_IPF_cubic(self,color,lattice):
cube = damask.Orientation(damask.Rotation(),lattice)
for direction in set(permutations(np.array(color['direction']))):
assert np.allclose(cube.IPFcolor(np.array(direction)),np.array(color['RGB']))
assert np.allclose(cube.IPF_color(np.array(direction)),np.array(color['RGB']))
@pytest.mark.parametrize('lattice',Lattice.lattices)
def test_IPF(self,lattice):
def test_IPF_equivalent(self,set_of_quaternions,lattice):
direction = np.random.random(3)*2.0-1
for rot in [Rotation.from_random() for r in range(n//100)]:
R = damask.Orientation(rot,lattice)
color = R.IPFcolor(direction)
for equivalent in R.equivalent:
assert np.allclose(color,R.IPFcolor(direction))
for ori in Orientation(Rotation(set_of_quaternions),lattice)[200]:
color = ori.IPF_color(direction)
for equivalent in ori.equivalent:
assert np.allclose(color,equivalent.IPF_color(direction))
@pytest.mark.parametrize('lattice',Lattice.lattices)
def test_IPF_vectorize(self,set_of_quaternions,lattice):
for ori in Orientation(Rotation(set_of_quaternions),lattice)[200]:
direction = np.random.random(3)*2.0-1
assert np.allclose(ori.IPF_color(direction),IPF_color(ori,direction))
@pytest.mark.parametrize('model',['Bain','KS','GT','GT_prime','NW','Pitsch'])
@pytest.mark.parametrize('lattice',['fcc','bcc'])

View File

@ -6,7 +6,7 @@ import numpy as np
from damask import Rotation
from damask import _rotation
n = 1000
n = 1100
atol=1.e-4
@pytest.fixture

View File

@ -97,20 +97,3 @@ class TestOrientation_vec:
assert all(ori_vec.reduced_vec.rotation.as_Rodrigues()[2] == ori2.reduced().rotation.as_Rodrigues() )
assert all(ori_vec.reduced_vec.rotation.as_cubochoric()[3] == ori3.reduced().rotation.as_cubochoric() )
assert all(ori_vec.reduced_vec.rotation.as_axis_angle()[4] == ori4.reduced().rotation.as_axis_angle() )
@pytest.mark.parametrize('lattice',['bcc','fcc','bct'])
def test_IPFcolor_vec(self,lattice):
ori0=Orientation(rot0,lattice)
ori1=Orientation(rot1,lattice)
ori2=Orientation(rot2,lattice)
ori3=Orientation(rot3,lattice)
quat=np.array([rot0.as_quaternion(),rot1.as_quaternion(),\
rot2.as_quaternion(),rot3.as_quaternion()])
ori_vec=Orientation(quat,lattice)
assert np.allclose( ori_vec.IPF_color(np.array([0,0,1]))[0],ori0.IPFcolor(np.array([0,0,1])))
assert np.allclose( ori_vec.IPF_color(np.array([0,2,1]))[1],ori1.IPFcolor(np.array([0,2,1])))
assert np.allclose( ori_vec.IPF_color(np.array([0,3,1]))[2],ori2.IPFcolor(np.array([0,3,1])))
assert np.allclose( ori_vec.IPF_color(np.array([4,0,1]))[3],ori3.IPFcolor(np.array([4,0,1])))