16 #ifdef USE_FACTORY_AUTOREGISTER
18 bool init = Source_Random::register_factory();
33 std::vector<int> source_position;
34 std::vector<int> source_momentum;
35 string str_noise_type;
40 err += params.
fetch_string(
"noise_type", str_noise_type);
65 const std::vector<int>& source_momentum,
66 const string str_noise_type)
70 const int t_dir = Ndim - 1;
73 std::vector<int> Lsize(Ndim);
85 for (
int mu = 0; mu < Ndim; ++mu) {
87 mu, source_position[mu]);
90 for (
int mu = 0; mu < Ndim - 1; ++mu) {
92 mu, source_momentum[mu]);
100 for (
int mu = 0; mu < Ndim; ++mu) {
113 for (
int mu = 0; mu < Ndim; ++mu) {
140 std::vector<int> Nsize(Ndim);
163 const int idx_r = 2 *
idx;
164 const int idx_i = 2 *
idx + 1;
169 for (
int z = 0; z < Nsize[2]; ++z) {
170 for (
int y = 0; y < Nsize[1]; ++y) {
171 for (
int x = 0; x < Nsize[0]; ++x) {
174 double rn_r = v.
cmp(idx_r, site, 0);
175 double rn_i = v.
cmp(idx_i, site, 0);
178 src.
set(idx_r, site, 0, rn_r);
179 src.
set(idx_i, site, 0, rn_i);
194 const int Lvol3 = Lx * Ly * Lz;
200 for (
int site = 0; site < Nvol; ++site) {
201 src1_r += src.
cmp(idx_r, site, 0);
202 src1_i += src.
cmp(idx_i, site, 0);
208 const double src2 = src.
norm2() / Lvol3;
218 const int idx = i_color + Nc * i_spin;
231 std::vector<int> Nsize(Ndim);
257 for (
int z = 0; z < Nsize[2]; ++z) {
258 for (
int y = 0; y < Nsize[1]; ++y) {
259 for (
int x = 0; x < Nsize[0]; ++x) {
262 for (
int i_color = 0; i_color < Nc; ++i_color) {
263 int idx = i_color + Nc * i_spin;
265 int idx_i = 2 *
idx + 1;
267 double rn_r = v.
cmp(idx_r, site, 0);
268 double rn_i = v.
cmp(idx_i, site, 0);
271 src.
set(idx_r, site, 0, rn_r);
272 src.
set(idx_i, site, 0, rn_i);
288 const int Lvol3 = Lx * Ly * Lz;
296 for (
int site = 0; site < Nvol; ++site) {
297 for (
int idx = 0;
idx < Nc * Nd; ++
idx) {
299 int idx_i = 2 *
idx + 1;
301 src1_r += src.
cmp(idx_r, site, 0);
302 src1_i += src.
cmp(idx_i, site, 0);
309 const double src2 = src.
norm2() / (Lvol3 * Nc * Nd);
323 std::vector<int> Nsize(Ndim);
349 for (
int z = 0; z < Nsize[2]; ++z) {
350 for (
int y = 0; y < Nsize[1]; ++y) {
351 for (
int x = 0; x < Nsize[0]; ++x) {
354 for (
int idx = 0;
idx < Nc * Nd; ++
idx) {
356 int idx_i = 2 *
idx + 1;
358 double rn_r = v.
cmp(idx_r, site, 0);
359 double rn_i = v.
cmp(idx_i, site, 0);
362 src.
set(idx_r, site, 0, rn_r);
363 src.
set(idx_i, site, 0, rn_i);
379 const int Lvol3 = Lx * Ly * Lz;
385 for (
int site = 0; site < Nvol; ++site) {
386 for (
int idx = 0;
idx < Nc * Nd; ++
idx) {
388 int idx_i = 2 *
idx + 1;
390 src1_r += src.
cmp(idx_r, site, 0);
391 src1_i += src.
cmp(idx_i, site, 0);
398 const double src2 = src.
norm2() / (Lvol3 * Nc * Nd);
410 int Nvol = src.
nvol();
414 assert(Nin >= 2 * nc);
415 int nd = Nin / nc / 2;
420 Field v(2, Nvol, Nex);
434 for (
int ex = 0; ex < Nex; ++ex) {
435 for (
int site = 0; site < Nvol; ++site) {
436 for (
int ri = 0; ri < 2; ++ri) {
437 rn = v.
cmp(ri, site, ex);
438 for (
int id = 0;
id < nd; ++id) {
439 int in = ri + 2 * (ic + nc * id);
443 src.
set(in, site, ex, rn);
458 int Nvol = src.
nvol();
463 assert(Nin == 2 * nc * nd);
465 Field v(2, Nvol, Nex);
483 for (
int ex = 0; ex < Nex; ++ex) {
484 for (
int site = 0; site < Nvol; ++site) {
485 for (
int ri = 0; ri < 2; ++ri) {
486 int in = ri + 2 * (ic + nc * is);
487 rn = v.
cmp(ri, site, ex);
491 src.
set(in, site, ex, rn);