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