Bridge++  Version 1.6.1
 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 
39 namespace Test_Eigensolver_Chebyshev {
40  const std::string test_name = "Eigensolver.Chebyshev";
41 
42  //- test-private parameters
43  namespace {
44  const std::string filename_input = "test_Eigensolver_Chebyshev.yaml";
45  }
46 
47  //- prototype declaration
48  int solve_chebyshev(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  //====================================================================
64  //- Check of eigenvalue solver
65  int solve_chebyshev(void)
66  {
67  // #### parameter setup ####
68  const int Ndim = CommonParameters::Ndim();
69  const int Nvol = CommonParameters::Nvol();
70 
71  const Parameters params_all = ParameterManager::read(filename_input);
72 
73  const Parameters params_test = params_all.lookup("Test_Eigensolver");
74  const Parameters params_fopr = params_all.lookup("Fopr");
75  const Parameters params_chebyshev = params_all.lookup("Fopr_Chebyshev");
76  const Parameters params_proj = params_all.lookup("Projection");
77  const Parameters params_smear = params_all.lookup("Smear");
78  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
79  const Parameters params_irlanczos = params_all.lookup("Eigensolver_Chebyshev");
80 
81  const string str_gconf_status = params_test.get_string("gauge_config_status");
82  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
83  const string readfile = params_test.get_string("config_filename_input");
84  const string str_rand_type = params_test.get_string("random_number_type");
85  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
86  const string str_vlevel = params_test.get_string("verbose_level");
87 
88  const bool do_check = params_test.is_set("expected_result");
89  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
90 
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_proj_type = params_proj.get_string("projection_type");
94  const string str_smear_type = params_smear.get_string("smear_type");
95  const int Nsmear = params_dr_smear.get_int("number_of_smearing");
96  const string str_sortfield_type = params_irlanczos.get_string("eigensolver_mode");
97  const int Nk = params_irlanczos.get_int("number_of_wanted_eigenvectors");
98  const int Np = params_irlanczos.get_int("number_of_working_eigenvectors");
99  const int Niter_eigen = params_irlanczos.get_int("maximum_number_of_iteration");
100  const double Enorm_eigen = params_irlanczos.get_double("convergence_criterion_squared");
101  const double Vthreshold = params_irlanczos.get_double("threshold_value");
102 
103  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
104 
105  //- print input parameters
106  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
107  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
108  vout.general(vl, " readfile = %s\n", readfile.c_str());
109  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
110  vout.general(vl, " seed = %lu\n", seed);
111  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
112  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
113  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
114  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
115  vout.general(vl, " sortfield_type = %s\n", str_sortfield_type.c_str());
116  vout.general(vl, "\n");
117 
118  //- input parameter check
119  int err = 0;
120  err += ParameterCheck::non_NULL(str_gconf_status);
121 
122  if (err) {
123  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
124  exit(EXIT_FAILURE);
125  }
126 
127  if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
128  if (CommonParameters::Nc() != 3) {
129  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
130  return EXIT_SKIP;
131  }
132  }
133 
134 
135  RandomNumberManager::initialize(str_rand_type, seed);
136 
137 
138  // #### Set up a gauge configuration ####
139  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
140 
141  if (str_gconf_status == "Continue") {
142  GaugeConfig(str_gconf_read).read(U, readfile);
143  } else if (str_gconf_status == "Cold_start") {
144  GaugeConfig("Unit").read(U);
145  } else if (str_gconf_status == "Hot_start") {
146  GaugeConfig("Random").read(U);
147  } else {
148  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
149  exit(EXIT_FAILURE);
150  }
151 
152  if (Nsmear > 0) {
153  unique_ptr<Projection> proj(Projection::New(str_proj_type));
154  proj->set_parameters(params_all.lookup("Projection"));
155 
156  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
157  smear->set_parameters(params_all.lookup("Smear"));
158 
159  const unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear));
160  dr_smear->set_parameters(params_all.lookup("Director_Smear"));
161  dr_smear->set_config(U);
162 
163  const Field_G *Usmear = (Field_G *)dr_smear->getptr_smearedConfig(Nsmear);
164  copy(*U, *Usmear);
165  }
166 
167 
168  // #### object setup #####
169  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
170  fopr->set_parameters(params_fopr);
171  fopr->set_config(U);
172  fopr->set_mode("DdagD");
173 
174  // unique_ptr<Fopr> fopr_ch(Fopr::New("Chebyshev", fopr));
175  unique_ptr<Fopr_Chebyshev> fopr_ch(new Fopr_Chebyshev(fopr.get()));
176  fopr_ch->set_parameters(params_chebyshev);
177 
178  const double Vthreshold_ch = fopr_ch->mult(Vthreshold * Vthreshold);
179  vout.general(vl, "Vthreshold_ch = %12.6f\n", Vthreshold_ch);
180 
181  //- NB. Low and High must be inversed, because of Chebyshev expansion.
182  const unique_ptr<Eigensolver_IRLanczos> eigen(new Eigensolver_IRLanczos(fopr_ch.get()));
183  eigen->set_parameters(str_sortfield_type, Nk, Np, Niter_eigen, Enorm_eigen, Vthreshold_ch);
184 
185  const unique_ptr<Timer> timer(new Timer(test_name));
186 
187 
188  // #### Execution main part ####
189  timer->start();
190 
191  Field_F b2;
192  const int NFin = b2.nin();
193  const int NFvol = b2.nvol();
194  const int NFex = b2.nex();
195 
196  const int Nm = Nk + Np;
197  std::vector<double> TDa(Nm);
198 
199  std::vector<Field> vk(Nm);
200  for (int k = 0; k < Nm; ++k) {
201  vk[k].reset(NFin, NFvol, NFex);
202  }
203 
204  int Nsbt = -1;
205  int Nconv = -100;
206  eigen->solve(TDa, vk, Nsbt, Nconv, (Field)b2);
207 
208  // vout.general(vl, " Nsbt = %d\n", Nsbt);
209  // vout.general(vl, " Nconv = %d\n", Nconv);
210 
211  for (int i = 0; i < Nsbt + 1; ++i) {
212  Field v(NFin, NFvol, NFex);
213 
214  fopr->set_mode("H");
215  fopr->mult(v, vk[i]);
216 
217  double vnum = dot(vk[i], v);
218  double vden = dot(vk[i], vk[i]);
219  double veig = vnum / vden;
220 
221  TDa[i] = veig;
222  axpy(v, -TDa[i], vk[i]); // v -= TDa[i] * vk[i];
223  double vv = v.norm2(); // vv = v * v;
224 
225  vout.general(vl, "Eigenvalues: %4d %20.14f %10.4e %10.4e\n", i, TDa[i], vv, vden - 1.0);
226  }
227 
228  const double result = TDa[0];
229 
230  timer->report();
231 
233 
234 
235  if (do_check) {
236  return Test::verify(result, expected_result);
237  } else {
238  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
239  return EXIT_SKIP;
240  }
241  }
242 } // 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:637
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:46
void solve(std::vector< double > &TDa, std::vector< Field > &vk, int &Nsbt, int &Nconv, const Field &b)
int nvol() const
Definition: field.h:128
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
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
int nin() const
Definition: field.h:127
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:129
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:320
void set_config(Field *U)
set pointer to original thin link variable
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
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
Field * getptr_smearedConfig(const int i_smear)
get pointer to i-th smeared config (0th is original thin link)
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)
void set_parameters(const Parameters &params)
set parameters, must be called before set_config
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:79
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