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