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