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