23 #ifdef USE_FACTORY_AUTOREGISTER
33 bool RandomNumbers::init_factory()
37 result &= RandomNumbers_Mseries::register_factory();
38 result &= RandomNumbers_MT19937::register_factory();
40 result &= RandomNumbers_SFMT::register_factory();
53 const double sq2r = 1.0 / sqrt(2.0);
55 const double pi = 4.0 * atan(1.0);
56 const double pi2 = 2.0 * pi;
68 double slg1 = sqrt(-log(1.0 - r1) * 2.0) * sq2r;
69 double ang1 = pi2 * r2;
71 rand1 = slg1 * cos(ang1);
72 rand2 = slg1 * sin(ang1);
79 if (str_rand_type ==
"Gaussian") {
81 }
else if (str_rand_type ==
"Uniform") {
83 }
else if (str_rand_type ==
"U1") {
85 }
else if (str_rand_type ==
"Z2") {
97 if (f.
nin() % 2 == 0) {
98 return generate_global<rand_gauss_even>(f);
100 return generate_global<rand_gauss_odd>(f);
108 return generate_global<rand_uniform>(f);
118 const int Nex = f.
nex();
119 const int Nvol = f.
nvol();
120 const int Nin = f.
nin();
122 assert(Nin % 2 == 0);
124 for (
int ex = 0; ex < Nex; ++ex) {
125 for (
int site = 0; site < Nvol; ++site) {
126 for (
int in_half = 0; in_half < Nin / 2; ++in_half) {
127 int idx_r = 2 * in_half;
128 int idx_i = 2 * in_half + 1;
131 double arg = atan2(f.
cmp(idx_i, site, ex), f.
cmp(idx_r, site, ex));
133 f.
set(idx_r, site, ex, cos(arg));
134 f.
set(idx_i, site, ex, sin(arg));
145 generate_global<rand_uniform>(f);
147 const int Nex = f.
nex();
148 const int Nvol = f.
nvol();
149 const int Nin = f.
nin();
151 assert(Nin % 2 == 0);
153 double RF2 = 1.0 / sqrt(2.0);
155 for (
int ex = 0; ex < Nex; ++ex) {
156 for (
int site = 0; site < Nvol; ++site) {
157 for (
int in = 0; in < Nin; ++in) {
158 double rn1 = f.
cmp(in, site, ex);
159 double rn2 = floor(2.0 * rn1);
160 double rn3 = (2.0 * rn2 - 1.0) * RF2;
161 f.
set(in, site, ex, rn3);
184 for (
size_t i = 0; i <
m_block; i += 2) {
188 double slg1 = sqrt(-log(1 - r1) * 2.0) * sq2r;
189 double ang1 = pi2 * r2;
191 *
m_ptr++ = slg1 * cos(ang1);
192 *
m_ptr++ = slg1 * sin(ang1);
196 for (
size_t i = 0; i <
m_block; i += 2) {
214 size_t ngauss = m_block / 2;
216 for (
size_t i = 0; i < ngauss; ++i) {
217 double r1 = m_rand_gauss->get();
218 double r2 = m_rand_gauss->get();
220 double slg1 = sqrt(-log(1 - r1) * 2.0) * sq2r;
221 double ang1 = pi2 * r2;
223 *m_ptr++ = slg1 * cos(ang1);
224 *m_ptr++ = slg1 * sin(ang1);
229 double r1 = m_rand_gauss->get();
230 double r2 = m_rand_gauss->get();
232 double slg1 = sqrt(-log(1 - r1) * 2.0) * sq2r;
233 double ang1 = pi2 * r2;
235 *m_ptr++ = slg1 * cos(ang1);
239 for (
size_t i = 0; i < m_block + 1; ++i) {
256 for (
size_t i = 0; i < m_block; ++i) {
257 *m_ptr++ = m_rand_gauss->get();
260 for (
size_t i = 0; i < m_block; ++i) {
274 template<
typename InnerGenerator>
277 InnerGenerator fill(f,
this);
279 const int Nin = f.
nin();
280 const int Nvol = f.
nvol();
281 const int Nex = f.
nex();
286 for (
int j = 0; j < Nex; ++j) {
287 for (
int i = 0; i < Nvol; ++i) {
309 for (
int j = 0; j < Nex; ++j) {
312 for (
int t = 0; t < Lt; ++t) {
313 bool in_t = in_j && (t >= ipe_t * Nt) && (t < (ipe_t + 1) * Nt);
315 for (
int z = 0; z < Lz; ++z) {
316 bool in_z = in_t && (z >= ipe_z * Nz) && (z < (ipe_z + 1) * Nz);
318 for (
int y = 0; y < Ly; ++y) {
319 bool in_y = in_z && (y >= ipe_y * Ny) && (y < (ipe_y + 1) * Ny);
321 for (
int x = 0; x < Lx; ++x) {
322 bool in_x = in_y && (x >= ipe_x * Nx) && (x < (ipe_x + 1) * Nx);
RandomNumbers * m_rand_gauss
void detailed(const char *format,...)
void set(const int jin, const int site, const int jex, double v)
virtual void uniform_lex_global(Field &)
uniform random number defined on global lattice.
Container of Field-type object.
virtual void U1_lex_global(Field &)
U(1) random number defined on global lattice.
double cmp(const int jin, const int site, const int jex) const
static int ipe(const int dir)
logical coordinate of current proc.
static const std::string class_name
void convertField(Field &eo, const Field &lex)
virtual void gauss_lex_global(Field &)
gaussian random number defined on global lattice.
Bridge::VerboseLevel m_vl
virtual void gauss_eo_global(Field &)
gaussian noise for even-odd perconditioned field (S.UEDA)
size_t block_size() const
size_t block_size() const
void operator()(const bool do_fill)
void crucial(const char *format,...)
void operator()(const bool do_fill)
static int size()
size of small world.
virtual void lex_global(const std::string &, Field &)
virtual void Z2_lex_global(Field &)
Z(2) random number defined on global lattice.
void generate_global(Field &f)
void gauss(double &rand1, double &rand2)