Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Solver_Wilson.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
21 
22 #include "Tools/gammaMatrixSet.h"
24 
25 #ifdef LIB_CPP11
26 using std::round;
27 #endif
28 
29 //====================================================================
31 
37 namespace Test_Solver_Wilson {
38  const std::string test_name = "Solver.Wilson";
39 
40  //- test-private parameters
41  namespace {
42  // const std::string filename_input = "test_Solver_Wilson.yaml";
43  }
44 
45  //- prototype declaration
46  int solver(const std::string&);
47 
48  //- solver for various algorithms
50  {
51  return solver("test_Solver_Wilson_BiCGStab_Cmplx.yaml");
52  }
53 
54 
56  {
57  return solver("test_Solver_Wilson_BiCGStab_DS_L_Cmplx.yaml");
58  }
59 
60 
62  {
63  return solver("test_Solver_Wilson_BiCGStab_IDS_L_Cmplx.yaml");
64  }
65 
66 
68  {
69  return solver("test_Solver_Wilson_BiCGStab_L_Cmplx.yaml");
70  }
71 
72 
74  {
75  return solver("test_Solver_Wilson_CGNE.yaml");
76  }
77 
78 
80  {
81  return solver("test_Solver_Wilson_CGNR.yaml");
82  }
83 
84 
86  {
87  return solver("test_Solver_Wilson_GMRES_m_Cmplx.yaml");
88  }
89 
90 
91 #ifdef USE_TESTMANAGER_AUTOREGISTER
92  namespace {
93 #if defined(USE_GROUP_SU2)
94  // Nc=2 is not available.
95 #else
96  static const bool is_registered_BiCGStab_Cmplx = TestManager::RegisterTest(
97  "Solver.Wilson.BiCGStab_Cmplx",
99  );
100 
101  static const bool is_registered_BiCGStab_DS_L_Cmplx = TestManager::RegisterTest(
102  "Solver.Wilson.BiCGStab_DS_L_Cmplx",
104  );
105 
106  static const bool is_registered_BiCGStab_IDS_L_Cmplx = TestManager::RegisterTest(
107  "Solver.Wilson.BiCGStab_IDS_L_Cmplx",
109  );
110 
111  static const bool is_registered_BiCGStab_L_Cmplx = TestManager::RegisterTest(
112  "Solver.Wilson.BiCGStab_L_Cmplx",
114  );
115 
116  static const bool is_registered_CGNE = TestManager::RegisterTest(
117  "Solver.Wilson.CGNE",
119  );
120 
121  static const bool is_registered_CGNR = TestManager::RegisterTest(
122  "Solver.Wilson.CGNR",
124  );
125 
126  static const bool is_registered_GMRES_m_Cmplx = TestManager::RegisterTest(
127  "Solver.Wilson.GMRES_m_Cmplx",
129  );
130 #endif
131  }
132 #endif
133 
134  //====================================================================
135  int solver(const std::string& filename_input)
136  {
137  // #### parameter setup ####
138  const int Nc = CommonParameters::Nc();
139  const int Nd = CommonParameters::Nd();
140  const int Ndim = CommonParameters::Ndim();
141  const int Nvol = CommonParameters::Nvol();
142 
143  const Parameters params_all = ParameterManager::read(filename_input);
144 
145  const Parameters params_test = params_all.lookup("Test_Solver");
146  const Parameters params_gfix = params_all.lookup("GaugeFixing");
147  const Parameters params_fopr = params_all.lookup("Fopr");
148  const Parameters params_solver = params_all.lookup("Solver");
149  const Parameters params_source = params_all.lookup("Source");
150 
151  const string str_gconf_status = params_test.get_string("gauge_config_status");
152  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
153  const string readfile = params_test.get_string("config_filename_input");
154  const string str_rand_type = params_test.get_string("random_number_type");
155  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
156  const string str_vlevel = params_test.get_string("verbose_level");
157 
158  const bool do_check = params_test.is_set("expected_result");
159  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
160 
161  const string str_gfix_type = params_gfix.get_string("gauge_fixing_type");
162  const string str_fopr_type = params_fopr.get_string("fermion_type");
163  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
164  const string str_solver_type = params_solver.get_string("solver_type");
165  const string str_source_type = params_source.get_string("source_type");
166 
167  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
168 
169  //- print input parameters
170  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
171  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
172  vout.general(vl, " readfile = %s\n", readfile.c_str());
173  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
174  vout.general(vl, " seed = %lu\n", seed);
175  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
176  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
177  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
178  vout.general(vl, " solver_type = %s\n", str_solver_type.c_str());
179  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
180 
181  //- input parameter check
182  int err = 0;
183  err += ParameterCheck::non_NULL(str_gconf_status);
184 
185  if (err) {
186  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
187  exit(EXIT_FAILURE);
188  }
189 
190  if (str_solver_type == "CG") {
191  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
192  exit(EXIT_FAILURE);
193  }
194 
195  RandomNumberManager::initialize(str_rand_type, seed);
196 
197 
198  // #### Set up a gauge configuration ####
199  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
200 
201  if (str_gconf_status == "Continue") {
202  GaugeConfig(str_gconf_read).read(U, readfile);
203  } else if (str_gconf_status == "Cold_start") {
204  GaugeConfig("Unit").read(U);
205  } else if (str_gconf_status == "Hot_start") {
206  GaugeConfig("Random").read(U);
207  } else {
208  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
209  exit(EXIT_FAILURE);
210  }
211 
212 
213  // #### Gauge fixing ####
214  {
215  unique_ptr<Field_G> Ufix(new Field_G(Nvol, Ndim));
216  const unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type));
217  gfix->set_parameters(params_gfix);
218 
219  gfix->fix(*Ufix, *U);
220 
221  copy(*U, *Ufix);
222  }
223 
224 
225  // #### object setup #####
226  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
227 
228  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
229  fopr->set_parameters(params_fopr);
230  fopr->set_config(U);
231 
232  unique_ptr<Solver> solver(Solver::New(str_solver_type, fopr));
233  solver->set_parameters(params_solver);
234 
235  const unique_ptr<Fprop> fprop_lex(new Fprop_Standard_lex(solver));
236 
237  const unique_ptr<Source> source(Source::New(str_source_type));
238  source->set_parameters(params_source);
239 
240  const unique_ptr<Timer> timer(new Timer(test_name));
241 
242 
243  // #### Execution main part ####
244  timer->start();
245 
246  std::vector<Field_F> sq(Nc * Nd);
247  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
248  sq[i_cd].set(0.0);
249  }
250 
251  vout.general(vl, "\n");
252  vout.general(vl, "Solving quark propagator:\n");
253  vout.general(vl, " color spin Nconv diff diff2\n");
254 
255  int ispin = 0;
256  // for (int ispin = 0; ispin < Nd; ++ispin) {
257 
258  int icolor = 0;
259  // for (int icolor = 0; icolor < Nc; ++icolor) {
260  int i_cd = icolor + Nc * ispin;
261 
262  Field_F b; // b.set(0.0);
263  source->set(b, i_cd);
264 
265  int Nconv;
266  double diff;
267  fprop_lex->invert_D(sq[i_cd], b, Nconv, diff);
268 
269  Field_F y(b);
270  fopr->set_mode("D");
271  fopr->mult(y, sq[i_cd]); // y = fopr->mult(sq[i_cd]);
272  axpy(y, -1.0, b); // y -= b;
273  double diff2 = y.norm2() / b.norm2();
274 
275  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
276  icolor, ispin, Nconv, diff, diff2);
277  // }
278  // }
279 
280  const double result = round(Nconv / 10.0);
281 
282  timer->report();
283 
285 
286 
287  if (do_check) {
288  return Test::verify(result, expected_result);
289  } else {
290  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
291  return EXIT_SKIP;
292  }
293  }
294 } // namespace Test_Solver_Wilson
#define EXIT_SKIP
Definition: test.h:17
const std::string test_name
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
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.
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
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