Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  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  set_parameters(source_position);
43 }
44 
45 
46 //====================================================================
47 void Source_Local::set_parameters(const std::vector<int>& source_position)
48 {
49  // #### parameter setup ####
50  int Ndim = CommonParameters::Ndim();
51 
52  std::vector<int> Lsize(Ndim);
53 
54  Lsize[0] = CommonParameters::Lx();
55  Lsize[1] = CommonParameters::Ly();
56  Lsize[2] = CommonParameters::Lz();
57  Lsize[3] = CommonParameters::Lt();
58 
59  //- print input parameters
60  vout.general(m_vl, "Source for spinor field - local:\n");
61  for (int mu = 0; mu < Ndim; ++mu) {
62  vout.general(m_vl, " source_position[%d] = %d\n",
63  mu, source_position[mu]);
64  }
65 
66  //- range check
67  int err = 0;
68  for (int mu = 0; mu < Ndim; ++mu) {
69  // NB. Lsize[mu] > abs(source_position[mu])
70  err += ParameterCheck::non_negative(Lsize[mu] - abs(source_position[mu]));
71  }
72 
73  if (err) {
74  vout.crucial(m_vl, "Error at %s: parameter range check failed.\n", class_name.c_str());
75  exit(EXIT_FAILURE);
76  }
77 
78  assert(source_position.size() == Ndim);
79 
80  //- store values
81  m_source_position.resize(Ndim);
82  m_source_position = source_position;
83 
84  for (int mu = 0; mu < Ndim; ++mu) {
85  while (m_source_position[mu] < 0)
86  {
87  m_source_position[mu] += Lsize[mu];
88  }
89  m_source_position[mu] %= Lsize[mu];
90  }
91 
92 
93  //- post-process
94  std::vector<int> Nsize(Ndim);
95  Nsize[0] = CommonParameters::Nx();
96  Nsize[1] = CommonParameters::Ny();
97  Nsize[2] = CommonParameters::Nz();
98  Nsize[3] = CommonParameters::Nt();
99 
100  //- check if source position is in current local node.
101  m_in_node = true;
102  for (int i = 0; i < Ndim; ++i) {
103  int inode = m_source_position[i] / Nsize[i];
104 
105  if (inode != Communicator::ipe(i)) {
106  m_in_node = false;
107  break;
108  }
109  }
110 
111  //- find local coordinate of source position.
112  if (m_in_node) {
113  for (int i = 0; i < Ndim; ++i) {
114  m_source_position[i] %= Nsize[i];
115  }
116  } else {
117  for (int i = 0; i < Ndim; ++i) {
118  m_source_position[i] = -1;
119  }
120  }
121 }
122 
123 
124 //====================================================================
125 void Source_Local::set(Field& src, const int idx)
126 {
127  //- clear field
128  src.set(0.0); // src = 0.0
129 
130  if (m_in_node) {
131  const int isite = m_index.site(m_source_position[0],
134  m_source_position[3]);
135 
136  //XXX complex as two doubles
137  src.set(2 * idx, isite, 0, 1.0);
138  }
139 }
140 
141 
142 //====================================================================
143 void Source_Local::set(Field& src, const int i_color, const int i_spin)
144 {
145  const int Nc = CommonParameters::Nc();
146  const int idx = i_color + Nc * i_spin;
147 
148  set(src, idx);
149 }
150 
151 
152 //====================================================================
153 void Source_Local::set_all_color(Field& src, const int i_spin)
154 {
155  const int Nc = CommonParameters::Nc();
156 
157  //- clear field
158  src.set(0.0);
159 
160  if (m_in_node) {
161  const int isite = m_index.site(m_source_position[0],
164  m_source_position[3]);
165 
166  for (int i_color = 0; i_color < Nc; ++i_color) {
167  int idx = i_color + Nc * i_spin;
168  int idx_r = 2 * idx;
169 
170  //XXX complex as two doubles
171  src.set(idx_r, isite, 0, 1.0);
172  }
173  }
174 }
175 
176 
177 //====================================================================
179 {
180  const int Nc = CommonParameters::Nc();
181  const int Nd = CommonParameters::Nd();
182 
183  //- clear field
184  src.set(0.0);
185 
186  if (m_in_node) {
187  const int isite = m_index.site(m_source_position[0],
190  m_source_position[3]);
191 
192  for (int idx = 0; idx < Nc * Nd; ++idx) {
193  int idx_r = 2 * idx;
194 
195  //XXX complex as two doubles
196  src.set(idx_r, isite, 0, 1.0);
197  }
198  }
199 }
200 
201 
202 //====================================================================
203 //============================================================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
static const std::string class_name
Definition: source_Local.h:36
void set_all_color_spin(Field &v)
void general(const char *format,...)
Definition: bridgeIO.cpp:197
Index_lex m_index
Definition: source_Local.h:39
Container of Field-type object.
Definition: field.h:45
Class for parameters.
Definition: parameters.h:46
static int ipe(const int dir)
logical coordinate of current proc.
void set_parameters(const Parameters &params)
void set_all_color(Field &v, const int i_spin)
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
void set(Field &v, const int idx)
Bridge::VerboseLevel m_vl
Definition: source.h:40
int non_negative(const int v)
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
std::vector< int > m_source_position
Definition: source_Local.h:40
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131