Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
randomNumbers.h
Go to the documentation of this file.
1 
14 #ifndef RANDOMNUMBERS_INCLUDED
15 #define RANDOMNUMBERS_INCLUDED
16 
17 #include "Field/field.h"
18 
19 #include "IO/bridgeIO.h"
20 using Bridge::vout;
21 
22 #ifdef USE_FACTORY
23 #include "Tools/factory.h"
24 #endif
25 
26 
28 
44 {
45  public:
46  static const std::string class_name;
47 
48  protected:
50 
51  public:
52 
54  : m_vl(CommonParameters::Vlevel()) {}
55 
56  virtual ~RandomNumbers() {}
57 
58  private:
59  // non-copyable
62 
63  public:
65 
66  virtual double get() = 0;
67 
68  void gauss(double& rand1, double& rand2);
69 
70 
71  virtual void lex_global(const std::string&, Field&);
72 
74  virtual void gauss_lex_global(Field&);
75 
77  virtual void uniform_lex_global(Field&);
78 
80  virtual void U1_lex_global(Field&);
81 
83  virtual void Z2_lex_global(Field&);
84 
85 
87  virtual void gauss_eo_global(Field&);
88 
89 
91  virtual void read_file(const std::string&) = 0;
92  virtual void write_file(const std::string&) = 0;
93 
95  virtual void reset(unsigned long seed) = 0;
96 
97 
98  protected:
100  {
101  public:
103  : m_rand_gauss(rand_gauss), m_ptr(f.ptr(0)), m_block(f.nin()) {}
104  void operator()(const bool do_fill);
105  size_t block_size() const;
106 
107  private:
109  double *m_ptr;
110  size_t m_block;
111  };
112 
114  {
115  public:
117  : m_rand_gauss(rand_gauss), m_ptr(f.ptr(0)), m_block(f.nin()) {}
118  void operator()(const bool do_fill);
119  size_t block_size() const;
120 
121  private:
123  double *m_ptr;
124  size_t m_block;
125  };
126 
128  {
129  public:
131  : m_rand_gauss(rand_gauss), m_ptr(f.ptr(0)), m_block(f.nin()) {}
132  void operator()(const bool do_fill);
133  size_t block_size() const;
134 
135  private:
137  double *m_ptr;
138  size_t m_block;
139  };
140 
141  private:
142  template<typename InnerGenerator>
143  void generate_global(Field& f);
144 
145 #ifdef USE_FACTORY
146  public:
147  typedef RandomNumbers *(*ProductCreator_int)(const int& iseed);
148  typedef RandomNumbers *(*ProductCreator_file)(const std::string& filename);
149 
152 
153  static RandomNumbers *New(const IdentifierType& subtype, const int& iseed)
154  {
155  ProductCreator_int p = Factory_int::Find(subtype);
156 
157  return p ? (*p)(iseed) : 0;
158  }
159 
160  static RandomNumbers *New(const IdentifierType& subtype, const std::string& filename)
161  {
162  ProductCreator_file p = Factory_file::Find(subtype);
163 
164  return p ? (*p)(filename) : 0;
165  }
166 
167 #ifdef USE_FACTORY_AUTOREGISTER
168 #else
169  static bool init_factory();
170 #endif
171 #endif
172 };
173 #endif
BridgeIO vout
Definition: bridgeIO.cpp:503
void set_parameter_verboselevel(const Bridge::VerboseLevel vl)
Definition: randomNumbers.h:64
virtual void uniform_lex_global(Field &)
uniform random number defined on global lattice.
Container of Field-type object.
Definition: field.h:45
virtual void U1_lex_global(Field &)
U(1) random number defined on global lattice.
RandomNumbers & operator=(const RandomNumbers &)
virtual void write_file(const std::string &)=0
static const std::string class_name
Definition: randomNumbers.h:46
virtual ~RandomNumbers()
Definition: randomNumbers.h:56
virtual void gauss_lex_global(Field &)
gaussian random number defined on global lattice.
RandomNumbers * m_rand_gauss
Bridge::VerboseLevel m_vl
Definition: randomNumbers.h:49
void operator()(const bool do_fill)
virtual void gauss_eo_global(Field &)
gaussian noise for even-odd perconditioned field (S.UEDA)
rand_gauss_even(Field &f, RandomNumbers *rand_gauss)
Common parameter class: provides parameters as singleton.
virtual void reset(unsigned long seed)=0
reset state with new seed.
void operator()(const bool do_fill)
virtual void read_file(const std::string &)=0
save and load random number status.
void operator()(const bool do_fill)
Base class of random number generators.
Definition: randomNumbers.h:43
virtual void lex_global(const std::string &, Field &)
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
virtual void Z2_lex_global(Field &)
Z(2) random number defined on global lattice.
void generate_global(Field &f)
std::string IdentifierType
Factory template class.
Definition: factory.h:39
rand_gauss_odd(Field &f, RandomNumbers *rand_gauss)
rand_uniform(Field &f, RandomNumbers *rand_gauss)
void gauss(double &rand1, double &rand2)