Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Spectrum_2ptFunction_eo.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "Field/shiftField_lex.h"
17 
18 #include "Fopr/fopr_Smeared.h"
19 
20 #include "IO/gaugeConfig.h"
21 
26 
27 #include "Tools/filename.h"
28 #include "Tools/gammaMatrixSet.h"
30 
31 //====================================================================
33 
43 namespace Test_Spectrum {
44  const std::string test_name = "Spectrum.Hadron2ptFunction_eo";
45 
46  //- test-private parameters
47  namespace {
48  // const std::string filename_input = "test_Spectrum_Clover_Hadron2ptFunction.yaml";
49  }
50 
51  //- prototype declaration
52  int hadron_2ptFunction_eo(const std::string&);
53 
54  //- hadron_2ptFunction for various fermions
56  {
57  return hadron_2ptFunction_eo("test_Spectrum_Clover_Hadron2ptFunction.yaml");
58  }
59 
60 
62  {
63  return hadron_2ptFunction_eo("test_Spectrum_Wilson_Hadron2ptFunction.yaml");
64  }
65 
66 
67 #ifdef USE_TESTMANAGER_AUTOREGISTER
68  namespace {
69 #if defined(USE_GROUP_SU2)
70  // Nc=2 is not available.
71 #else
72  static const bool is_registered_Clover_eo = TestManager::RegisterTest(
73  "Spectrum.Clover.Hadron2ptFunction_eo",
75  );
76 
77  //- NB. test_Spectrum_Wilson is implemented separately for beginners
78  // static const bool is_registered_Wilson_eo = TestManager::RegisterTest(
79  // "Spectrum.Wilson.Hadron2ptFunction_eo",
80  // hadron_2ptFunction_eo_Wilson
81  // );
82 #endif
83  }
84 #endif
85 
86  //====================================================================
87  int hadron_2ptFunction_eo(const std::string& filename_input)
88  {
89  // #### parameter setup ####
90  const int Nc = CommonParameters::Nc();
91  const int Nd = CommonParameters::Nd();
92  const int Ndim = CommonParameters::Ndim();
93  const int Nvol = CommonParameters::Nvol();
94 
95  const Parameters params_all = ParameterManager::read(filename_input);
96 
97  const Parameters params_test = params_all.lookup("Test_Spectrum");
98 
99  const int N_quark = params_test.get_int("number_of_valence_quarks");
100 
101  const std::string str_gconf_status = params_test.get_string("gauge_config_status");
102  const std::string str_gconf_read = params_test.get_string("gauge_config_type_input");
103  const vector<int> Nshift_origin = params_test.get_int_vector("shift_origin");
104  const std::string readfile = params_test.get_string("config_filename_input");
105  const std::string str_rand_type = params_test.get_string("random_number_type");
106  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
107  const std::string str_vlevel = params_test.get_string("verbose_level");
108 
109  const bool do_check = params_test.is_set("expected_result");
110  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
111 
112  const std::string str_gfix_type = params_all.lookup("GaugeFixing").get_string("gauge_fixing_type");
113  const std::string str_proj_type = params_all.lookup("Projection").get_string("projection_type");
114  const std::string str_smear_type = params_all.lookup("Smear").get_string("smear_type");
115 
116  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
117 
118  //- print input parameters
119  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
120  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
121  vout.general(vl, " readfile = %s\n", readfile.c_str());
122  for (int mu = 0; mu < Ndim; ++mu) {
123  vout.general(vl, " shift_origin[%d] = %d\n", mu, Nshift_origin[mu]);
124  }
125  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
126  vout.general(vl, " seed = %lu\n", seed);
127  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
128  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
129  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
130  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
131 
132  vector<Parameters> params_quark;
133  for (int iq = 0; iq < N_quark; ++iq) {
134  std::string qlabel = Filename("Quark_{id}").format(iq + 1);
135  params_quark.push_back(params_all.lookup(qlabel));
136  }
137 
138  // NB. all str_gmset_type are supposed to be the same.
139  const std::string str_gmset_type = params_quark[0].lookup("Fopr").get_string("gamma_matrix_type");
140  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
141 
142  for (int iq = 0; iq < N_quark; ++iq) {
143  vout.general(vl, " Quark_%d:\n", iq + 1);
144  vout.general(vl, " solver_type = %s\n",
145  params_quark[iq].lookup("Solver").get_string("solver_type").c_str());
146  vout.general(vl, " source_type = %s\n",
147  params_quark[iq].lookup("Source").get_string("source_type").c_str());
148 
149  std::string str_solver_type = params_quark[iq].lookup("Solver").get_string("solver_type");
150  vout.general(vl, " solver_type = %s\n", str_solver_type.c_str());
151 
152  vector<int> source_position = params_quark[iq].lookup("Source").get_int_vector("source_position");
153  for (int mu = 0; mu < Ndim; ++mu) {
154  vout.general(vl, " source_position[%d] = %d\n", mu, source_position[mu]);
155  }
156  }
157  vout.general(vl, "\n");
158 
159  //- input parameter check
160  int err = 0;
161  err += ParameterCheck::non_NULL(str_gconf_status);
162 
163  if (err) {
164  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
165  exit(EXIT_FAILURE);
166  }
167 
168  for (int iq = 0; iq < N_quark; ++iq) {
169  std::string str_solver_type = params_quark[iq].lookup("Solver").get_string("solver_type");
170 
171  if (str_solver_type == "CG") {
172  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
173  exit(EXIT_FAILURE);
174  }
175  }
176 
177  RandomNumberManager::initialize(str_rand_type, seed);
178 
179 
180  // #### Set up a gauge configuration ####
181  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
182 
183  if (str_gconf_status == "Continue") {
184  GaugeConfig(str_gconf_read).read(U, readfile);
185  } else if (str_gconf_status == "Cold_start") {
186  GaugeConfig("Unit").read(U);
187  } else if (str_gconf_status == "Hot_start") {
188  GaugeConfig("Random").read(U);
189  } else {
190  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
191  exit(EXIT_FAILURE);
192  }
193 
194  {
196  for (int i_dir = 0; i_dir < Ndim; ++i_dir) {
197  for (int i_shift = 0; i_shift < Nshift_origin[i_dir]; ++i_shift) {
198  unique_ptr<Field_G> Ushift(new Field_G(Nvol, Ndim));
199  shift.backward(*Ushift, *U, i_dir);
200  copy(*U, *Ushift);
201  }
202  }
203  }
204 
205  {
206  unique_ptr<Projection> proj(Projection::New(str_proj_type));
207  proj->set_parameters(params_all.lookup("Projection"));
208 
209  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
210  smear->set_parameters(params_all.lookup("Smear"));
211 
212  const unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear));
213  dr_smear->set_parameters(params_all.lookup("Director_Smear"));
214  dr_smear->set_config(U);
215 
216  const int Nsmear = dr_smear->get_Nsmear();
217  const Field_G *Usmear = (Field_G *)dr_smear->getptr_smearedConfig(Nsmear);
218 
219  copy(*U, *Usmear);
220  }
221 
222 
223  // #### Gauge fixing ####
224  {
225  unique_ptr<Field_G> Ufix(new Field_G(Nvol, Ndim));
226  const unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type));
227  gfix->set_parameters(params_all.lookup("GaugeFixing"));
228 
229  gfix->fix(*Ufix, *U);
230 
231  copy(*U, *Ufix);
232  }
233 
234 
235  // #### object setup #####
236  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
237 
238 #ifdef LIB_CPP11
239  std::vector<unique_ptr<Fopr> > fopr(N_quark);
240  std::vector<unique_ptr<Fopr> > fopr_eo(N_quark);
241  std::vector<unique_ptr<Solver> > solver(N_quark);
242  std::vector<unique_ptr<Fprop> > fprop_eo(N_quark);
243  std::vector<unique_ptr<Source> > source(N_quark);
244 
245  // NB. Fopr is used only for check of diff2 below.
246 
247  for (int iq = 0; iq < N_quark; ++iq) {
248  std::string str_fopr_type = params_quark[iq].lookup("Fopr").get_string("fermion_type");
249  fopr[iq].reset(Fopr::New(str_fopr_type, str_gmset_type));
250  fopr[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
251  fopr[iq]->set_config(U);
252 
253  fopr_eo[iq].reset(Fopr::New(str_fopr_type + "_eo", str_gmset_type));
254  fopr_eo[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
255  fopr_eo[iq]->set_config(U);
256 
257  std::string str_solver_type = params_quark[iq].lookup("Solver").get_string("solver_type");
258  solver[iq].reset(Solver::New(str_solver_type, fopr_eo[iq]));
259  solver[iq]->set_parameters(params_quark[iq].lookup("Solver"));
260 
261  fprop_eo[iq].reset(new Fprop_Standard_eo(solver[iq]));
262 
263  std::string str_source_type = params_quark[iq].lookup("Source").get_string("source_type");
264  source[iq].reset(Source::New(str_source_type));
265  source[iq]->set_parameters(params_quark[iq].lookup("Source"));
266  }
267 #else
268  std::vector<Fopr *> fopr(N_quark);
269  std::vector<Fopr *> fopr_eo(N_quark);
270  std::vector<Solver *> solver(N_quark);
271  std::vector<Fprop *> fprop_eo(N_quark);
272  std::vector<Source *> source(N_quark);
273 
274  // NB. Fopr is used only for check of diff2 below.
275 
276  for (int iq = 0; iq < N_quark; ++iq) {
277  std::string str_fopr_type = params_quark[iq].lookup("Fopr").get_string("fermion_type");
278  fopr[iq] = Fopr::New(str_fopr_type, str_gmset_type);
279  fopr[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
280  fopr[iq]->set_config(U);
281 
282  fopr_eo[iq] = Fopr::New(str_fopr_type + "_eo", str_gmset_type);
283  fopr_eo[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
284  fopr_eo[iq]->set_config(U);
285 
286  std::string str_solver_type = params_quark[iq].lookup("Solver").get_string("solver_type");
287  solver[iq] = Solver::New(str_solver_type, fopr_eo[iq]);
288  solver[iq]->set_parameters(params_quark[iq].lookup("Solver"));
289 
290  fprop_eo[iq] = new Fprop_Standard_eo(solver[iq]);
291 
292  std::string str_source_type = params_quark[iq].lookup("Source").get_string("source_type");
293  source[iq] = Source::New(str_source_type);
294  source[iq]->set_parameters(params_quark[iq].lookup("Source"));
295  }
296 #endif
297 
298  Corr2pt_4spinor corr(gmset);
299  corr.set_parameters(params_all.lookup("Corr2pt_4spinor"));
300 
301  const unique_ptr<Timer> timer(new Timer(test_name));
302 
303 
304  // #### Execution main part ####
305  timer->start();
306 
307  typedef std::vector<Field_F> PropagatorSet;
308  std::vector<PropagatorSet> sq(N_quark);
309  for (int iq = 0; iq < N_quark; ++iq) {
310  sq[iq].resize(Nc * Nd);
311 
312  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
313  sq[iq][i_cd].set(0.0);
314  }
315  }
316 
317  for (int iq = 0; iq < N_quark; ++iq) {
318  vout.general(vl, "Solving quark propagator, flavor = %d:\n", iq + 1);
319  vout.general(vl, " color spin Nconv diff diff2\n");
320 
321  for (int ispin = 0; ispin < Nd; ++ispin) {
322  for (int icolor = 0; icolor < Nc; ++icolor) {
323  int i_cd = icolor + Nc * ispin;
324 
325  Field_F b; // b.set(0.0);
326  source[iq]->set(b, i_cd);
327 
328  int Nconv;
329  double diff;
330  fprop_eo[iq]->invert_D(sq[iq][i_cd], b, Nconv, diff);
331 
332  Field_F y(b);
333  fopr[iq]->set_mode("D");
334  fopr[iq]->mult(y, sq[iq][i_cd]); // y = fopr[iq]->mult(sq[iq][i_cd]);
335  axpy(y, -1.0, b); // y -= b;
336  double diff2 = y.norm2() / b.norm2();
337 
338  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
339  icolor, ispin, Nconv, diff, diff2);
340  }
341  }
342 
343  vout.general(vl, "\n");
344  }
345 
346 
347  //- meson correlators
348  std::vector<double> result(N_quark);
349 
350  vout.general(vl, "2-point correlator:\n");
351 
352  //- case(iq_1 == iq_2)
353  for (int iq = 0; iq < N_quark; ++iq) {
354  vout.general(vl, "Flavor combination = %d, %d\n", iq + 1, iq + 1);
355  result[iq] = corr.meson_all(sq[iq], sq[iq]);
356  vout.general(vl, "\n");
357  }
358 
359 
360  //- case(iq_1 < iq_2)
361  for (int iq = 0; iq < N_quark; ++iq) {
362  for (int jq = iq + 1; jq < N_quark; ++jq) {
363  vout.general(vl, "Flavor combination = %d, %d\n", iq + 1, jq + 1);
364  double result_2 = corr.meson_all(sq[iq], sq[jq]);
365  vout.general(vl, "\n");
366  }
367  }
368 
369 
370  timer->report();
371 
372 #ifdef LIB_CPP11
373  // do nothing.
374 #else
375  // tidy-up
376  for (int iq = 0; iq < N_quark; ++iq) {
377  delete fopr_eo[iq];
378  delete solver[iq];
379  delete fprop_eo[iq];
380  delete source[iq];
381  delete fopr[iq];
382  }
383 #endif
384 
386 
387 
388  if (do_check) {
389  return Test::verify(result[0], expected_result);
390  } else {
391  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
392  return EXIT_SKIP;
393  }
394  }
395 } // namespace Test_Spectrum
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
std::string format()
Definition: filename.h:61
double meson_all(const std::vector< Field_F > &sq1, const std::vector< Field_F > &sq2)
double norm2() const
Definition: field.cpp:592
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
virtual void set_parameters(const Parameters &param)=0
int hadron_2ptFunction_eo(const std::string &)
void general(const char *format,...)
Definition: bridgeIO.cpp:197
int solver(const std::string &)
int shift(void)
Two-point correlator for Wilson-type fermions.
virtual void set_parameters(const Parameters &)=0
int get_int(const string &key) const
Definition: parameters.cpp:192
Class for parameters.
Definition: parameters.h:46
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:532
Wilson-type fermion field.
Definition: field_F.h:37
Parameters lookup(const string &key) const
Definition: parameters.h:79
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69
static bool initialize(const std::string &rng_type, unsigned long seed)
SU(N) gauge field.
Definition: field_G.h:38
void read(Field_G *U, const string &filename=string())
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
double get_double(const string &key) const
Definition: parameters.cpp:175
Get quark propagator for Fopr with even-odd site index.
Filename utility.
Definition: filename.h:43
void backward(Field &, const Field &, const int mu)
int non_NULL(const std::string v)
bool is_set(const string &key) const
Definition: parameters.cpp:528
void start()
Definition: timer.cpp:44
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:319
void set_config(Field *U)
set pointer to original thin link variable
int get_Nsmear()
get number of applied smearing operation
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
static void read(const std::string &params_file, Parameters &params)
Manager of smeared configurations.
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
const std::string test_name
Bridge::VerboseLevel vl
Field * getptr_smearedConfig(const int i_smear)
get pointer to i-th smeared config (0th is original thin link)
VerboseLevel
Definition: bridgeIO.h:42
void set_parameters(const Parameters &params)
set parameters, must be called before set_config
Methods to shift a field in the lexical site index.
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
virtual void fix(Field_G &Ufix, const Field_G &Uorg)=0
virtual void set_parameters(const Parameters &params)
string get_string(const string &key) const
Definition: parameters.cpp:221
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:267
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
virtual void set_parameters(const Parameters &params)=0