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