QMCPACK
RotationMatrix3D.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2022 QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_ROTATION_MATRIX_3D_H
14 #define QMCPLUSPLUS_ROTATION_MATRIX_3D_H
15 
17 #include "config/stdlib/Constants.h" // For TWOPI
18 
19 namespace qmcplusplus
20 {
21 
22 /// Create a random 3D rotation matrix from three random numbers.
23 /// Each input random number should be in the range [0,1).
24 /// See the script Numerics/tests/derive_random_rotation.py for more information about the algorithm.
25 
26 template<typename T>
27 inline Tensor<T, 3> generateRotationMatrix(T rng1, T rng2, T rng3)
28 {
29  // The angular values for a random rotation matrix
30  // phi : 0 to 2*pi
31  // psi : 0 to 2*pi
32  // cth : -1 to 1 (cth = cos(theta))
33  T phi(TWOPI * rng1);
34  T psi(TWOPI * rng2);
35  T cth(1.0 - 2 * rng3);
36  T sph(std::sin(phi)), cph(std::cos(phi));
37  T sth(std::sqrt(1.0 - cth * cth));
38  T sps(std::sin(psi)), cps(std::cos(psi));
39  // clang-format off
40  return Tensor<T,3>( cph * cth * cps - sph * sps,
41  sph * cth * cps + cph * sps,
42  -sth * cps,
43  -cph * cth * sps - sph * cps,
44  -sph * cth * sps + cph * cps,
45  sth * sps,
46  cph * sth,
47  sph * sth,
48  cth);
49  // clang-format on
50 }
51 
52 } // namespace qmcplusplus
53 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
MakeReturn< UnaryNode< FnSin, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sin(const Vector< T1, C1 > &l)
MakeReturn< UnaryNode< FnCos, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t cos(const Vector< T1, C1 > &l)
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
Tensor< T, 3 > generateRotationMatrix(T rng1, T rng2, T rng3)
Create a random 3D rotation matrix from three random numbers.