2020-02-22 04:33:54 +05:30
|
|
|
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
|
|
|
|
|
2020-05-16 17:14:07 +05:30
|
|
|
n = 1000
|
2020-02-22 04:33:54 +05:30
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def reference_dir(reference_dir_base):
|
|
|
|
"""Directory containing reference results."""
|
|
|
|
return os.path.join(reference_dir_base,'Rotation')
|
|
|
|
|
|
|
|
|
|
|
|
class TestOrientation:
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('color',[{'label':'red', 'RGB':[1,0,0],'direction':[0,0,1]},
|
|
|
|
{'label':'green','RGB':[0,1,0],'direction':[0,1,1]},
|
|
|
|
{'label':'blue', 'RGB':[0,0,1],'direction':[1,1,1]}])
|
|
|
|
@pytest.mark.parametrize('lattice',['fcc','bcc'])
|
2020-05-16 17:14:07 +05:30
|
|
|
def test_IPF_cubic(self,color,lattice):
|
2020-02-22 04:33:54 +05:30
|
|
|
cube = damask.Orientation(damask.Rotation(),lattice)
|
|
|
|
for direction in set(permutations(np.array(color['direction']))):
|
2020-05-16 17:14:07 +05:30
|
|
|
assert np.allclose(cube.IPFcolor(np.array(direction)),np.array(color['RGB']))
|
2020-02-22 04:33:54 +05:30
|
|
|
|
|
|
|
@pytest.mark.parametrize('lattice',Lattice.lattices)
|
|
|
|
def test_IPF(self,lattice):
|
|
|
|
direction = np.random.random(3)*2.0-1
|
2020-05-16 14:47:12 +05:30
|
|
|
for rot in [Rotation.from_random() for r in range(n//100)]:
|
2020-02-22 04:33:54 +05:30
|
|
|
R = damask.Orientation(rot,lattice)
|
|
|
|
color = R.IPFcolor(direction)
|
|
|
|
for equivalent in R.equivalentOrientations():
|
|
|
|
assert np.allclose(color,R.IPFcolor(direction))
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('model',['Bain','KS','GT','GT_prime','NW','Pitsch'])
|
|
|
|
@pytest.mark.parametrize('lattice',['fcc','bcc'])
|
|
|
|
def test_relationship_forward_backward(self,model,lattice):
|
2020-05-16 14:47:12 +05:30
|
|
|
ori = Orientation(Rotation.from_random(),lattice)
|
2020-02-22 04:33:54 +05:30
|
|
|
for i,r in enumerate(ori.relatedOrientations(model)):
|
|
|
|
ori2 = r.relatedOrientations(model)[i]
|
|
|
|
misorientation = ori.rotation.misorientation(ori2.rotation)
|
|
|
|
assert misorientation.asAxisAngle(degrees=True)[3]<1.0e-5
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('model',['Bain','KS','GT','GT_prime','NW','Pitsch'])
|
|
|
|
@pytest.mark.parametrize('lattice',['fcc','bcc'])
|
|
|
|
def test_relationship_reference(self,update,reference_dir,model,lattice):
|
|
|
|
reference = os.path.join(reference_dir,'{}_{}.txt'.format(lattice,model))
|
|
|
|
ori = Orientation(Rotation(),lattice)
|
2020-05-17 11:31:34 +05:30
|
|
|
eu = np.array([o.rotation.as_Eulers(degrees=True) for o in ori.relatedOrientations(model)])
|
2020-05-16 17:14:07 +05:30
|
|
|
if update:
|
2020-02-22 04:33:54 +05:30
|
|
|
coords = np.array([(1,i+1) for i,x in enumerate(eu)])
|
|
|
|
table = damask.Table(eu,{'Eulers':(3,)})
|
|
|
|
table.add('pos',coords)
|
|
|
|
table.to_ASCII(reference)
|
|
|
|
assert np.allclose(eu,damask.Table.from_ASCII(reference).get('Eulers'))
|