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