Bridge++  Ver. 2.0.2
source_MomentumWall.cpp
Go to the documentation of this file.
1 
14 #include "source_MomentumWall.h"
15 
16 #ifdef USE_FACTORY_AUTOREGISTER
17 namespace {
18  bool init = Source_MomentumWall::register_factory();
19 }
20 #endif
21 
22 const std::string Source_MomentumWall::class_name = "Source_MomentumWall";
23 
24 //====================================================================
26 {
27  std::string vlevel;
28  if (!params.fetch_string("verbose_level", vlevel)) {
29  m_vl = vout.set_verbose_level(vlevel);
30  }
31 
32  //- fetch and check input parameters
33  std::vector<int> source_position;
34  std::vector<int> source_momentum;
35 
36  int err = 0;
37  err += params.fetch_int_vector("source_position", source_position);
38  err += params.fetch_int_vector("source_momentum", source_momentum);
39 
40  if (err) {
41  vout.crucial(m_vl, "Error at %s: input parameter not found.\n", class_name.c_str());
42  exit(EXIT_FAILURE);
43  }
44 
45  set_parameters(source_position, source_momentum);
46 }
47 
48 
49 //====================================================================
51 {
52  params.set_int_vector("source_position", m_source_position);
53  params.set_int_vector("source_momentum", m_source_momentum);
54 
55  params.set_string("verbose_level", vout.get_verbose_level(m_vl));
56 }
57 
58 
59 //====================================================================
60 void Source_MomentumWall::set_parameters(const std::vector<int>& source_position,
61  const std::vector<int>& source_momentum)
62 {
63  // #### parameter setup ####
64  const int Ndim = CommonParameters::Ndim();
65  const int t_dir = Ndim - 1;
66 
67  //- global lattice size
68  std::vector<int> Lsize(Ndim);
69 
70  Lsize[0] = CommonParameters::Lx();
71  Lsize[1] = CommonParameters::Ly();
72  Lsize[2] = CommonParameters::Lz();
73  Lsize[3] = CommonParameters::Lt();
74 
75  //- local size
76  const int Nt = CommonParameters::Nt();
77 
78  //- print input parameters
79  vout.general(m_vl, "Source for spinor field - momentum wall smeared:\n");
80  for (int mu = 0; mu < Ndim; ++mu) {
81  vout.general(m_vl, " source_position[%d] = %d\n",
82  mu, source_position[mu]);
83  }
84  for (int mu = 0; mu < Ndim - 1; ++mu) {
85  vout.general(m_vl, " source_momentum[%d] = %d\n",
86  mu, source_momentum[mu]);
87  }
88 
89 
90  //- range check
91  int err = 0;
92  for (int mu = 0; mu < Ndim; ++mu) {
93  // NB. Lsize[mu] > abs(source_position[mu])
94  err += ParameterCheck::non_negative(Lsize[mu] - abs(source_position[mu]));
95  }
96 
97  if (err) {
98  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
99  exit(EXIT_FAILURE);
100  }
101 
102  //- store values
103  m_source_position.resize(Ndim);
104  for (int mu = 0; mu < Ndim; ++mu) {
105  m_source_position[mu] = (source_position[mu] + Lsize[mu]) % Lsize[mu];
106  }
107 
108  m_source_momentum = source_momentum;
109 
110  //- post-process
111 
112  //- PE location in t-direction.
113  const int tpe = m_source_position[t_dir] / Nt;
114 
115  m_in_node = false;
116 
117  if (tpe == Communicator::ipe(t_dir)) {
118  m_in_node = true;
119  }
120 }
121 
122 
123 //====================================================================
124 void Source_MomentumWall::set(Field& src, const int idx)
125 {
126  const int Ndim = CommonParameters::Ndim();
127 
128  const int x_dir = 0;
129  const int y_dir = 1;
130  const int z_dir = 2;
131  const int t_dir = Ndim - 1;
132 
133  //- global lattice size
134  const int Lx = CommonParameters::Lx();
135  const int Ly = CommonParameters::Ly();
136  const int Lz = CommonParameters::Lz();
137  const int Lvol3 = Lx * Ly * Lz;
138 
139  //- local size
140  const int Nx = CommonParameters::Nx();
141  const int Ny = CommonParameters::Ny();
142  const int Nz = CommonParameters::Nz();
143  const int Nt = CommonParameters::Nt();
144 
145  static const double PI = 4.0 * atan(1.0);
146 
147  std::vector<double> p_unit(Ndim - 1);
148 
149  p_unit[x_dir] = (2.0 * PI / Lx) * m_source_momentum[x_dir];
150  p_unit[y_dir] = (2.0 * PI / Ly) * m_source_momentum[y_dir];
151  p_unit[z_dir] = (2.0 * PI / Lz) * m_source_momentum[z_dir];
152 
153  std::vector<int> ipe(Ndim - 1);
154  ipe[x_dir] = Communicator::ipe(x_dir);
155  ipe[y_dir] = Communicator::ipe(y_dir);
156  ipe[z_dir] = Communicator::ipe(z_dir);
157 
158  //- clear field
159  src.set(0.0);
160 
161  if (m_in_node) {
162  const int t = m_source_position[t_dir] % Nt;
163 
164  for (int z = 0; z < Nz; ++z) {
165  for (int y = 0; y < Ny; ++y) {
166  for (int x = 0; x < Nx; ++x) {
167  int site = m_index.site(x, y, z, t);
168 
169  int x_global = x + ipe[x_dir] * Nx;
170  int y_global = y + ipe[y_dir] * Ny;
171  int z_global = z + ipe[z_dir] * Nz;
172 
173  double p_x = p_unit[x_dir] * (x_global - m_source_position[x_dir]);
174  double p_y = p_unit[y_dir] * (y_global - m_source_position[y_dir]);
175  double p_z = p_unit[z_dir] * (z_global - m_source_position[z_dir]);
176 
177  double theta = p_x + p_y + p_z;
178 
179  int idx_r = 2 * idx;
180  int idx_i = 2 * idx + 1;
181 
182  //XXX field layout: complex as two doubles
183  src.set(idx_r, site, 0, cos(theta) / Lvol3);
184  src.set(idx_i, site, 0, sin(theta) / Lvol3);
185  }
186  }
187  }
188  }
189 }
190 
191 
192 //====================================================================
193 void Source_MomentumWall::set(Field& src, const int i_color, const int i_spin)
194 {
195  const int Nc = CommonParameters::Nc();
196  const int idx = i_color + Nc * i_spin;
197 
198  set(src, idx);
199 }
200 
201 
202 //====================================================================
203 void Source_MomentumWall::set_all_color(Field& src, const int i_spin)
204 {
205  const int Nc = CommonParameters::Nc();
206  const int Ndim = CommonParameters::Ndim();
207 
208  const int x_dir = 0;
209  const int y_dir = 1;
210  const int z_dir = 2;
211  const int t_dir = Ndim - 1;
212 
213  //- global lattice size
214  const int Lx = CommonParameters::Lx();
215  const int Ly = CommonParameters::Ly();
216  const int Lz = CommonParameters::Lz();
217  const int Lvol3 = Lx * Ly * Lz;
218 
219  //- local size
220  const int Nx = CommonParameters::Nx();
221  const int Ny = CommonParameters::Ny();
222  const int Nz = CommonParameters::Nz();
223  const int Nt = CommonParameters::Nt();
224 
225  static const double PI = 4.0 * atan(1.0);
226 
227  std::vector<double> p_unit(Ndim - 1);
228 
229  p_unit[x_dir] = (2.0 * PI / Lx) * m_source_momentum[x_dir];
230  p_unit[y_dir] = (2.0 * PI / Ly) * m_source_momentum[y_dir];
231  p_unit[z_dir] = (2.0 * PI / Lz) * m_source_momentum[z_dir];
232 
233  std::vector<int> ipe(Ndim - 1);
234  ipe[x_dir] = Communicator::ipe(x_dir);
235  ipe[y_dir] = Communicator::ipe(y_dir);
236  ipe[z_dir] = Communicator::ipe(z_dir);
237 
238  //- clear field
239  src.set(0.0);
240 
241  if (m_in_node) {
242  const int t = m_source_position[t_dir] % Nt;
243 
244  for (int z = 0; z < Nz; ++z) {
245  for (int y = 0; y < Ny; ++y) {
246  for (int x = 0; x < Nx; ++x) {
247  int site = m_index.site(x, y, z, t);
248 
249  int x_global = x + ipe[x_dir] * Nx;
250  int y_global = y + ipe[y_dir] * Ny;
251  int z_global = z + ipe[z_dir] * Nz;
252 
253  double p_x = p_unit[x_dir] * (x_global - m_source_position[x_dir]);
254  double p_y = p_unit[y_dir] * (y_global - m_source_position[y_dir]);
255  double p_z = p_unit[z_dir] * (z_global - m_source_position[z_dir]);
256 
257  double theta = p_x + p_y + p_z;
258 
259  for (int i_color = 0; i_color < Nc; ++i_color) {
260  int idx = i_color + Nc * i_spin;
261  int idx_r = 2 * idx;
262  int idx_i = 2 * idx + 1;
263 
264  //XXX field layout: complex as two doubles
265  src.set(idx_r, site, 0, cos(theta) / Lvol3);
266  src.set(idx_i, site, 0, sin(theta) / Lvol3);
267  }
268  }
269  }
270  }
271  }
272 }
273 
274 
275 //====================================================================
277 {
278  const int Nc = CommonParameters::Nc();
279  const int Nd = CommonParameters::Nd();
280  const int Ndim = CommonParameters::Ndim();
281 
282  const int x_dir = 0;
283  const int y_dir = 1;
284  const int z_dir = 2;
285  const int t_dir = Ndim - 1;
286 
287  //- global lattice size
288  const int Lx = CommonParameters::Lx();
289  const int Ly = CommonParameters::Ly();
290  const int Lz = CommonParameters::Lz();
291  const int Lvol3 = Lx * Ly * Lz;
292 
293  //- local size
294  const int Nx = CommonParameters::Nx();
295  const int Ny = CommonParameters::Ny();
296  const int Nz = CommonParameters::Nz();
297  const int Nt = CommonParameters::Nt();
298 
299  static const double PI = 4.0 * atan(1.0);
300 
301  std::vector<double> p_unit(Ndim - 1);
302 
303  p_unit[x_dir] = (2.0 * PI / Lx) * m_source_momentum[x_dir];
304  p_unit[y_dir] = (2.0 * PI / Ly) * m_source_momentum[y_dir];
305  p_unit[z_dir] = (2.0 * PI / Lz) * m_source_momentum[z_dir];
306 
307  std::vector<int> ipe(Ndim - 1);
308  ipe[x_dir] = Communicator::ipe(x_dir);
309  ipe[y_dir] = Communicator::ipe(y_dir);
310  ipe[z_dir] = Communicator::ipe(z_dir);
311 
312  //- clear field
313  src.set(0.0);
314 
315  if (m_in_node) {
316  const int t = m_source_position[t_dir] % Nt;
317 
318  for (int z = 0; z < Nz; ++z) {
319  for (int y = 0; y < Ny; ++y) {
320  for (int x = 0; x < Nx; ++x) {
321  int site = m_index.site(x, y, z, t);
322 
323  int x_global = x + ipe[x_dir] * Nx;
324  int y_global = y + ipe[y_dir] * Ny;
325  int z_global = z + ipe[z_dir] * Nz;
326 
327  double p_x = p_unit[x_dir] * (x_global - m_source_position[x_dir]);
328  double p_y = p_unit[y_dir] * (y_global - m_source_position[y_dir]);
329  double p_z = p_unit[z_dir] * (z_global - m_source_position[z_dir]);
330 
331  double theta = p_x + p_y + p_z;
332 
333  for (int idx = 0; idx < Nc * Nd; ++idx) {
334  int idx_r = 2 * idx;
335  int idx_i = 2 * idx + 1;
336 
337  //XXX field layout: complex as two doubles
338  src.set(idx_r, site, 0, cos(theta) / Lvol3);
339  src.set(idx_i, site, 0, sin(theta) / Lvol3);
340  }
341  }
342  }
343  }
344  }
345 }
346 
347 
348 //====================================================================
349 //============================================================END=====
CommonParameters::Ny
static int Ny()
Definition: commonParameters.h:106
CommonParameters::Nz
static int Nz()
Definition: commonParameters.h:107
Parameters::set_string
void set_string(const string &key, const string &value)
Definition: parameters.cpp:39
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
Field::set
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
Parameters
Class for parameters.
Definition: parameters.h:46
Source_MomentumWall::set_all_color
void set_all_color(Field &v, const int i_spin)
Definition: source_MomentumWall.cpp:203
CommonParameters::Ly
static int Ly()
Definition: commonParameters.h:92
ParameterCheck::non_negative
int non_negative(const int v)
Definition: parameterCheck.cpp:21
source_MomentumWall.h
Momentum wall source.
Source_MomentumWall::m_vl
Bridge::VerboseLevel m_vl
Definition: source_MomentumWall.h:42
CommonParameters::Nx
static int Nx()
Definition: commonParameters.h:105
CommonParameters::Lt
static int Lt()
Definition: commonParameters.h:94
Source_MomentumWall::set_all_color_spin
void set_all_color_spin(Field &v)
Definition: source_MomentumWall.cpp:276
CommonParameters::Lx
static int Lx()
Definition: commonParameters.h:91
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
CommonParameters::Lz
static int Lz()
Definition: commonParameters.h:93
CommonParameters::Nt
static int Nt()
Definition: commonParameters.h:108
Parameters::fetch_int_vector
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:429
Source_MomentumWall::m_index
Index_lex m_index
Definition: source_MomentumWall.h:44
AIndex_eo_qxs::idx
int idx(const int in, const int Nin, const int ist, const int Nx2, const int Ny, const int leo, const int Nvol2, const int ex)
Definition: aindex_eo.h:27
Source_MomentumWall::m_source_position
std::vector< int > m_source_position
Definition: source_MomentumWall.h:45
Index_lex::site
int site(const int &x, const int &y, const int &z, const int &t) const
Definition: index_lex.h:55
Parameters::set_int_vector
void set_int_vector(const string &key, const vector< int > &value)
Definition: parameters.cpp:45
Source_MomentumWall::class_name
static const std::string class_name
Definition: source_MomentumWall.h:39
CommonParameters::Nd
static int Nd()
Definition: commonParameters.h:116
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
Communicator::ipe
static int ipe(const int dir)
logical coordinate of current proc.
Definition: communicator.cpp:105
Parameters::fetch_string
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:378
Source_MomentumWall::m_source_momentum
std::vector< int > m_source_momentum
Definition: source_MomentumWall.h:46
Source_MomentumWall::set_parameters
void set_parameters(const Parameters &params)
Definition: source_MomentumWall.cpp:25
Source_MomentumWall::m_in_node
bool m_in_node
Definition: source_MomentumWall.h:47
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Field
Container of Field-type object.
Definition: field.h:46
Source_MomentumWall::get_parameters
void get_parameters(Parameters &params) const
Definition: source_MomentumWall.cpp:50
Source_MomentumWall::set
void set(Field &v, const int idx)
Definition: source_MomentumWall.cpp:124
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
Bridge::BridgeIO::get_verbose_level
static std::string get_verbose_level(const VerboseLevel vl)
Definition: bridgeIO.cpp:154