Bridge++  Ver. 2.0.2
source_Local.cpp
Go to the documentation of this file.
1 
14 #include "source_Local.h"
15 
16 #ifdef USE_FACTORY_AUTOREGISTER
17 namespace {
18  bool init = Source_Local::register_factory();
19 }
20 #endif
21 
22 const std::string Source_Local::class_name = "Source_Local";
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  set_parameters(source_position);
44 }
45 
46 
47 //====================================================================
49 {
50  params.set_int_vector("source_position", m_source_position);
51 
52  params.set_string("verbose_level", vout.get_verbose_level(m_vl));
53 }
54 
55 
56 //====================================================================
57 void Source_Local::set_parameters(const std::vector<int>& source_position)
58 {
59  // #### parameter setup ####
60  int Ndim = CommonParameters::Ndim();
61 
62  std::vector<int> Lsize(Ndim);
63 
64  Lsize[0] = CommonParameters::Lx();
65  Lsize[1] = CommonParameters::Ly();
66  Lsize[2] = CommonParameters::Lz();
67  Lsize[3] = CommonParameters::Lt();
68 
69  //- print input parameters
70  vout.general(m_vl, "Source for spinor field - local:\n");
71  for (int mu = 0; mu < Ndim; ++mu) {
72  vout.general(m_vl, " source_position[%d] = %d\n",
73  mu, source_position[mu]);
74  }
75 
76  //- range check
77  int err = 0;
78  for (int mu = 0; mu < Ndim; ++mu) {
79  // NB. Lsize[mu] > abs(source_position[mu])
80  err += ParameterCheck::non_negative(Lsize[mu] - abs(source_position[mu]));
81  }
82 
83  if (err) {
84  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
85  exit(EXIT_FAILURE);
86  }
87 
88  assert(source_position.size() == Ndim);
89 
90  //- store values
91  m_source_position.resize(Ndim);
92  m_source_position = source_position;
93 
94  for (int mu = 0; mu < Ndim; ++mu) {
95  while (m_source_position[mu] < 0)
96  {
97  m_source_position[mu] += Lsize[mu];
98  }
99  m_source_position[mu] %= Lsize[mu];
100  }
101 
102 
103  //- post-process
104  std::vector<int> Nsize(Ndim);
105  Nsize[0] = CommonParameters::Nx();
106  Nsize[1] = CommonParameters::Ny();
107  Nsize[2] = CommonParameters::Nz();
108  Nsize[3] = CommonParameters::Nt();
109 
110  //- check if source position is in current local node.
111  m_in_node = true;
112  for (int i = 0; i < Ndim; ++i) {
113  int inode = m_source_position[i] / Nsize[i];
114 
115  if (inode != Communicator::ipe(i)) {
116  m_in_node = false;
117  break;
118  }
119  }
120 
121  //- find local coordinate of source position.
122  if (m_in_node) {
123  for (int i = 0; i < Ndim; ++i) {
124  m_source_position[i] %= Nsize[i];
125  }
126  } else {
127  for (int i = 0; i < Ndim; ++i) {
128  m_source_position[i] = -1;
129  }
130  }
131 }
132 
133 
134 //====================================================================
135 void Source_Local::set(Field& src, const int idx)
136 {
137  //- clear field
138  src.set(0.0); // src = 0.0
139 
140  if (m_in_node) {
141  const int isite = m_index.site(m_source_position[0],
144  m_source_position[3]);
145 
146  //XXX complex as two doubles
147  src.set(2 * idx, isite, 0, 1.0);
148  }
149 }
150 
151 
152 //====================================================================
153 void Source_Local::set(Field& src, const int i_color, const int i_spin)
154 {
155  const int Nc = CommonParameters::Nc();
156  const int idx = i_color + Nc * i_spin;
157 
158  set(src, idx);
159 }
160 
161 
162 //====================================================================
163 void Source_Local::set_all_color(Field& src, const int i_spin)
164 {
165  const int Nc = CommonParameters::Nc();
166 
167  //- clear field
168  src.set(0.0);
169 
170  if (m_in_node) {
171  const int isite = m_index.site(m_source_position[0],
174  m_source_position[3]);
175 
176  for (int i_color = 0; i_color < Nc; ++i_color) {
177  int idx = i_color + Nc * i_spin;
178  int idx_r = 2 * idx;
179 
180  //XXX complex as two doubles
181  src.set(idx_r, isite, 0, 1.0);
182  }
183  }
184 }
185 
186 
187 //====================================================================
189 {
190  const int Nc = CommonParameters::Nc();
191  const int Nd = CommonParameters::Nd();
192 
193  //- clear field
194  src.set(0.0);
195 
196  if (m_in_node) {
197  const int isite = m_index.site(m_source_position[0],
200  m_source_position[3]);
201 
202  for (int idx = 0; idx < Nc * Nd; ++idx) {
203  int idx_r = 2 * idx;
204 
205  //XXX complex as two doubles
206  src.set(idx_r, isite, 0, 1.0);
207  }
208  }
209 }
210 
211 
212 //====================================================================
213 //============================================================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
Source_Local::set_all_color_spin
void set_all_color_spin(Field &v)
Definition: source_Local.cpp:188
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_Local.h
CommonParameters::Ly
static int Ly()
Definition: commonParameters.h:92
Source_Local::m_source_position
std::vector< int > m_source_position
Definition: source_Local.h:42
ParameterCheck::non_negative
int non_negative(const int v)
Definition: parameterCheck.cpp:21
Source_Local::m_index
Index_lex m_index
Definition: source_Local.h:41
Source_Local::get_parameters
void get_parameters(Parameters &params) const
Definition: source_Local.cpp:48
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
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
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_Local::set_parameters
void set_parameters(const Parameters &params)
Definition: source_Local.cpp:25
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
Source_Local::m_in_node
bool m_in_node
Definition: source_Local.h:43
Communicator::ipe
static int ipe(const int dir)
logical coordinate of current proc.
Definition: communicator.cpp:105
Source_Local::class_name
static const std::string class_name
Definition: source_Local.h:36
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
Source_Local::set
void set(Field &v, const int idx)
Definition: source_Local.cpp:135
Field
Container of Field-type object.
Definition: field.h:46
Source_Local::set_all_color
void set_all_color(Field &v, const int i_spin)
Definition: source_Local.cpp:163
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Source_Local::m_vl
Bridge::VerboseLevel m_vl
Definition: source_Local.h:39
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