Bridge++  Version 1.4.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 "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 
41 namespace Test_Spectrum {
42  const std::string test_name = "Spectrum.Hadron2ptFunction_eo";
43 
44  //- test-private parameters
45  namespace {
46  // const std::string filename_input = "test_Spectrum_Clover_Hadron2ptFunction.yaml";
47  }
48 
49  //- prototype declaration
50  int hadron_2ptFunction_eo(const std::string&);
51 
52  //- hadron_2ptFunction for various fermions
54  {
55  return hadron_2ptFunction_eo("test_Spectrum_Clover_Hadron2ptFunction.yaml");
56  }
57 
58 
60  {
61  return hadron_2ptFunction_eo("test_Spectrum_Wilson_Hadron2ptFunction.yaml");
62  }
63 
64 
65 #ifdef USE_TESTMANAGER_AUTOREGISTER
66  namespace {
67 #if defined(USE_GROUP_SU2)
68  // Nc=2 is not available.
69 #else
70  static const bool is_registered_Clover_eo = TestManager::RegisterTest(
71  "Spectrum.Clover.Hadron2ptFunction_eo",
73  );
74 
75  //- NB. test_Spectrum_Wilson is implemented separately for beginners
76  // static const bool is_registered_Wilson_eo = TestManager::RegisterTest(
77  // "Spectrum.Wilson.Hadron2ptFunction_eo",
78  // hadron_2ptFunction_eo_Wilson
79  // );
80 #endif
81  }
82 #endif
83 
84  //====================================================================
85  int hadron_2ptFunction_eo(const std::string& filename_input)
86  {
87  // #### parameter setup ####
88  int Nc = CommonParameters::Nc();
89  int Nd = CommonParameters::Nd();
90  int Ndim = CommonParameters::Ndim();
91  int Nvol = CommonParameters::Nvol();
92 
93  Parameters params_all = ParameterManager::read(filename_input);
94 
95  Parameters params_test = params_all.lookup("Test_Spectrum");
96 
97  const int N_quark = params_test.get_int("number_of_valence_quarks");
98 
99  const string str_gconf_status = params_test.get_string("gauge_config_status");
100  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
101  const string readfile = params_test.get_string("config_filename_input");
102  const string str_rand_type = params_test.get_string("random_number_type");
103  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
104  const string str_vlevel = params_test.get_string("verbose_level");
105 
106  const bool do_check = params_test.is_set("expected_result");
107  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
108 
109  const string str_gfix_type = params_all.lookup("GaugeFixing").get_string("gauge_fixing_type");
110  const string str_proj_type = params_all.lookup("Projection").get_string("projection_type");
111  const string str_smear_type = params_all.lookup("Smear").get_string("smear_type");
112  const string str_solver_type = params_all.lookup("Solver").get_string("solver_type");
113 
115 
116  //- print input parameters
117  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
118  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
119  vout.general(vl, " readfile = %s\n", readfile.c_str());
120  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
121  vout.general(vl, " seed = %lu\n", seed);
122  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
123  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
124  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
125  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
126  vout.general(vl, " solver_type = %s\n", str_solver_type.c_str());
127 
128  vector<Parameters> params_quark;
129 
130  for (int iq = 0; iq < N_quark; ++iq) {
131  string qlabel = Filename("Quark_{id}").format(iq + 1);
132  params_quark.push_back(params_all.lookup(qlabel));
133  }
134 
135  // NB. all str_gmset_type are supposed to be the same.
136  string str_gmset_type = params_quark[0].lookup("Fopr").get_string("gamma_matrix_type");
137  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
138 
139  for (int iq = 0; iq < N_quark; ++iq) {
140  vout.general(vl, " Quark_%d:\n", iq + 1);
141  vout.general(vl, " source_type = %s\n",
142  params_quark[iq].lookup("Source").get_string("source_type").c_str());
143 
144  vector<int> pos = params_quark[iq].lookup("Source").get_int_vector("source_position");
145 
146  for (int mu = 0; mu < Ndim; ++mu) {
147  vout.general(vl, " source_position[%d] = %d\n", mu, pos[mu]);
148  }
149  }
150  vout.general(vl, "\n");
151 
152  //- input parameter check
153  int err = 0;
154  err += ParameterCheck::non_NULL(str_gconf_status);
155 
156  if (err) {
157  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
158  exit(EXIT_FAILURE);
159  }
160 
161  if (str_solver_type == "CG") {
162  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
163  exit(EXIT_FAILURE);
164  }
165 
166  RandomNumberManager::initialize(str_rand_type, seed);
167 
168 
169  // #### Set up a gauge configuration ####
170  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
171 
172  if (str_gconf_status == "Continue") {
173  GaugeConfig(str_gconf_read).read(U, readfile);
174  } else if (str_gconf_status == "Cold_start") {
175  GaugeConfig("Unit").read(U);
176  } else if (str_gconf_status == "Hot_start") {
177  GaugeConfig("Random").read(U);
178  } else {
179  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
180  exit(EXIT_FAILURE);
181  }
182 
183  unique_ptr<Projection> proj(Projection::New(str_proj_type));
184  proj->set_parameters(params_all.lookup("Projection"));
185 
186  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
187  smear->set_parameters(params_all.lookup("Smear"));
188 
189  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear));
190  dr_smear->set_parameters(params_all.lookup("Director_Smear"));
191  dr_smear->set_config(U);
192 
193  int Nsmear = dr_smear->get_Nsmear();
194  Field_G *Usmear = (Field_G *)dr_smear->getptr_smearedConfig(Nsmear);
195 
196 
197  // #### Gauge fixing ####
198  unique_ptr<Field_G> Ufix(new Field_G(Nvol, Ndim));
199  unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type));
200  gfix->set_parameters(params_all.lookup("GaugeFixing"));
201 
202  gfix->fix(*Ufix, *Usmear);
203 
204  copy(*U, *Ufix);
205 
206 
207  // #### object setup #####
208  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
209 
210 #ifdef LIB_CPP11
211  std::vector<unique_ptr<Fopr> > fopr(N_quark);
212  std::vector<unique_ptr<Fopr> > fopr_eo(N_quark);
213  std::vector<unique_ptr<Solver> > solver(N_quark);
214  std::vector<unique_ptr<Fprop> > fprop_eo(N_quark);
215  std::vector<unique_ptr<Source> > source(N_quark);
216 
217  // NB. Fopr is used only for check of diff2 below.
218 
219  for (int iq = 0; iq < N_quark; ++iq) {
220  string str_fopr_type = params_quark[iq].lookup("Fopr").get_string("fermion_type");
221 
222  fopr[iq].reset(Fopr::New(str_fopr_type, str_gmset_type));
223  fopr[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
224  fopr[iq]->set_config(U);
225 
226  fopr_eo[iq].reset(Fopr::New(str_fopr_type + "_eo", str_gmset_type));
227  fopr_eo[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
228  fopr_eo[iq]->set_config(U);
229 
230  solver[iq].reset(Solver::New(str_solver_type, fopr_eo[iq]));
231  solver[iq]->set_parameters(params_all.lookup("Solver"));
232 
233  fprop_eo[iq].reset(new Fprop_Standard_eo(solver[iq]));
234 
235  string str_source_type = params_quark[iq].lookup("Source").get_string("source_type");
236  source[iq].reset(Source::New(str_source_type));
237  source[iq]->set_parameters(params_quark[iq].lookup("Source"));
238  }
239 #else
240  std::vector<Fopr *> fopr(N_quark);
241  std::vector<Fopr *> fopr_eo(N_quark);
242  std::vector<Solver *> solver(N_quark);
243  std::vector<Fprop *> fprop_eo(N_quark);
244  std::vector<Source *> source(N_quark);
245 
246  // NB. Fopr is used only for check of diff2 below.
247 
248  for (int iq = 0; iq < N_quark; ++iq) {
249  string str_fopr_type = params_quark[iq].lookup("Fopr").get_string("fermion_type");
250 
251  fopr[iq] = Fopr::New(str_fopr_type, str_gmset_type);
252  fopr[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
253  fopr[iq]->set_config(U);
254 
255  fopr_eo[iq] = Fopr::New(str_fopr_type + "_eo", str_gmset_type);
256  fopr_eo[iq]->set_parameters(params_quark[iq].lookup("Fopr"));
257  fopr_eo[iq]->set_config(U);
258 
259  solver[iq] = Solver::New(str_solver_type, fopr_eo[iq]);
260  solver[iq]->set_parameters(params_all.lookup("Solver"));
261 
262  fprop_eo[iq] = new Fprop_Standard_eo(solver[iq]);
263 
264  string str_source_type = params_quark[iq].lookup("Source").get_string("source_type");
265  source[iq] = Source::New(str_source_type);
266  source[iq]->set_parameters(params_quark[iq].lookup("Source"));
267  }
268 #endif
269 
270  unique_ptr<Timer> timer(new Timer(test_name));
271 
272  Corr2pt_4spinor corr(gmset);
273  corr.set_parameters(params_all.lookup("Corr2pt_4spinor"));
274 
275 
276  // #### Execution main part ####
277  timer->start();
278 
279  typedef std::vector<Field_F> PropagatorSet;
280 
281  std::vector<PropagatorSet> sq(N_quark);
282  for (int iq = 0; iq < N_quark; ++iq) {
283  sq[iq].resize(Nc * Nd);
284 
285  for (int i = 0; i < Nc * Nd; ++i) {
286  sq[iq][i].set(0.0);
287  }
288  }
289 
290  Field_F b;
291  b.set(0.0);
292 
293  int Nconv;
294  double diff, diff2;
295 
296  for (int iq = 0; iq < N_quark; ++iq) {
297  vout.general(vl, "Solving quark propagator, flavor = %d:\n", iq + 1);
298  vout.general(vl, " color spin Nconv diff diff2\n");
299 
300  for (int ispin = 0; ispin < Nd; ++ispin) {
301  for (int icolor = 0; icolor < Nc; ++icolor) {
302  int idx = icolor + Nc * ispin;
303  source[iq]->set(b, idx);
304 
305  fprop_eo[iq]->invert_D(sq[iq][idx], b, Nconv, diff);
306 
307  Field_F y(b);
308  fopr[iq]->set_mode("D");
309  fopr[iq]->mult(y, sq[iq][idx]); // y = fopr[iq]->mult(sq[iq][idx]);
310  axpy(y, -1.0, b); // y -= b;
311  diff2 = y.norm2() / b.norm2();
312 
313  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
314  icolor, ispin, Nconv, diff, diff2);
315  }
316  }
317 
318  vout.general(vl, "\n");
319  }
320 
321 
322  //- meson correlators
323  std::vector<double> result(N_quark);
324 
325  vout.general(vl, "2-point correlator:\n");
326 
327  //- case(iq_1 == iq_2)
328  for (int iq = 0; iq < N_quark; ++iq) {
329  vout.general(vl, "Flavor combination = %d, %d\n", iq + 1, iq + 1);
330  result[iq] = corr.meson_all(sq[iq], sq[iq]);
331  vout.general(vl, "\n");
332  }
333 
334 
335  //- case(iq_1 < iq_2)
336  for (int iq = 0; iq < N_quark; ++iq) {
337  for (int jq = iq + 1; jq < N_quark; ++jq) {
338  vout.general(vl, "Flavor combination = %d, %d\n", iq + 1, jq + 1);
339  double result_2 = corr.meson_all(sq[iq], sq[jq]);
340  vout.general(vl, "\n");
341  }
342  }
343 
344 
345  timer->report();
346 
347 #ifdef LIB_CPP11
348  // do nothing.
349 #else
350  // tidy-up
351  for (int iq = 0; iq < N_quark; ++iq) {
352  delete fopr_eo[iq];
353  delete solver[iq];
354  delete fprop_eo[iq];
355  delete source[iq];
356  delete fopr[iq];
357  }
358 #endif
359 
361 
362 
363  if (do_check) {
364  return Test::verify(result[0], expected_result);
365  } else {
366  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
367  return EXIT_SKIP;
368  }
369  }
370 } // 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
int hadron_2ptFunction_eo(const std::string &)
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
Get quark propagator for Fopr with even-odd site index.
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
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)
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