Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Eigensolver_Chebyshev.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
17 
18 #include "Fopr/fopr_Chebyshev.h"
19 #include "Fopr/fopr_Smeared.h"
20 
21 #include "IO/gaugeConfig.h"
22 
24 
25 //====================================================================
27 
38 namespace Test_Eigensolver_Chebyshev {
39  const std::string test_name = "Eigensolver.Chebyshev";
40 
41  //- test-private parameters
42  namespace {
43  const std::string filename_input = "test_Eigensolver_Chebyshev.yaml";
44  }
45 
46  //- prototype declaration
47  int solve_chebyshev(void);
48 
49 #ifdef USE_TESTMANAGER_AUTOREGISTER
50  namespace {
51 #if defined(USE_GROUP_SU2)
52  // Nc=2 is not available.
53 #else
54  static const bool is_registered = TestManager::RegisterTest(
55  test_name,
57  );
58 #endif
59  }
60 #endif
61 
62  //====================================================================
63  //- Check of eigenvalue solver
64  int solve_chebyshev(void)
65  {
66  // #### parameter setup ####
67  const int Ndim = CommonParameters::Ndim();
68  const int Nvol = CommonParameters::Nvol();
69 
70  const Parameters params_all = ParameterManager::read(filename_input);
71 
72  const Parameters params_test = params_all.lookup("Test_Eigensolver");
73  const Parameters params_fopr = params_all.lookup("Fopr");
74  const Parameters params_chebyshev = params_all.lookup("Fopr_Chebyshev");
75  const Parameters params_proj = params_all.lookup("Projection");
76  const Parameters params_smear = params_all.lookup("Smear");
77  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
78  const Parameters params_irlanczos = params_all.lookup("Eigensolver_Chebyshev");
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_fopr_type = params_fopr.get_string("fermion_type");
91  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
92  const string str_proj_type = params_proj.get_string("projection_type");
93  const string str_smear_type = params_smear.get_string("smear_type");
94  const string str_sortfield_type = params_irlanczos.get_string("eigensolver_mode");
95  const int Nk = params_irlanczos.get_int("number_of_wanted_eigenvectors");
96  const int Np = params_irlanczos.get_int("number_of_working_eigenvectors");
97  const int Niter_eigen = params_irlanczos.get_int("maximum_number_of_iteration");
98  const double Enorm_eigen = params_irlanczos.get_double("convergence_criterion_squared");
99  const double Vthreshold = params_irlanczos.get_double("threshold_value");
100 
101  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
102 
103  //- print input parameters
104  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
105  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
106  vout.general(vl, " readfile = %s\n", readfile.c_str());
107  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
108  vout.general(vl, " seed = %lu\n", seed);
109  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
110  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
111  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
112  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
113  vout.general(vl, " sortfield_type = %s\n", str_sortfield_type.c_str());
114  vout.general(vl, "\n");
115 
116  //- input parameter check
117  int err = 0;
118  err += ParameterCheck::non_NULL(str_gconf_status);
119 
120  if (err) {
121  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
122  exit(EXIT_FAILURE);
123  }
124 
125 
126  RandomNumberManager::initialize(str_rand_type, seed);
127 
128 
129  // #### Set up a gauge configuration ####
130  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
131 
132  if (str_gconf_status == "Continue") {
133  GaugeConfig(str_gconf_read).read(U, readfile);
134  } else if (str_gconf_status == "Cold_start") {
135  GaugeConfig("Unit").read(U);
136  } else if (str_gconf_status == "Hot_start") {
137  GaugeConfig("Random").read(U);
138  } else {
139  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
140  exit(EXIT_FAILURE);
141  }
142 
143  unique_ptr<Projection> proj(Projection::New(str_proj_type));
144  proj->set_parameters(params_proj);
145 
146  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
147  smear->set_parameters(params_smear);
148 
149  unique_ptr<Director> dr_smear(new Director_Smear(smear));
150  dr_smear->set_parameters(params_dr_smear);
151 
152 
153  // #### object setup #####
154  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
155  fopr->set_parameters(params_fopr);
156 
157  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr, dr_smear));
158  fopr_smear->set_config(U);
159  fopr_smear->set_mode("DdagD");
160 
161  // unique_ptr<Fopr> fopr_ch(Fopr::New("Chebyshev", fopr_smear));
162  unique_ptr<Fopr_Chebyshev> fopr_ch(new Fopr_Chebyshev(fopr_smear.get()));
163  fopr_ch->set_parameters(params_chebyshev);
164 
165  const double Vthreshold_ch = fopr_ch->mult(Vthreshold * Vthreshold);
166  vout.general(vl, "Vthreshold_ch = %12.6f\n", Vthreshold_ch);
167 
168  //- NB. Low and High must be inversed, because of Chebyshev expansion.
169  const unique_ptr<Eigensolver_IRLanczos> eigen(new Eigensolver_IRLanczos(fopr_ch.get()));
170  eigen->set_parameters(str_sortfield_type, Nk, Np, Niter_eigen, Enorm_eigen, Vthreshold_ch);
171 
172  const unique_ptr<Timer> timer(new Timer(test_name));
173 
174 
175  // #### Execution main part ####
176  timer->start();
177 
178  Field_F b2;
179  const int NFin = b2.nin();
180  const int NFvol = b2.nvol();
181  const int NFex = b2.nex();
182 
183  const int Nm = Nk + Np;
184  std::vector<double> TDa(Nm);
185 
186  std::vector<Field> vk(Nm);
187  for (int k = 0; k < Nm; ++k) {
188  vk[k].reset(NFin, NFvol, NFex);
189  }
190 
191  int Nsbt = -1;
192  int Nconv = -100;
193  eigen->solve(TDa, vk, Nsbt, Nconv, (Field)b2);
194 
195  // vout.general(vl, " Nsbt = %d\n", Nsbt);
196  // vout.general(vl, " Nconv = %d\n", Nconv);
197 
198  for (int i = 0; i < Nsbt + 1; ++i) {
199  Field v(NFin, NFvol, NFex);
200 
201  fopr_smear->set_mode("H");
202  fopr_smear->mult(v, vk[i]);
203 
204  double vnum = dot(vk[i], v);
205  double vden = dot(vk[i], vk[i]);
206  double veig = vnum / vden;
207 
208  TDa[i] = veig;
209  axpy(v, -TDa[i], vk[i]); // v -= TDa[i] * vk[i];
210  double vv = v.norm2(); // vv = v * v;
211 
212  vout.general(vl, "Eigenvalues: %4d %20.14f %10.4e %10.4e\n", i, TDa[i], vv, vden - 1.0);
213  }
214 
215  const double result = TDa[0];
216 
217  timer->report();
218 
220 
221 
222  if (do_check) {
223  return Test::verify(result, expected_result);
224  } else {
225  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
226  return EXIT_SKIP;
227  }
228  }
229 } // namespace Test_Eigensolver_Chebyshev
#define EXIT_SKIP
Definition: test.h:17
Eigenvalue solver with Implicitly Restarted Lanczos algorithm.
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
double norm2() const
Definition: field.cpp:592
virtual void set_parameters(const Parameters &param)=0
double dot(const Field &y, const Field &x)
Definition: field.cpp:46
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
virtual void set_config(Field *)=0
setting pointer to the gauge configuration.
Container of Field-type object.
Definition: field.h:45
void solve(std::vector< double > &TDa, std::vector< Field > &vk, int &Nsbt, int &Nconv, const Field &b)
int nvol() const
Definition: field.h:127
virtual void set_parameters(const Parameters &)=0
int get_int(const string &key) const
Definition: parameters.cpp:192
Class for parameters.
Definition: parameters.h:46
Wilson-type fermion field.
Definition: field_F.h:37
int nin() const
Definition: field.h:126
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
void set_parameters(const Parameters &params)
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
void mult(Field &v, const Field &f)
multiplies fermion operator to a given field (2nd argument)
pointer get() const
int nex() const
Definition: field.h:128
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
Chebyshev polynomial of fermion operator.
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:319
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
virtual void set_parameters(const Parameters &params)=0
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
Bridge::VerboseLevel vl
void set_parameters(const Parameters &params)
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
string get_string(const string &key) const
Definition: parameters.cpp:221
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