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-11-22 01:31:01 +05:30
|
|
|
from damask import Rotation
|
2020-04-08 17:11:46 +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."""
|
2020-04-08 17:11:46 +05:30
|
|
|
specials =[np.array([ 1.0, 0.0, 0.0, 0.0]),
|
|
|
|
#-----------------------------------------------
|
|
|
|
np.array([ 1.0, 1.0, 0.0, 0.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 1.0, 0.0, 1.0, 0.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 1.0, 0.0, 0.0, 1.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0, 1.0, 1.0, 0.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0, 1.0, 0.0, 1.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0, 0.0, 1.0, 1.0])*np.sqrt(2.)*.5,
|
|
|
|
#-----------------------------------------------
|
|
|
|
np.array([ 1.0,-1.0, 0.0, 0.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 1.0, 0.0,-1.0, 0.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 1.0, 0.0, 0.0,-1.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0, 1.0,-1.0, 0.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0, 1.0, 0.0,-1.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0, 0.0, 1.0,-1.0])*np.sqrt(2.)*.5,
|
|
|
|
#-----------------------------------------------
|
|
|
|
np.array([ 0.0, 1.0,-1.0, 0.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0, 1.0, 0.0,-1.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0, 0.0, 1.0,-1.0])*np.sqrt(2.)*.5,
|
|
|
|
#-----------------------------------------------
|
|
|
|
np.array([ 0.0,-1.0,-1.0, 0.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0,-1.0, 0.0,-1.0])*np.sqrt(2.)*.5,
|
|
|
|
np.array([ 0.0, 0.0,-1.0,-1.0])*np.sqrt(2.)*.5,
|
|
|
|
#-----------------------------------------------
|
|
|
|
]
|
|
|
|
return [Rotation.fromQuaternion(s) for s in specials] + \
|
|
|
|
[Rotation.fromRandom() for r in range(n-len(specials))]
|
2019-11-24 10:59:00 +05:30
|
|
|
|
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:
|
2020-04-08 17:11:46 +05:30
|
|
|
c = Rotation.fromEulers(rot.asEulers())
|
|
|
|
ok = np.allclose(rot.asQuaternion(),c.asQuaternion())
|
|
|
|
if np.isclose(rot.asQuaternion()[0],0.0,atol=1.e-13,rtol=0.0):
|
|
|
|
ok = ok or np.allclose(rot.asQuaternion(),c.asQuaternion()*-1.)
|
|
|
|
assert ok
|
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:
|
2020-04-08 17:11:46 +05:30
|
|
|
c = Rotation.fromAxisAngle(rot.asAxisAngle())
|
|
|
|
assert np.allclose(rot.asEulers(),c.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:
|
2020-04-08 17:11:46 +05:30
|
|
|
c = Rotation.fromMatrix(rot.asMatrix())
|
|
|
|
ok = np.allclose(rot.asAxisAngle(),c.asAxisAngle())
|
|
|
|
if np.isclose(rot.asAxisAngle()[3],np.pi):
|
|
|
|
ok = ok or np.allclose(rot.asAxisAngle(),c.asAxisAngle()*np.array([-1.,-1.,-1.,1.]))
|
|
|
|
assert ok
|
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:
|
2020-04-08 17:11:46 +05:30
|
|
|
c = Rotation.fromRodrigues(rot.asRodrigues())
|
|
|
|
assert np.allclose(rot.asMatrix(),c.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:
|
2020-04-08 17:11:46 +05:30
|
|
|
c = Rotation.fromHomochoric(rot.asHomochoric())
|
|
|
|
assert np.allclose(np.clip(rot.asRodrigues(),None,1.e9),np.clip(c.asRodrigues(),None,1.e9))
|
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:
|
2020-04-08 17:11:46 +05:30
|
|
|
c = Rotation.fromCubochoric(rot.asCubochoric())
|
|
|
|
assert np.allclose(rot.asHomochoric(),c.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:
|
2020-04-08 17:11:46 +05:30
|
|
|
c = Rotation.fromQuaternion(rot.asQuaternion())
|
|
|
|
assert np.allclose(rot.asCubochoric(),c.asCubochoric())
|