Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
source_Wall.cpp
Go to the documentation of this file.
1 
14 #include "source_Wall.h"
15 
16 #ifdef USE_FACTORY_AUTOREGISTER
17 namespace {
18  bool init = Source_Wall::register_factory();
19 }
20 #endif
21 
22 const std::string Source_Wall::class_name = "Source_Wall";
23 
24 //====================================================================
26 {
27  const string str_vlevel = params.get_string("verbose_level");
28 
29  m_vl = vout.set_verbose_level(str_vlevel);
30 
31  //- fetch and check input parameters
32  std::vector<int> source_position;
33 
34  int err = 0;
35  err += params.fetch_int_vector("source_position", source_position);
36 
37  if (err) {
38  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
39  exit(EXIT_FAILURE);
40  }
41 
42 
43  set_parameters(source_position);
44 }
45 
46 
47 //====================================================================
48 void Source_Wall::set_parameters(const std::vector<int>& source_position)
49 {
50  // #### parameter setup ####
51  const int Ndim = CommonParameters::Ndim();
52 
53  //- global lattice size
54  std::vector<int> Lsize(Ndim);
55 
56  Lsize[0] = CommonParameters::Lx();
57  Lsize[1] = CommonParameters::Ly();
58  Lsize[2] = CommonParameters::Lz();
59  Lsize[3] = CommonParameters::Lt();
60 
61  //- local size
62  std::vector<int> Nsize(Ndim);
63  Nsize[0] = CommonParameters::Nx();
64  Nsize[1] = CommonParameters::Ny();
65  Nsize[2] = CommonParameters::Nz();
66  Nsize[3] = CommonParameters::Nt();
67 
68  const int t_dir = Ndim - 1;
69 
70  //- print input parameters
71  vout.general(m_vl, "Source for spinor field - Wall smeared:\n");
72  vout.general(m_vl, " source_position[t] = %d\n", source_position[t_dir]);
73 
74  //- range check
75  int err = 0;
76  // NB. Lsize[t_dir] > abs(source_position[t_dir])
77  err += ParameterCheck::non_negative(Lsize[t_dir] - abs(source_position[t_dir]));
78 
79  if (err) {
80  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
81  exit(EXIT_FAILURE);
82  }
83 
84  //- store values
85  m_source_position.resize(Ndim);
86  for (int mu = 0; mu < Ndim; ++mu) {
87  m_source_position[mu] = 0;
88  }
89  m_source_position[t_dir] = (source_position[t_dir] + Lsize[t_dir]) % Lsize[t_dir];
90 
91 
92  //- post-process
93 
94  //- PE location in t-direction.
95  int tpe = m_source_position[t_dir] / Nsize[t_dir];
96 
97  m_in_node = false;
98 
99  if (tpe == Communicator::ipe(t_dir)) {
100  m_in_node = true;
101  }
102 }
103 
104 
105 //====================================================================
106 void Source_Wall::set(Field& src, const int idx)
107 {
108  const int Ndim = CommonParameters::Ndim();
109 
110  //- global lattice size
111  const int Lx = CommonParameters::Lx();
112  const int Ly = CommonParameters::Ly();
113  const int Lz = CommonParameters::Lz();
114 
115  const int Lvol3 = Lx * Ly * Lz;
116 
117  //- local size
118  std::vector<int> Nsize(Ndim);
119 
120  Nsize[0] = CommonParameters::Nx();
121  Nsize[1] = CommonParameters::Ny();
122  Nsize[2] = CommonParameters::Nz();
123  Nsize[3] = CommonParameters::Nt();
124 
125  //- clear field
126  src.set(0.0);
127 
128  if (m_in_node) {
129  int t = m_source_position[3] % Nsize[3];
130 
131  for (int z = 0; z < Nsize[2]; ++z) {
132  for (int y = 0; y < Nsize[1]; ++y) {
133  for (int x = 0; x < Nsize[0]; ++x) {
134  int isite = m_index.site(x, y, z, t);
135 
136  //XXX field layout: complex as two doubles
137  src.set(2 * idx, isite, 0, 1.0 / Lvol3);
138  }
139  }
140  }
141  }
142 }
143 
144 
145 //====================================================================
146 void Source_Wall::set(Field& src, const int i_color, const int i_spin)
147 {
148  const int Nc = CommonParameters::Nc();
149  const int idx = i_color + Nc * i_spin;
150 
151  set(src, idx);
152 }
153 
154 
155 //====================================================================
156 void Source_Wall::set_all_color(Field& src, const int i_spin)
157 {
158  const int Nc = CommonParameters::Nc();
159  const int Ndim = CommonParameters::Ndim();
160 
161  //- global lattice size
162  const int Lx = CommonParameters::Lx();
163  const int Ly = CommonParameters::Ly();
164  const int Lz = CommonParameters::Lz();
165 
166  const int Lvol3 = Lx * Ly * Lz;
167 
168  //- local size
169  std::vector<int> Nsize(Ndim);
170 
171  Nsize[0] = CommonParameters::Nx();
172  Nsize[1] = CommonParameters::Ny();
173  Nsize[2] = CommonParameters::Nz();
174  Nsize[3] = CommonParameters::Nt();
175 
176  //- clear field
177  src.set(0.0);
178 
179  if (m_in_node) {
180  int t = m_source_position[3] % Nsize[3];
181 
182  for (int z = 0; z < Nsize[2]; ++z) {
183  for (int y = 0; y < Nsize[1]; ++y) {
184  for (int x = 0; x < Nsize[0]; ++x) {
185  int isite = m_index.site(x, y, z, t);
186 
187  for (int i_color = 0; i_color < Nc; ++i_color) {
188  int idx = i_color + Nc * i_spin;
189  int idx_r = 2 * idx;
190 
191  //XXX field layout: complex as two doubles
192  src.set(idx_r, isite, 0, 1.0 / Lvol3);
193  }
194  }
195  }
196  }
197  }
198 }
199 
200 
201 //====================================================================
203 {
204  const int Nc = CommonParameters::Nc();
205  const int Nd = CommonParameters::Nd();
206  const int Ndim = CommonParameters::Ndim();
207 
208  //- global lattice size
209  const int Lx = CommonParameters::Lx();
210  const int Ly = CommonParameters::Ly();
211  const int Lz = CommonParameters::Lz();
212 
213  const int Lvol3 = Lx * Ly * Lz;
214 
215  //- local size
216  std::vector<int> Nsize(Ndim);
217 
218  Nsize[0] = CommonParameters::Nx();
219  Nsize[1] = CommonParameters::Ny();
220  Nsize[2] = CommonParameters::Nz();
221  Nsize[3] = CommonParameters::Nt();
222 
223  //- clear field
224  src.set(0.0);
225 
226  if (m_in_node) {
227  int t = m_source_position[3] % Nsize[3];
228 
229  for (int z = 0; z < Nsize[2]; ++z) {
230  for (int y = 0; y < Nsize[1]; ++y) {
231  for (int x = 0; x < Nsize[0]; ++x) {
232  int isite = m_index.site(x, y, z, t);
233 
234  for (int idx = 0; idx < Nc * Nd; ++idx) {
235  int idx_r = 2 * idx;
236 
237  //XXX field layout: complex as two doubles
238  src.set(idx_r, isite, 0, 1.0 / Lvol3);
239  }
240  }
241  }
242  }
243  }
244 }
245 
246 
247 //====================================================================
248 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:503
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
int site(const int &x, const int &y, const int &z, const int &t) const
Definition: index_lex.h:53
void general(const char *format,...)
Definition: bridgeIO.cpp:197
static const std::string class_name
Definition: source_Wall.h:35
Container of Field-type object.
Definition: field.h:45
void set_all_color(Field &v, const int i_spin)
Class for parameters.
Definition: parameters.h:46
static int ipe(const int dir)
logical coordinate of current proc.
bool m_in_node
Definition: source_Wall.h:40
void set_parameters(const Parameters &params)
Definition: source_Wall.cpp:25
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
Bridge::VerboseLevel m_vl
Definition: source.h:40
int non_negative(const int v)
Index_lex m_index
Definition: source_Wall.h:38
std::vector< int > m_source_position
Definition: source_Wall.h:39
string get_string(const string &key) const
Definition: parameters.cpp:221
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:429
void set_all_color_spin(Field &v)
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
void set(Field &v, const int idx)