From 6e27a140f66796e47072897c9d0659323127342f Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 30 Jun 2020 17:35:52 +0200 Subject: [PATCH] better split --- python/tests/conftest.py | 79 +++++++++++++++++++++++++++++++++++ python/tests/test_Rotation.py | 77 ---------------------------------- 2 files changed, 79 insertions(+), 77 deletions(-) diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 411c07a8c..78ebea2a5 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -1,7 +1,10 @@ import os +import numpy as np import pytest +from damask import Rotation + def pytest_addoption(parser): parser.addoption("--update", action="store_true", @@ -16,3 +19,79 @@ def update(request): def reference_dir_base(): """Directory containing reference results.""" return os.path.join(os.path.dirname(__file__),'reference') + +@pytest.fixture +def set_of_rotations(): + """A set of n random rotations.""" + n = 1100 + scatter=1.e-2 + specials = np.array([ + [1.0, 0.0, 0.0, 0.0], + #---------------------- + [0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 1.0, 0.0], + [0.0, 0.0, 0.0, 1.0], + [0.0,-1.0, 0.0, 0.0], + [0.0, 0.0,-1.0, 0.0], + [0.0, 0.0, 0.0,-1.0], + #---------------------- + [1.0, 1.0, 0.0, 0.0], + [1.0, 0.0, 1.0, 0.0], + [1.0, 0.0, 0.0, 1.0], + [0.0, 1.0, 1.0, 0.0], + [0.0, 1.0, 0.0, 1.0], + [0.0, 0.0, 1.0, 1.0], + #---------------------- + [1.0,-1.0, 0.0, 0.0], + [1.0, 0.0,-1.0, 0.0], + [1.0, 0.0, 0.0,-1.0], + [0.0, 1.0,-1.0, 0.0], + [0.0, 1.0, 0.0,-1.0], + [0.0, 0.0, 1.0,-1.0], + #---------------------- + [0.0, 1.0,-1.0, 0.0], + [0.0, 1.0, 0.0,-1.0], + [0.0, 0.0, 1.0,-1.0], + #---------------------- + [0.0,-1.0,-1.0, 0.0], + [0.0,-1.0, 0.0,-1.0], + [0.0, 0.0,-1.0,-1.0], + #---------------------- + [1.0, 1.0, 1.0, 0.0], + [1.0, 1.0, 0.0, 1.0], + [1.0, 0.0, 1.0, 1.0], + [1.0,-1.0, 1.0, 0.0], + [1.0,-1.0, 0.0, 1.0], + [1.0, 0.0,-1.0, 1.0], + [1.0, 1.0,-1.0, 0.0], + [1.0, 1.0, 0.0,-1.0], + [1.0, 0.0, 1.0,-1.0], + [1.0,-1.0,-1.0, 0.0], + [1.0,-1.0, 0.0,-1.0], + [1.0, 0.0,-1.0,-1.0], + #---------------------- + [0.0, 1.0, 1.0, 1.0], + [0.0, 1.0,-1.0, 1.0], + [0.0, 1.0, 1.0,-1.0], + [0.0,-1.0, 1.0, 1.0], + [0.0,-1.0,-1.0, 1.0], + [0.0,-1.0, 1.0,-1.0], + [0.0,-1.0,-1.0,-1.0], + #---------------------- + [1.0, 1.0, 1.0, 1.0], + [1.0,-1.0, 1.0, 1.0], + [1.0, 1.0,-1.0, 1.0], + [1.0, 1.0, 1.0,-1.0], + [1.0,-1.0,-1.0, 1.0], + [1.0,-1.0, 1.0,-1.0], + [1.0, 1.0,-1.0,-1.0], + [1.0,-1.0,-1.0,-1.0], + ]) + specials /= np.linalg.norm(specials,axis=1).reshape(-1,1) + specials_scatter = specials + np.broadcast_to(np.random.rand(4)*scatter,specials.shape) + specials_scatter /= np.linalg.norm(specials_scatter,axis=1).reshape(-1,1) + specials_scatter[specials_scatter[:,0]<0]*=-1 + + return [Rotation.from_quaternion(s) for s in specials] + \ + [Rotation.from_quaternion(s) for s in specials_scatter] + \ + [Rotation.from_random() for _ in range(n-len(specials)-len(specials_scatter))] diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index b087cc774..6acca8e79 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -9,83 +9,6 @@ from damask import _rotation n = 1000 atol=1.e-4 - -@pytest.fixture -def set_of_rotations(): - """A set of n random rotations.""" - n = 1100 - scatter=1.e-2 - specials = np.array([ - [1.0, 0.0, 0.0, 0.0], - #---------------------- - [0.0, 1.0, 0.0, 0.0], - [0.0, 0.0, 1.0, 0.0], - [0.0, 0.0, 0.0, 1.0], - [0.0,-1.0, 0.0, 0.0], - [0.0, 0.0,-1.0, 0.0], - [0.0, 0.0, 0.0,-1.0], - #---------------------- - [1.0, 1.0, 0.0, 0.0], - [1.0, 0.0, 1.0, 0.0], - [1.0, 0.0, 0.0, 1.0], - [0.0, 1.0, 1.0, 0.0], - [0.0, 1.0, 0.0, 1.0], - [0.0, 0.0, 1.0, 1.0], - #---------------------- - [1.0,-1.0, 0.0, 0.0], - [1.0, 0.0,-1.0, 0.0], - [1.0, 0.0, 0.0,-1.0], - [0.0, 1.0,-1.0, 0.0], - [0.0, 1.0, 0.0,-1.0], - [0.0, 0.0, 1.0,-1.0], - #---------------------- - [0.0, 1.0,-1.0, 0.0], - [0.0, 1.0, 0.0,-1.0], - [0.0, 0.0, 1.0,-1.0], - #---------------------- - [0.0,-1.0,-1.0, 0.0], - [0.0,-1.0, 0.0,-1.0], - [0.0, 0.0,-1.0,-1.0], - #---------------------- - [1.0, 1.0, 1.0, 0.0], - [1.0, 1.0, 0.0, 1.0], - [1.0, 0.0, 1.0, 1.0], - [1.0,-1.0, 1.0, 0.0], - [1.0,-1.0, 0.0, 1.0], - [1.0, 0.0,-1.0, 1.0], - [1.0, 1.0,-1.0, 0.0], - [1.0, 1.0, 0.0,-1.0], - [1.0, 0.0, 1.0,-1.0], - [1.0,-1.0,-1.0, 0.0], - [1.0,-1.0, 0.0,-1.0], - [1.0, 0.0,-1.0,-1.0], - #---------------------- - [0.0, 1.0, 1.0, 1.0], - [0.0, 1.0,-1.0, 1.0], - [0.0, 1.0, 1.0,-1.0], - [0.0,-1.0, 1.0, 1.0], - [0.0,-1.0,-1.0, 1.0], - [0.0,-1.0, 1.0,-1.0], - [0.0,-1.0,-1.0,-1.0], - #---------------------- - [1.0, 1.0, 1.0, 1.0], - [1.0,-1.0, 1.0, 1.0], - [1.0, 1.0,-1.0, 1.0], - [1.0, 1.0, 1.0,-1.0], - [1.0,-1.0,-1.0, 1.0], - [1.0,-1.0, 1.0,-1.0], - [1.0, 1.0,-1.0,-1.0], - [1.0,-1.0,-1.0,-1.0], - ]) - specials /= np.linalg.norm(specials,axis=1).reshape(-1,1) - specials_scatter = specials + np.broadcast_to(np.random.rand(4)*scatter,specials.shape) - specials_scatter /= np.linalg.norm(specials_scatter,axis=1).reshape(-1,1) - specials_scatter[specials_scatter[:,0]<0]*=-1 - - return [Rotation.from_quaternion(s) for s in specials] + \ - [Rotation.from_quaternion(s) for s in specials_scatter] + \ - [Rotation.from_random() for _ in range(n-len(specials)-len(specials_scatter))] - @pytest.fixture def reference_dir(reference_dir_base): """Directory containing reference results."""