QMCPACK
RandomSeqGeneratorGlobal.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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef QMCPLUSPLUS_RANDOMSEQUENCEGENERATORGLOBAL_H
16 #define QMCPLUSPLUS_RANDOMSEQUENCEGENERATORGLOBAL_H
17 
18 #include <algorithm>
19 #include <RandomGenerator.h>
20 #include "RandomSeqGenerator.h"
21 
22 namespace qmcplusplus
23 {
24 template<typename T, unsigned D>
25 inline void makeGaussRandom(std::vector<TinyVector<T, D>>& a)
26 {
27  assignGaussRand(&(a[0][0]), a.size() * D, Random);
28 }
29 
30 ///specialized functions: stick to overloading
31 template<typename T, unsigned D>
33 {
34  assignGaussRand(&(a(0, 0)[0]), a.size() * D, Random);
35 }
36 
37 template<typename T, unsigned D>
39 {
40  assignGaussRand(&(a[0][0]), a.size() * D, Random);
41 }
42 
43 template<typename T>
45 {
46  assignGaussRand(&(a[0]), a.size(), Random);
47 }
48 
49 template<typename T, unsigned D>
51 {
52  assignUniformRand(&(a[0][0]), a.size() * D, Random);
53 }
54 
55 template<typename T>
57 {
58  assignUniformRand(&(a[0]), a.size(), Random);
59 }
60 
61 template<typename T>
63 {
64  for (int i = 0; i < a.size(); i++)
65  {
66  bool failed = true;
67  while (failed)
68  {
69  T x = 1.0 - 2.0 * Random();
70  T y = 1.0 - 2.0 * Random();
71  T z = 1.0 - 2.0 * Random();
72  T sep = std::sqrt(x * x + y * y + z * z);
73  if (sep < 1)
74  {
75  T rinv = 1.0 / sep;
76  a[i][0] = x * rinv;
77  a[i][1] = y * rinv;
78  a[i][2] = z * rinv;
79  failed = false;
80  }
81  }
82  }
83 }
84 
85 template<typename T>
87 {
88  for (int i = 0; i < a.size(); i++)
89  {
90  bool failed = true;
91  while (failed)
92  {
93  T x = 1.0 - 2.0 * Random();
94  T y = 1.0 - 2.0 * Random();
95  T sep = std::sqrt(x * x + y * y);
96  if (sep < 1)
97  {
98  T rinv = 1.0 / sep;
99  a[i][0] = x * rinv;
100  a[i][1] = y * rinv;
101  failed = false;
102  }
103  }
104  }
105 }
106 
107 } // namespace qmcplusplus
108 
109 
110 #endif
void makeUniformRandom(ParticleAttrib< TinyVector< T, D >> &a)
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
#define Random
Attaches a unit to a Vector for IO.
void assignGaussRand(T *restrict a, unsigned n, RG &rng)
size_type size() const
return the current size
Definition: OhmmsVector.h:162
void makeSphereRandom(ParticleAttrib< TinyVector< T, 3 >> &a)
void makeGaussRandom(std::vector< TinyVector< T, D >> &a)
void assignUniformRand(T *restrict a, unsigned n, RG &rng)
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
Declare a global Random Number Generator.