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