11 #include <hpp/external/ISOI/grid_generation.h> 50 alpha(alpha), beta(beta), gamma(gamma) {;}
64 MPI_Type_contiguous(3, MPIType<T>(), &dtype);
65 MPI_Type_commit(&dtype);
79 angles.
gamma = M_PI/2;
82 angles.
beta = M_PI/2-phi;
92 std::ostream& operator<<(std::ostream& out, const EulerAngles<T>& angles)
95 out << angles.
alpha <<
",";
96 out << angles.beta <<
",";
102 template <
typename T>
112 template <
typename T>
117 template <
typename T>
120 T c1 = std::cos(alpha);
121 T c2 = std::cos(beta);
122 T c3 = std::cos(gamma);
123 T s1 = std::sin(alpha);
124 T s2 = std::sin(beta);
125 T s3 = std::sin(gamma);
126 R(0,0) = c1*c3 - c2*s1*s3;
127 R(0,1) = -c1*s3 - c2*c3*s1;
129 R(1,0) = c3*s1 + c1*c2*s3;
130 R(1,1) = c1*c2*c3 - s1*s3;
138 template <
typename T>
148 template <
typename T>
154 angle.
beta = std::acos(R(2,2));
156 if (angle.
beta > 1e3*std::numeric_limits<T>::epsilon()) {
158 angle.
alpha = std::atan2(R(0,2),-R(1,2));
159 angle.
gamma = std::atan2(R(2,0),R(2,1));
164 T alphaPlusGamma = std::atan2(-R(0,1), R(0,0));
167 angle.
alpha = alphaPlusGamma/2.0;
168 angle.
gamma = alphaPlusGamma/2.0;
186 return std::mt19937();
189 std::random_device rd;
190 return std::mt19937(rd());
195 template <
typename T>
198 static std::vector<T> v(3);
203 R(0,0) = std::cos(2*M_PI*x1);
205 R(0,1) = std::sin(2*M_PI*x1);
210 v[0] = std::cos(2*M_PI*x2)*std::sqrt(x3);
211 v[1] = std::sin(2*M_PI*x2)*std::sqrt(x3);
212 v[2] = std::sqrt(1-x3);
225 template <
typename T>
228 static std::vector<T> v(3);
235 static std::uniform_real_distribution<double> dist(0.0,1.0);
246 template <
typename T>
249 static std::mt19937 gen =
makeMt19937(defaultSeed);
255 template <
typename T>
276 template <
typename T>
279 static std::mt19937 gen =
makeMt19937(defaultSeed);
282 std::normal_distribution<T> dist(0.0,1.0);
286 std::vector<T> D = ones<T>(dim);
287 for (
unsigned int n=1; n<dim; n++) {
288 std::valarray<T> x(dim-n+1);
289 for (
unsigned int i=0; i<dim-n+1; i++) {
292 D[n-1] = std::copysign(1.0, x[0]);
293 x[0] -= D[n-1]*std::sqrt((x*x).sum());
296 Tensor2<T> Hx = identityTensor2<T>(dim-n+1) - (T)2.0*
outer(x, x)/(x*x).sum();
298 for (
unsigned int i=n-1; i<dim; i++) {
299 for (
unsigned int j=n-1; j<dim; j++) {
300 mat(i,j) = Hx(i-n+1,j-n+1);
308 H = (D*H.
trans()).trans();
320 template <
typename T>
324 randomRotationTensorArvo1992<T>(A, defaultSeed);
327 A = randomRotationTensorStewart1980<T>(dim, defaultSeed);
333 std::cerr <<
"Warning: random rotation tensor didn't pass check. Re-generating." << std::endl;
334 randomRotationTensorInPlace<T>(dim, A, defaultSeed);
339 template <
typename T>
343 randomRotationTensorInPlace<T>(dim, A, defaultSeed);
351 template <
typename T>
358 angles.
alpha = std::atan2(2*(q0*q1+q2*q3), 1-2*(std::pow(q1,2.)+std::pow(q2,2.)));
359 angles.
beta = std::asin(2*(q0*q2-q3*q1));
360 angles.
gamma = std::atan2(2*(q0*q3+q1*q2), 1-2*(std::pow(q2,2.)+std::pow(q3,2.)));
375 template <
typename T>
380 isoi::Quaternion
getQuat(
unsigned int i) {
return quatList[i];}
382 unsigned int size() {
return quatList.size();}
void setBeta(const T &beta)
Definition: rotation.h:57
T alpha
Definition: rotation.h:44
Tensor2< T > outer(const std::vector< T > &A, const std::vector< T > &B)
Definition: tensor.h:640
T getBeta() const
Definition: rotation.h:54
EulerAngles< T > getEulerAngle(unsigned int i)
Definition: rotation.h:381
T beta
Definition: rotation.h:45
void rotationTensorFrom3UniformRandomsArvo1992(Tensor2< T > &A, T x1, T x2, T x3)
Definition: rotation.h:196
Definition: casesUtils.cpp:4
Tensor2< T > randomRotationTensorStewart1980(unsigned int dim, bool defaultSeed=false)
Generate a random rotation tensor.
Definition: rotation.h:277
std::vector< isoi::Quaternion > quatList
Definition: rotation.h:385
Definition: rotation.h:18
Tensor2< T > EulerZXZRotationMatrix(T alpha, T beta, T gamma)
Definition: rotation.h:118
Tensor2< T > randomRotationTensor(unsigned int dim, bool defaultSeed=false)
Definition: rotation.h:340
SymmetryType
Definition: rotation.h:17
HPP_NVCC_ONLY(__host__ __device__) EulerAngles()
Definition: rotation.h:48
Definition: rotation.h:376
void setAlpha(const T &alpha)
Definition: rotation.h:56
void rotationTensorFrom3UniformRandoms(Tensor2< T > &A, T x1, T x2, T x3)
Definition: rotation.h:256
SymmetryType symmetryType
Definition: rotation.h:384
Header file for tensor classes.
bool operator==(const SpectralDatasetID &l, const SpectralDatasetID &r)
Definition: spectralUtils.cpp:132
A class for second order tensors.
Definition: tensor.h:303
void setGamma(const T &gamma)
Definition: rotation.h:58
MPI_Datatype getEulerAnglesTypeMPI()
Definition: rotation.h:62
bool isRotationMatrix() const
Definition: tensor.cpp:342
void randomRotationTensorArvo1992(std::mt19937 &gen, Tensor2< T > &A)
Definition: rotation.h:226
EulerAngles< T > polarToEuler(T theta, T phi)
Convert polar angles to Euler angles.
Definition: rotation.h:76
std::mt19937 makeMt19937(bool defaultSeed)
Definition: rotation.h:184
std::vector< EulerAngles< T > > eulerAngleList
Definition: rotation.h:386
void outerInPlace(const std::vector< T > &A, const std::vector< T > &B, Tensor2< T > &C)
Definition: tensor.h:653
T gamma
Definition: rotation.h:46
bool operator!=(const EulerAngles< T > &l, const EulerAngles< T > &r)
Definition: rotation.h:113
Tensor2< T > trans() const
The transpose of the tensor.
Definition: tensor.cpp:536
SO3Discrete()
Definition: rotation.h:378
isoi::Quaternion getQuat(unsigned int i)
Definition: rotation.h:380
EulerAngles< T > getEulerZXZAngles(Tensor2< T > R)
Get Euler angles from rotation matrix.
Definition: rotation.h:149
T getAlpha() const
Definition: rotation.h:53
EulerAngles< T > quaternionToEulerAngles(isoi::Quaternion &q)
Definition: rotation.h:352
T prod(const std::vector< T > &vec)
Product of all the entries of a vector.
Definition: tensor.h:128
T getGamma() const
Definition: rotation.h:55
void randomRotationTensorInPlace(unsigned int dim, Tensor2< T > &A, bool defaultSeed=false)
Generate a random rotation tensor.
Definition: rotation.h:321
Definition: rotation.h:43
Definition: rotation.h:19
unsigned int size()
Definition: rotation.h:382