Bridge++  Version 1.6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Spectrum_2ptFunction.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 
46 /*
47  Description of Parameters
48 
49  Test_Spectrum:
50  gauge_config_status: { Continue, Cold_start, or Hot_start }
51  gauge_config_type_input: { file and I/O type }
52  config_filename_input: { filename of gauge config file }
53 
54  number_of_valence_quarks: { number of valence quarks, N_quark }
55 
56  verbose_level: { verbose level }
57  expected_result: { result value }
58 
59  Quark_{1,2,... N_quark }:
60  Fopr: { Fopr type and parameters }
61  Solver: { Solver type and parameters }
62  Source: { Source type and parameters }
63 
64  Projection:
65  Smear:
66  Director_Smear: { parameters for smearing }
67 
68  GaugeFixing: { gauge fixing type and parameters }
69  */
70 
71 namespace Test_Spectrum {
72  const std::string test_name = "Spectrum.Hadron2ptFunction";
73 
74  //- test-private parameters
75  namespace {
76  // const std::string filename_input = "test_Spectrum_Clover_Hadron2ptFunction.yaml";
77  }
78 
79  //- prototype declaration
80  int hadron_2ptFunction(const std::string&);
81 
82  //- hadron_2ptFunction for various fermions
84  {
85  return hadron_2ptFunction("test_Spectrum_Clover_Hadron2ptFunction.yaml");
86  }
87 
88 
90  {
91  return hadron_2ptFunction("test_Spectrum_CloverGeneral_Hadron2ptFunction.yaml");
92  }
93 
94 
95  //- NB. test_Spectrum_Wilson is implemented separately for beginners
96  // int hadron_2ptFunction_Wilson() {
97  // return hadron_2ptFunction("test_Spectrum_Wilson_Hadron2ptFunction.yaml");
98  // }
100  {
101  return hadron_2ptFunction("test_Spectrum_Wilson_Hadron2ptFunction_ShiftOrigin.yaml");
102  }
103 
104 
106  {
107  return hadron_2ptFunction("test_Spectrum_Wilson_Hadron2ptFunction_WallSource.yaml");
108  }
109 
110 
112  {
113  return hadron_2ptFunction("test_Spectrum_WilsonGeneral_Hadron2ptFunction.yaml");
114  }
115 
116 
117 #ifdef USE_TESTMANAGER_AUTOREGISTER
118  namespace {
119 #if defined(USE_GROUP_SU2)
120  // Nc=2 is not available.
121 #else
122  static const bool is_registered_Clover = TestManager::RegisterTest(
123  "Spectrum.Clover.Hadron2ptFunction",
125  );
126 
127  static const bool is_registered_CloverGeneral = TestManager::RegisterTest(
128  "Spectrum.CloverGeneral.Hadron2ptFunction",
130  );
131 
132  //- NB. test_Spectrum_Wilson is implemented separately for beginners
133  // static const bool is_registered_Wilson = TestManager::RegisterTest(
134  // "Spectrum.Wilson.Hadron2ptFunction",
135  // hadron_2ptFunction_Wilson
136  // );
137 
138  static const bool is_registered_Wilson_ShiftOrigin = TestManager::RegisterTest(
139  "Spectrum.Wilson.Hadron2ptFunction_ShiftOrigin",
141  );
142 
143  static const bool is_registered_Wilson_WallSource = TestManager::RegisterTest(
144  "Spectrum.Wilson.Hadron2ptFunction_WallSource",
146  );
147 
148  static const bool is_registered_Wilson_General = TestManager::RegisterTest(
149  "Spectrum.WilsonGeneral.Hadron2ptFunction",
151  );
152 #endif
153  }
154 #endif
155 
156  //====================================================================
157  int hadron_2ptFunction(const std::string& filename_input)
158  {
159  // #### parameter setup ####
160  const int Nc = CommonParameters::Nc();
161  const int Nd = CommonParameters::Nd();
162  const int Ndim = CommonParameters::Ndim();
163  const int Nvol = CommonParameters::Nvol();
164 
165  const Parameters params_all = ParameterManager::read(filename_input);
166  const Parameters params_test = params_all.lookup("Test_Spectrum");
167 
168  const int N_quark = params_test.get_int("number_of_valence_quarks");
169 
170  const std::string str_gconf_status = params_test.get_string("gauge_config_status");
171  const std::string str_gconf_read = params_test.get_string("gauge_config_type_input");
172  const std::string readfile = params_test.get_string("config_filename_input");
173  const vector<int> Nshift_origin = params_test.get_int_vector("shift_origin");
174  const std::string str_rand_type = params_test.get_string("random_number_type");
175  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
176  const std::string str_vlevel = params_test.get_string("verbose_level");
177 
178  const bool do_check = params_test.is_set("expected_result");
179  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
180 
181  const std::string str_gfix_type = params_all.lookup("GaugeFixing").get_string("gauge_fixing_type");
182  const std::string str_proj_type = params_all.lookup("Projection").get_string("projection_type");
183  const std::string str_smear_type = params_all.lookup("Smear").get_string("smear_type");
184  const int Nsmear = params_all.lookup("Director_Smear").get_int("number_of_smearing");
185 
186  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
187 
188  //- print input parameters
189  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
190  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
191  vout.general(vl, " readfile = %s\n", readfile.c_str());
192  for (int mu = 0; mu < Ndim; ++mu) {
193  vout.general(vl, " shift_origin[%d] = %d\n", mu, Nshift_origin[mu]);
194  }
195  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
196  vout.general(vl, " seed = %lu\n", seed);
197  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
198  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
199  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
200  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
201 
202  vector<Parameters> params_quark;
203  for (int iq = 0; iq < N_quark; ++iq) {
204  std::string qlabel = Filename("Quark_{id}").format(iq + 1);
205  params_quark.push_back(params_all.lookup(qlabel));
206  }
207 
208  // NB. all str_gmset_type are supposed to be the same.
209  const std::string str_gmset_type = params_quark[0].lookup("Fopr").get_string("gamma_matrix_type");
210  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
211 
212 
213  for (int iq = 0; iq < N_quark; ++iq) {
214  vout.general(vl, " Quark_%d:\n", iq + 1);
215  vout.general(vl, " solver_type = %s\n",
216  params_quark[iq].lookup("Solver").get_string("solver_type").c_str());
217  vout.general(vl, " source_type = %s\n",
218  params_quark[iq].lookup("Source").get_string("source_type").c_str());
219 
220  vector<int> source_position = params_quark[iq].lookup("Source").get_int_vector("source_position");
221  for (int mu = 0; mu < Ndim; ++mu) {
222  vout.general(vl, " source_position[%d] = %d\n", mu, source_position[mu]);
223  }
224  }
225  vout.general(vl, "\n");
226 
227 
228  //- input parameter check
229  int err = 0;
230  err += ParameterCheck::non_NULL(str_gconf_status);
231 
232  if (err) {
233  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
234  exit(EXIT_FAILURE);
235  }
236 
237  for (int iq = 0; iq < N_quark; ++iq) {
238  std::string str_solver_type = params_quark[iq].lookup("Solver").get_string("solver_type");
239 
240  if (str_solver_type == "CG") {
241  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
242  exit(EXIT_FAILURE);
243  }
244  }
245 
246  if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
247  if (CommonParameters::Nc() != 3) {
248  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
249  return EXIT_SKIP;
250  }
251  }
252 
253  if ( (str_gfix_type == "Coulomb") || (str_gfix_type == "Landau") ) {
254  if (CommonParameters::Nc() != 3) {
255  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
256  return EXIT_SKIP;
257  }
258  }
259 
260 
261  RandomNumberManager::initialize(str_rand_type, seed);
262 
263 
264  // #### Set up a gauge configuration ####
265  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
266 
267  if (str_gconf_status == "Continue") {
268  GaugeConfig(str_gconf_read).read(U, readfile);
269  } else if (str_gconf_status == "Cold_start") {
270  GaugeConfig("Unit").read(U);
271  } else if (str_gconf_status == "Hot_start") {
272  GaugeConfig("Random").read(U);
273  } else {
274  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
275  exit(EXIT_FAILURE);
276  }
277 
278  {
280  for (int i_dir = 0; i_dir < Ndim; ++i_dir) {
281  for (int i_shift = 0; i_shift < Nshift_origin[i_dir]; ++i_shift) {
282  unique_ptr<Field_G> Ushift(new Field_G(Nvol, Ndim));
283  shift.backward(*Ushift, *U, i_dir);
284  copy(*U, *Ushift);
285  }
286  }
287  }
288 
289  if (Nsmear > 0) {
290  unique_ptr<Projection> proj(Projection::New(str_proj_type));
291  proj->set_parameters(params_all.lookup("Projection"));
292 
293  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
294  smear->set_parameters(params_all.lookup("Smear"));
295 
296  const unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear));
297  dr_smear->set_parameters(params_all.lookup("Director_Smear"));
298  dr_smear->set_config(U);
299 
300  const Field_G *Usmear = (Field_G *)dr_smear->getptr_smearedConfig(Nsmear);
301  copy(*U, *Usmear);
302  }
303 
304 
305  // #### Gauge fixing ####
306  {
307  unique_ptr<Field_G> Ufix(new Field_G(Nvol, Ndim));
308 
309  const unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type));
310  gfix->set_parameters(params_all.lookup("GaugeFixing"));
311 
312  gfix->fix(*Ufix, *U);
313 
314  copy(*U, *Ufix);
315  }
316 
317 
318  // #### object setup #####
319  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
320 
321 #ifdef LIB_CPP11
322  std::vector<unique_ptr<Fopr> > fopr(N_quark);
323  std::vector<unique_ptr<Solver> > solver(N_quark);
324  std::vector<unique_ptr<Fprop> > fprop_lex(N_quark);
325  std::vector<unique_ptr<Source> > source(N_quark);
326 
327  for (int iq = 0; iq < N_quark; ++iq) {
328  std::string str_fopr_type = params_quark[iq].lookup("Fopr").get_string("fermion_type");
329  fopr[iq].reset(Fopr::New(str_fopr_type, str_gmset_type));
330  fopr[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
331  fopr[iq]->set_config(U);
332 
333  std::string str_solver_type = params_quark[iq].lookup("Solver").get_string("solver_type");
334  solver[iq].reset(Solver::New(str_solver_type, fopr[iq]));
335  solver[iq]->set_parameters(params_quark[iq].lookup("Solver"));
336 
337  fprop_lex[iq].reset(new Fprop_Standard_lex(solver[iq]));
338 
339  std::string str_source_type = params_quark[iq].lookup("Source").get_string("source_type");
340  source[iq].reset(Source::New(str_source_type));
341  source[iq]->set_parameters(params_quark[iq].lookup("Source"));
342  }
343 #else
344  std::vector<Fopr *> fopr(N_quark);
345  std::vector<Solver *> solver(N_quark);
346  std::vector<Fprop *> fprop_lex(N_quark);
347  std::vector<Source *> source(N_quark);
348 
349  for (int iq = 0; iq < N_quark; ++iq) {
350  std::string str_fopr_type = params_quark[iq].lookup("Fopr").get_string("fermion_type");
351  fopr[iq] = Fopr::New(str_fopr_type, str_gmset_type);
352  fopr[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
353  fopr[iq]->set_config(U);
354 
355  std::string str_solver_type = params_quark[iq].lookup("Solver").get_string("solver_type");
356  solver[iq] = Solver::New(str_solver_type, fopr[iq]);
357  solver[iq]->set_parameters(params_quark[iq].lookup("Solver"));
358 
359  fprop_lex[iq] = new Fprop_Standard_lex(solver[iq]);
360 
361  std::string str_source_type = params_quark[iq].lookup("Source").get_string("source_type");
362  source[iq] = Source::New(str_source_type);
363  source[iq]->set_parameters(params_quark[iq].lookup("Source"));
364  }
365 #endif
366 
367  Corr2pt_4spinor corr(gmset);
368  corr.set_parameters(params_all.lookup("Corr2pt_4spinor"));
369 
370  const unique_ptr<Timer> timer(new Timer(test_name));
371 
372 
373  // #### Execution main part ####
374  timer->start();
375 
376  typedef std::vector<Field_F> PropagatorSet;
377  std::vector<PropagatorSet> sq(N_quark);
378  for (int iq = 0; iq < N_quark; ++iq) {
379  sq[iq].resize(Nc * Nd);
380 
381  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
382  sq[iq][i_cd].set(0.0);
383  }
384  }
385 
386  for (int iq = 0; iq < N_quark; ++iq) {
387  vout.general(vl, "Solving quark propagator, flavor = %d:\n", iq + 1);
388  vout.general(vl, " color spin Nconv diff diff2\n");
389 
390  for (int ispin = 0; ispin < Nd; ++ispin) {
391  for (int icolor = 0; icolor < Nc; ++icolor) {
392  int i_cd = icolor + Nc * ispin;
393 
394  Field_F b; // b.set(0.0);
395  source[iq]->set(b, i_cd);
396 
397  int Nconv;
398  double diff;
399  fprop_lex[iq]->invert_D(sq[iq][i_cd], b, Nconv, diff);
400 
401  Field_F y(b);
402  fopr[iq]->set_mode("D");
403  fopr[iq]->mult(y, sq[iq][i_cd]); // y = fopr[iq]->mult(sq[iq][i_cd]);
404  axpy(y, -1.0, b); // y -= b;
405  double diff2 = y.norm2() / b.norm2();
406 
407  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
408  icolor, ispin, Nconv, diff, diff2);
409  }
410  }
411 
412  vout.general(vl, "\n");
413  }
414 
415 
416  //- meson correlators
417  std::vector<double> result(N_quark);
418 
419  vout.general(vl, "2-point correlator:\n");
420 
421  //- case(iq_1 == iq_2)
422  for (int iq = 0; iq < N_quark; ++iq) {
423  vout.general(vl, "Flavor combination = %d, %d\n", iq + 1, iq + 1);
424  result[iq] = corr.meson_all(sq[iq], sq[iq]);
425  vout.general(vl, "\n");
426  }
427 
428  //- case(iq_1 < iq_2)
429  for (int iq = 0; iq < N_quark; ++iq) {
430  for (int jq = iq + 1; jq < N_quark; ++jq) {
431  vout.general(vl, "Flavor combination = %d, %d\n", iq + 1, jq + 1);
432  double result_2 = corr.meson_all(sq[iq], sq[jq]);
433  vout.general(vl, "\n");
434  }
435  }
436 
437 
438  timer->report();
439 
441 
442 #ifdef LIB_CPP11
443  // do nothing
444 #else
445  // tidy-up
446  for (int iq = 0; iq < N_quark; ++iq) {
447  delete fopr[iq];
448  delete solver[iq];
449  delete fprop_lex[iq];
450  delete source[iq];
451  }
452 #endif
453 
454  if (do_check) {
455  return Test::verify(result[0], expected_result);
456  } else {
457  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
458  return EXIT_SKIP;
459  }
460  }
461 } // 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:637
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:176
virtual void set_parameters(const Parameters &param)=0
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
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:320
Get quark propagator for Fopr with lexical site index.
void set_config(Field *U)
set pointer to original thin link variable
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:79
Definition: timer.h:31
virtual void fix(Field_G &Ufix, const Field_G &Uorg)=0
virtual void set_parameters(const Parameters &params)
int hadron_2ptFunction(const std::string &)
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