2019-12-09 02:18:32 +05:30
|
|
|
import os
|
|
|
|
|
2019-11-24 10:59:00 +05:30
|
|
|
import pytest
|
2019-11-22 01:31:01 +05:30
|
|
|
import numpy as np
|
2019-11-24 10:59:00 +05:30
|
|
|
|
2019-12-09 02:18:32 +05:30
|
|
|
import damask
|
2019-11-22 01:31:01 +05:30
|
|
|
from damask import Rotation
|
2019-12-09 01:59:26 +05:30
|
|
|
from damask import Orientation
|
2019-11-24 10:59:00 +05:30
|
|
|
|
2020-01-15 03:00:08 +05:30
|
|
|
n = 1000
|
2019-11-24 10:59:00 +05:30
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def default():
|
|
|
|
"""A set of n random rotations."""
|
|
|
|
return [Rotation.fromRandom() for r in range(n)]
|
|
|
|
|
2019-12-09 02:18:32 +05:30
|
|
|
@pytest.fixture
|
|
|
|
def reference_dir(reference_dir_base):
|
|
|
|
"""Directory containing reference results."""
|
|
|
|
return os.path.join(reference_dir_base,'Rotation')
|
|
|
|
|
2019-11-22 01:31:01 +05:30
|
|
|
|
|
|
|
class TestRotation:
|
|
|
|
|
2019-11-24 10:59:00 +05:30
|
|
|
def test_Eulers(self,default):
|
|
|
|
for rot in default:
|
2019-11-22 02:18:54 +05:30
|
|
|
assert np.allclose(rot.asQuaternion(),
|
|
|
|
Rotation.fromEulers(rot.asEulers()).asQuaternion())
|
2019-11-22 01:31:01 +05:30
|
|
|
|
2019-11-24 10:59:00 +05:30
|
|
|
def test_AxisAngle(self,default):
|
|
|
|
for rot in default:
|
2019-11-22 02:18:54 +05:30
|
|
|
assert np.allclose(rot.asEulers(),
|
|
|
|
Rotation.fromAxisAngle(rot.asAxisAngle()).asEulers())
|
2019-11-22 01:31:01 +05:30
|
|
|
|
2019-11-24 10:59:00 +05:30
|
|
|
def test_Matrix(self,default):
|
|
|
|
for rot in default:
|
2019-11-22 02:18:54 +05:30
|
|
|
assert np.allclose(rot.asAxisAngle(),
|
|
|
|
Rotation.fromMatrix(rot.asMatrix()).asAxisAngle())
|
2019-11-22 01:31:01 +05:30
|
|
|
|
2019-11-24 10:59:00 +05:30
|
|
|
def test_Rodriques(self,default):
|
|
|
|
for rot in default:
|
2019-11-22 02:18:54 +05:30
|
|
|
assert np.allclose(rot.asMatrix(),
|
|
|
|
Rotation.fromRodrigues(rot.asRodrigues()).asMatrix())
|
2019-11-22 01:31:01 +05:30
|
|
|
|
2019-11-24 10:59:00 +05:30
|
|
|
def test_Homochoric(self,default):
|
|
|
|
for rot in default:
|
2019-11-22 02:18:54 +05:30
|
|
|
assert np.allclose(rot.asRodrigues(),
|
2020-01-14 15:27:50 +05:30
|
|
|
Rotation.fromHomochoric(rot.asHomochoric()).asRodrigues(),rtol=1.e-4)
|
2019-11-22 01:31:01 +05:30
|
|
|
|
2019-11-24 10:59:00 +05:30
|
|
|
def test_Cubochoric(self,default):
|
|
|
|
for rot in default:
|
2019-11-22 02:18:54 +05:30
|
|
|
assert np.allclose(rot.asHomochoric(),
|
2020-01-14 15:27:50 +05:30
|
|
|
Rotation.fromCubochoric(rot.asCubochoric()).asHomochoric())
|
2019-11-22 01:31:01 +05:30
|
|
|
|
2019-11-24 10:59:00 +05:30
|
|
|
def test_Quaternion(self,default):
|
|
|
|
for rot in default:
|
2019-11-22 02:18:54 +05:30
|
|
|
assert np.allclose(rot.asCubochoric(),
|
2020-01-14 15:27:50 +05:30
|
|
|
Rotation.fromQuaternion(rot.asQuaternion()).asCubochoric())
|
2019-12-09 01:59:26 +05:30
|
|
|
|
|
|
|
|
|
|
|
@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):
|
|
|
|
ori = Orientation(Rotation.fromRandom(),lattice)
|
|
|
|
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
|
|
|
|
|
2019-12-09 02:18:32 +05:30
|
|
|
@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)
|
|
|
|
eu = np.array([o.rotation.asEulers(degrees=True) for o in ori.relatedOrientations(model)])
|
|
|
|
if update:
|
2019-12-09 02:27:07 +05:30
|
|
|
coords = np.array([(1,i+1) for i,x in enumerate(eu)])
|
2019-12-09 02:18:32 +05:30
|
|
|
table = damask.Table(eu,{'Eulers':(3,)})
|
2019-12-09 02:27:07 +05:30
|
|
|
table.add('pos',coords)
|
2019-12-09 02:18:32 +05:30
|
|
|
table.to_ASCII(reference)
|
|
|
|
assert np.allclose(eu,damask.Table.from_ASCII(reference).get('Eulers'))
|