Bridge++  Ver. 2.0.2
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 
96  {
97  return hadron_2ptFunction("test_Spectrum_Wilson_TwistedMass_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_Wilson_TwistedMass = TestManager::RegisterTest(
139  "Spectrum.Wilson_TwistedMass.Hadron2ptFunction",
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  const std::string str_gfix_type = params_all.lookup("GaugeFixing").get_string("gauge_fixing_type");
193  const std::string str_proj_type = params_all.lookup("Projection").get_string("projection_type");
194  const std::string str_smear_type = params_all.lookup("Smear").get_string("smear_type");
195  const int Nsmear = params_all.lookup("Director_Smear").get_int("number_of_smearing");
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  if ((Nsmear > 0) && (str_proj_type == "Stout_SU3")) {
258  if (CommonParameters::Nc() != 3) {
259  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
260  return EXIT_SKIP;
261  }
262  }
263 
264  if ((str_gfix_type == "Coulomb") || (str_gfix_type == "Landau")) {
265  if (CommonParameters::Nc() != 3) {
266  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
267  return EXIT_SKIP;
268  }
269  }
270 
271 
272  RandomNumberManager::initialize(str_rand_type, seed);
273 
274 
275  // #### Set up a gauge configuration ####
276  Field_G U(Nvol, Ndim);
277 
278  if (str_gconf_status == "Continue") {
279  GaugeConfig(str_gconf_read).read(U, readfile);
280  } else if (str_gconf_status == "Cold_start") {
281  GaugeConfig("Unit").read(U);
282  } else if (str_gconf_status == "Hot_start") {
283  GaugeConfig("Random").read(U);
284  } else {
285  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
286  exit(EXIT_FAILURE);
287  }
288 
289  {
291  for (int i_dir = 0; i_dir < Ndim; ++i_dir) {
292  for (int i_shift = 0; i_shift < Nshift_origin[i_dir]; ++i_shift) {
293  Field_G Ushift(Nvol, Ndim);
294  shift.backward(Ushift, U, i_dir);
295  copy(U, Ushift);
296  }
297  }
298  }
299 
300  if (Nsmear > 0) {
301  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_all.lookup("Projection")));
302  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_all.lookup("Smear")));
303  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear.get(), params_all.lookup("Director_Smear")));
304  dr_smear->set_config(&U);
305 
306  const Field_G *Usmear = (Field_G *)dr_smear->getptr_smearedConfig(Nsmear);
307  copy(U, *Usmear);
308  }
309 
310 
311  // #### Gauge fixing ####
312  {
313  Field_G Ufix(Nvol, Ndim);
314 
315  unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type, params_all.lookup("GaugeFixing")));
316 
317  gfix->fix(Ufix, U);
318  copy(U, Ufix);
319  }
320 
321 
322  // #### object setup #####
323  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
324 
325  struct QuarkType
326  {
327  unique_ptr<Fopr> fopr;
328  unique_ptr<Solver> solver;
329  unique_ptr<Fprop> fprop;
330  unique_ptr<Source> source;
331  };
332 
333  std::vector<QuarkType> quark(N_quark);
334 
335  for (int iq = 0; iq < N_quark; ++iq) {
336  const Parameters& params_fopr = params_quark[iq].lookup("Fopr");
337  const Parameters& params_solver = params_quark[iq].lookup("Solver");
338  const Parameters& params_source = params_quark[iq].lookup("Source");
339 
340  quark[iq].fopr.reset(Fopr::New(params_fopr.get_string("fermion_type"),
341  params_fopr));
342  quark[iq].fopr->set_config(&U);
343 
344  quark[iq].solver.reset(Solver::New(params_solver.get_string("solver_type"),
345  quark[iq].fopr.get(),
346  params_solver));
347 
348  quark[iq].fprop.reset(new Fprop_Standard_lex(quark[iq].solver.get()));
349 
350  quark[iq].source.reset(Source::New(params_source.get_string("source_type"),
351  params_source));
352  }
353 
354  Corr2pt_4spinor corr(gmset.get(), params_all.lookup("Corr2pt_4spinor"));
355 
356  Timer timer(test_name);
357 
358 
359  // #### Execution main part ####
360  timer.start();
361 
362  typedef std::vector<Field_F> PropagatorSet;
363  std::vector<PropagatorSet> sq(N_quark);
364  for (int iq = 0; iq < N_quark; ++iq) {
365  sq[iq].resize(Nc * Nd);
366 
367  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
368  sq[iq][i_cd].set(0.0);
369  }
370  }
371 
372  for (int iq = 0; iq < N_quark; ++iq) {
373  vout.general(vl, "Solving quark propagator, flavor = %d:\n", iq + 1);
374  vout.general(vl, " color spin Nconv diff diff2\n");
375 
376  for (int ispin = 0; ispin < Nd; ++ispin) {
377  for (int icolor = 0; icolor < Nc; ++icolor) {
378  int i_cd = icolor + Nc * ispin;
379 
380  Field_F b; // b.set(0.0);
381  quark[iq].source->set(b, i_cd);
382 
383  int Nconv;
384  double diff;
385  quark[iq].fprop->invert_D(sq[iq][i_cd], b, Nconv, diff);
386 
387  Field_F y(b);
388  quark[iq].fopr->set_mode("D");
389  quark[iq].fopr->mult(y, sq[iq][i_cd]); // y = fopr[iq]->mult(sq[iq][i_cd]);
390  axpy(y, -1.0, b); // y -= b;
391  double diff2 = y.norm2() / b.norm2();
392 
393  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
394  icolor, ispin, Nconv, diff, diff2);
395  }
396  }
397 
398  vout.general(vl, "\n");
399  }
400 
401 
402  //- meson correlators
403  std::vector<double> result(N_quark);
404 
405  vout.general(vl, "2-point correlator:\n");
406 
407  //- case(iq_1 == iq_2)
408  for (int iq = 0; iq < N_quark; ++iq) {
409  vout.general(vl, "Flavor combination = %d, %d\n", iq + 1, iq + 1);
410  result[iq] = corr.meson_all(sq[iq], sq[iq]);
411  vout.general(vl, "\n");
412  }
413 
414  //- case(iq_1 < iq_2)
415  for (int iq = 0; iq < N_quark; ++iq) {
416  for (int jq = iq + 1; jq < N_quark; ++jq) {
417  vout.general(vl, "Flavor combination = %d, %d\n", iq + 1, jq + 1);
418  double result_2 = corr.meson_all(sq[iq], sq[jq]);
419  vout.general(vl, "\n");
420  }
421  }
422 
423 
424  timer.report();
425 
427 
428 
429  if (do_check) {
430  return Test::verify(result[0], expected_result);
431  } else {
432  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
433  return EXIT_SKIP;
434  }
435  }
436 } // namespace Test_Spectrum
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Test_Spectrum::hadron_2ptFunction_WilsonGeneral
int hadron_2ptFunction_WilsonGeneral()
Definition: test_Spectrum_2ptFunction.cpp:117
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
Fprop_Standard_lex
Get quark propagator for Fopr with lexical site index.
Definition: fprop_Standard_lex.h:33
Test_Spectrum::test_name
const std::string test_name
Definition: test_Spectrum_2ptFunction.cpp:72
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
Field::set
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
Parameters
Class for parameters.
Definition: parameters.h:46
Corr2pt_4spinor::meson_all
double meson_all(const std::vector< Field_F > &sq1, const std::vector< Field_F > &sq2)
Definition: corr2pt_4spinor.cpp:53
shiftField_lex.h
Parameters::get_int
int get_int(const string &key) const
Definition: parameters.cpp:192
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
GaugeConfig::read
void read(Field_G &U, const string &filename=string())
Definition: gaugeConfig.cpp:121
fprop_Standard_lex.h
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
filename.h
Parameters::get_int_vector
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:267
source.h
Timer
Definition: timer.h:31
RandomNumberManager::finalize
static void finalize()
Definition: randomNumberManager.cpp:80
copy
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:212
Test_Spectrum::hadron_2ptFunction_Wilson_TwistedMass
int hadron_2ptFunction_Wilson_TwistedMass()
Definition: test_Spectrum_2ptFunction.cpp:95
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Field::norm2
double norm2() const
Definition: field.cpp:113
Timer::start
void start()
Definition: timer.cpp:44
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
Test_Spectrum::hadron_2ptFunction_CloverGeneral
int hadron_2ptFunction_CloverGeneral()
Definition: test_Spectrum_2ptFunction.cpp:89
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
Test_Spectrum::hadron_2ptFunction_Wilson_ShiftOrigin
int hadron_2ptFunction_Wilson_ShiftOrigin()
Definition: test_Spectrum_2ptFunction.cpp:105
test.h
Test_Spectrum::hadron_2ptFunction_Wilson_WallSource
int hadron_2ptFunction_Wilson_WallSource()
Definition: test_Spectrum_2ptFunction.cpp:111
ParameterManager::read
static void read(const std::string &params_file, Parameters &params)
Definition: parameterManager.cpp:33
Parameters::get_double
double get_double(const string &key) const
Definition: parameters.cpp:175
Corr2pt_4spinor
Two-point correlator for Wilson-type fermions.
Definition: corr2pt_4spinor.h:42
Director_Smear
Manager of smeared configurations.
Definition: director_Smear.h:39
Test_Solver_Wilson::solver
int solver(const std::string &)
Definition: test_Solver_Wilson.cpp:134
ShiftField_lex
Methods to shift a field in the lexical site index.
Definition: shiftField_lex.h:39
Test_Spectrum::hadron_2ptFunction_Clover
int hadron_2ptFunction_Clover()
Definition: test_Spectrum_2ptFunction.cpp:83
Parameters::get_unsigned_long
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
EXIT_SKIP
#define EXIT_SKIP
Definition: test.h:17
CommonParameters::Nd
static int Nd()
Definition: commonParameters.h:116
randomNumberManager.h
Test_Spectrum
Test of spectroscopy.
Definition: test_Spectrum_2ptFunction.cpp:71
GaugeConfig
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:80
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
Parameters::is_set
bool is_set(const string &key) const
Definition: parameters.cpp:525
Field_F
Wilson-type fermion field.
Definition: field_F.h:37
fopr_Smeared.h
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
gaugeFixing.h
Test_Spectrum::hadron_2ptFunction
int hadron_2ptFunction(const std::string &)
Definition: test_Spectrum_2ptFunction.cpp:168
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
corr2pt_4spinor.h
Filename::format
std::string format()
Definition: filename.h:61
Filename
Filename utility.
Definition: filename.h:43
gammaMatrixSet.h
Parameters::lookup
Parameters lookup(const string &key) const
Definition: parameters.h:79
Timer::report
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
Test_Gauge::shift
int shift(void)
Definition: test_Gauge_Shift.cpp:58
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
TestManager::RegisterTest
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69