From e0f3fe3cc0e3e35a90a9fd19205409f075cecff4 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 21 Nov 2019 21:01:01 +0100 Subject: [PATCH] ported from hand written test class --- python/tests/test_Rotation.py | 54 ++++++++++++++++++++++++++++++++++ python/tests/test_mechanics.py | 9 +++++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 python/tests/test_Rotation.py diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py new file mode 100644 index 000000000..c0834f9a8 --- /dev/null +++ b/python/tests/test_Rotation.py @@ -0,0 +1,54 @@ +import numpy as np +from damask import Rotation + +class TestRotation: + + n = 1000 + + def test_Eulers(self): + for r in range(self.n): + rot = Rotation.fromRandom() + assert np.allclose(rot.asQuaternion(), + Rotation.fromEulers(rot.asEulers()).asQuaternion()) + + + def test_AxisAngle(self): + for r in range(self.n): + rot = Rotation.fromRandom() + assert np.allclose(rot.asEulers(), + Rotation.fromAxisAngle(rot.asAxisAngle()).asEulers()) + + + def test_Matrix(self): + for r in range(self.n): + rot = Rotation.fromRandom() + assert np.allclose(rot.asAxisAngle(), + Rotation.fromMatrix(rot.asMatrix()).asAxisAngle()) + + + def test_Rodriques(self): + for r in range(self.n): + rot = Rotation.fromRandom() + assert np.allclose(rot.asMatrix(), + Rotation.fromRodrigues(rot.asRodrigues()).asMatrix()) + + + def test_Homochoric(self): + for r in range(self.n): + rot = Rotation.fromRandom() + assert np.allclose(rot.asRodrigues(), + Rotation.fromHomochoric(rot.asHomochoric()).asRodrigues()) + + + def test_Cubochoric(self): + for r in range(self.n): + rot = Rotation.fromRandom() + assert np.allclose(rot.asHomochoric(), + Rotation.fromCubochoric(rot.asCubochoric()).asHomochoric()) + + + def test_Quaternion(self): + for r in range(self.n): + rot = Rotation.fromRandom() + assert np.allclose(rot.asCubochoric(), + Rotation.fromQuaternion(rot.asQuaternion()).asCubochoric()) diff --git a/python/tests/test_mechanics.py b/python/tests/test_mechanics.py index aeed1594a..aab92bef3 100644 --- a/python/tests/test_mechanics.py +++ b/python/tests/test_mechanics.py @@ -3,7 +3,7 @@ from damask import mechanics class TestMechanics: - n = 9 + n = 1000 c = np.random.randint(n) @@ -133,3 +133,10 @@ class TestMechanics: x = mechanics.symmetric(np.random.random((self.n,3,3))) assert np.allclose(mechanics.transpose(x), x) + + + def test_Mises(self): + """Ensure that equivalent stress is 3/2 of equivalent strain.""" + x = np.random.random((self.n,3,3)) + assert np.allclose(mechanics.Mises_stress(x)/mechanics.Mises_strain(x), + 1.5)