Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Spectrum_Wilson_2ptFunction.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
22 
23 #include "Tools/gammaMatrixSet.h"
25 
26 //====================================================================
28 
39 namespace Test_Spectrum_Wilson {
40  const std::string test_name = "Spectrum.Wilson.Hadron2ptFunction";
41 
42  //- test-private parameters
43  namespace {
44  const std::string filename_input = "test_Spectrum_Wilson_Hadron2ptFunction.yaml";
45  }
46 
47  //- prototype declaration
48  int hadron_2ptFunction(void);
49 
50 #ifdef USE_TESTMANAGER_AUTOREGISTER
51  namespace {
52 #if defined(USE_GROUP_SU2)
53  // Nc=2 is not available.
54 #else
55  static const bool is_registered = TestManager::RegisterTest(
56  test_name,
58  );
59 #endif
60  }
61 #endif
62 
63  //====================================================================
65  {
66  // #### parameter setup ####
67  const int Nc = CommonParameters::Nc();
68  const int Nd = CommonParameters::Nd();
69  const int Ndim = CommonParameters::Ndim();
70  const int Nvol = CommonParameters::Nvol();
71 
72  const Parameters params_all = ParameterManager::read(filename_input);
73 
74  const Parameters params_test = params_all.lookup("Test_Spectrum");
75  const Parameters params_gfix = params_all.lookup("GaugeFixing");
76  const Parameters params_fopr = params_all.lookup("Fopr");
77  const Parameters params_solver = params_all.lookup("Solver");
78  const Parameters params_source = params_all.lookup("Source");
79 
80  const string str_gconf_status = params_test.get_string("gauge_config_status");
81  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
82  const string readfile = params_test.get_string("config_filename_input");
83  const string str_rand_type = params_test.get_string("random_number_type");
84  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
85  const string str_vlevel = params_test.get_string("verbose_level");
86 
87  const bool do_check = params_test.is_set("expected_result");
88  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
89 
90  const string str_gfix_type = params_gfix.get_string("gauge_fixing_type");
91  const string str_fopr_type = params_fopr.get_string("fermion_type");
92  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
93  const string str_solver_type = params_solver.get_string("solver_type");
94  const string str_source_type = params_source.get_string("source_type");
95 
96  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
97 
98  //- print input parameters
99  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
100  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
101  vout.general(vl, " readfile = %s\n", readfile.c_str());
102  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
103  vout.general(vl, " seed = %lu\n", seed);
104  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
105  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
106  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
107  vout.general(vl, " solver_type = %s\n", str_solver_type.c_str());
108  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
109 
110  //- input parameter check
111  int err = 0;
112  err += ParameterCheck::non_NULL(str_gconf_status);
113 
114  if (err) {
115  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
116  exit(EXIT_FAILURE);
117  }
118 
119  if (str_solver_type == "CG") {
120  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
121  exit(EXIT_FAILURE);
122  }
123 
124  RandomNumberManager::initialize(str_rand_type, seed);
125 
126 
127  // #### Set up a gauge configuration ####
128  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
129 
130  if (str_gconf_status == "Continue") {
131  GaugeConfig(str_gconf_read).read(U, readfile);
132  } else if (str_gconf_status == "Cold_start") {
133  GaugeConfig("Unit").read(U);
134  } else if (str_gconf_status == "Hot_start") {
135  GaugeConfig("Random").read(U);
136  } else {
137  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
138  exit(EXIT_FAILURE);
139  }
140 
141 
142  // #### Gauge fixing ####
143  {
144  unique_ptr<Field_G> Ufix(new Field_G(Nvol, Ndim));
145  const unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type));
146  gfix->set_parameters(params_gfix);
147 
148  gfix->fix(*Ufix, *U);
149 
150  copy(*U, *Ufix);
151  }
152 
153 
154  // #### object setup #####
155  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
156 
157  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
158  fopr->set_parameters(params_fopr);
159  fopr->set_config(U);
160 
161  unique_ptr<Solver> solver(Solver::New(str_solver_type, fopr));
162  solver->set_parameters(params_solver);
163 
164  const unique_ptr<Fprop> fprop_lex(new Fprop_Standard_lex(solver));
165 
166  const unique_ptr<Source> source(Source::New(str_source_type));
167  source->set_parameters(params_source);
168 
169  Corr2pt_4spinor corr(gmset);
170  corr.set_parameters(params_all.lookup("Corr2pt_4spinor"));
171 
172  const unique_ptr<Timer> timer(new Timer(test_name));
173 
174 
175  // #### Execution main part ####
176  timer->start();
177 
178  std::vector<Field_F> sq(Nc * Nd);
179  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
180  sq[i_cd].set(0.0);
181  }
182 
183  vout.general(vl, "\n");
184  vout.general(vl, "Solving quark propagator:\n");
185  vout.general(vl, " color spin Nconv diff diff2\n");
186 
187  for (int ispin = 0; ispin < Nd; ++ispin) {
188  for (int icolor = 0; icolor < Nc; ++icolor) {
189  int i_cd = icolor + Nc * ispin;
190 
191  Field_F b; // b.set(0.0);
192  source->set(b, i_cd);
193 
194  int Nconv;
195  double diff;
196  fprop_lex->invert_D(sq[i_cd], b, Nconv, diff);
197 
198  Field_F y(b);
199  fopr->set_mode("D");
200  fopr->mult(y, sq[i_cd]); // y = fopr->mult(sq[i_cd]);
201  axpy(y, -1.0, b); // y -= b;
202  double diff2 = y.norm2() / b.norm2();
203 
204  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
205  icolor, ispin, Nconv, diff, diff2);
206  }
207  }
208 
209  //- meson correlators
210  vout.general(vl, "\n");
211  vout.general(vl, "2-point correlator:\n");
212 
213  const double result = corr.meson_all(sq, sq);
214 
215  timer->report();
216 
218 
219 
220  if (do_check) {
221  return Test::verify(result, expected_result);
222  } else {
223  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
224  return EXIT_SKIP;
225  }
226  }
227 } // namespace Test_Spectrum_Wilson
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
double meson_all(const std::vector< Field_F > &sq1, const std::vector< Field_F > &sq2)
double norm2() const
Definition: field.cpp:592
void general(const char *format,...)
Definition: bridgeIO.cpp:197
virtual void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr.h:94
int solver(const std::string &)
virtual void set_config(Field *)=0
setting pointer to the gauge configuration.
Two-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
virtual void set_parameters(const Parameters &params)=0
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
virtual void invert_D(Field &, const Field &, int &, double &)=0
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
virtual void set_parameters(const Parameters &)=0
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 crucial(const char *format,...)
Definition: bridgeIO.cpp:178
static void read(const std::string &params_file, Parameters &params)
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
virtual void mult(Field &, const Field &)=0
multiplies fermion operator to a given field (2nd argument)
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
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
virtual void set_parameters(const Parameters &)=0
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
virtual void set(Field &, const int)=0
virtual void set_parameters(const Parameters &params)=0