Bridge++  Version 1.4.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 "Tests/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  int Nc = CommonParameters::Nc();
68  int Nd = CommonParameters::Nd();
69  int Ndim = CommonParameters::Ndim();
70  int Nvol = CommonParameters::Nvol();
71 
72  Parameters params_all = ParameterManager::read(filename_input);
73 
74  Parameters params_test = params_all.lookup("Test_Spectrum");
75  Parameters params_gfix = params_all.lookup("GaugeFixing");
76  Parameters params_fopr = params_all.lookup("Fopr");
77  Parameters params_solver = params_all.lookup("Solver");
78  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 
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  unique_ptr<Field_G> Ufix(new Field_G(Nvol, Ndim));
144  unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type));
145  gfix->set_parameters(params_gfix);
146 
147  gfix->fix(*Ufix, *U);
148 
149  copy(*U, *Ufix);
150 
151 
152  // #### object setup #####
153  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
154 
155  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
156  fopr->set_parameters(params_fopr);
157  fopr->set_config(U);
158 
159  unique_ptr<Solver> solver(Solver::New(str_solver_type, fopr));
160  solver->set_parameters(params_solver);
161 
162  unique_ptr<Fprop> fprop_lex(new Fprop_Standard_lex(solver));
163 
164  unique_ptr<Source> source(Source::New(str_source_type));
165  source->set_parameters(params_source);
166 
167  unique_ptr<Timer> timer(new Timer(test_name));
168 
169  Corr2pt_4spinor corr(gmset);
170  corr.set_parameters(params_all.lookup("Corr2pt_4spinor"));
171 
172 
173  // #### Execution main part ####
174  timer->start();
175 
176  std::vector<Field_F> sq(Nc * Nd);
177  for (int i = 0; i < Nc * Nd; ++i) {
178  sq[i].set(0.0);
179  }
180 
181  Field_F b;
182  b.set(0.0);
183 
184  int Nconv;
185  double diff;
186 
187  vout.general(vl, "\n");
188  vout.general(vl, "Solving quark propagator:\n");
189  vout.general(vl, " color spin Nconv diff diff2\n");
190 
191  for (int ispin = 0; ispin < Nd; ++ispin) {
192  for (int icolor = 0; icolor < Nc; ++icolor) {
193  int idx = icolor + Nc * ispin;
194  source->set(b, idx);
195 
196  fprop_lex->invert_D(sq[idx], b, Nconv, diff);
197 
198  Field_F y(b);
199  fopr->set_mode("D");
200  fopr->mult(y, sq[idx]); // y = fopr->mult(sq[idx]);
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  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:495
void detailed(const char *format,...)
Definition: bridgeIO.cpp:212
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
void general(const char *format,...)
Definition: bridgeIO.cpp:195
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:381
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:78
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:104
double get_double(const string &key) const
Definition: parameters.cpp:70
virtual void set_parameters(const Parameters &)=0
int non_NULL(const std::string v)
Definition: checker.cpp:61
bool is_set(const string &key) const
Definition: parameters.cpp:396
virtual void set(Field &, int)=0
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
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
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:42
virtual void mult(Field &, const Field &)=0
multiplies fermion operator to a given field (2nd argument)
virtual void set_mode(std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr.h:96
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
virtual void set_parameters(const Parameters &)=0
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
virtual void set_parameters(const Parameters &params)=0