Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Eigensolver.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
17 
18 #include "Fopr/fopr_Smeared.h"
19 
20 #include "IO/gaugeConfig.h"
21 
23 
24 //====================================================================
26 
37 namespace Test_Eigensolver {
38  const std::string test_name = "Eigensolver.Test";
39 
40  //- test-private parameters
41  namespace {
42  const std::string filename_input = "test_Eigensolver.yaml";
43  }
44 
45  //- prototype declaration
46  int solve(void);
47 
48 #ifdef USE_TESTMANAGER_AUTOREGISTER
49  namespace {
50 #if defined(USE_GROUP_SU2)
51  // Nc=2 is not available.
52 #else
53  static const bool is_registered = TestManager::RegisterTest(
54  test_name,
55  solve
56  );
57 #endif
58  }
59 #endif
60 
61  //====================================================================
62  //- Check of eigenvalue solver
63  int solve(void)
64  {
65  // ##### parameter setup #####
66  const int Ndim = CommonParameters::Ndim();
67  const int Nvol = CommonParameters::Nvol();
68 
69  const Parameters params_all = ParameterManager::read(filename_input);
70 
71  const Parameters params_test = params_all.lookup("Test_Eigensolver");
72  const Parameters params_fopr = params_all.lookup("Fopr");
73  const Parameters params_proj = params_all.lookup("Projection");
74  const Parameters params_smear = params_all.lookup("Smear");
75  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
76  const Parameters params_irlanczos = params_all.lookup("Eigensolver");
77 
78  const string str_gconf_status = params_test.get_string("gauge_config_status");
79  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
80  const string readfile = params_test.get_string("config_filename_input");
81  const string str_rand_type = params_test.get_string("random_number_type");
82  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
83  const string str_vlevel = params_test.get_string("verbose_level");
84 
85  const bool do_check = params_test.is_set("expected_result");
86  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
87 
88  const string str_fopr_type = params_fopr.get_string("fermion_type");
89  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
90  const string str_proj_type = params_proj.get_string("projection_type");
91  const string str_smear_type = params_smear.get_string("smear_type");
92  const string str_sortfield_type = params_irlanczos.get_string("eigensolver_mode");
93  const int Nk = params_irlanczos.get_int("number_of_wanted_eigenvectors");
94  const int Np = params_irlanczos.get_int("number_of_working_eigenvectors");
95 
96  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
97 
98  //- print input parameters
99  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
100  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
101  vout.general(vl, " readfile = %s\n", readfile.c_str());
102  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
103  vout.general(vl, " seed = %lu\n", seed);
104  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
105  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
106  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
107  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
108  vout.general(vl, " sortfield_type = %s\n", str_sortfield_type.c_str());
109  vout.general(vl, "\n");
110 
111  //- input parameter check
112  int err = 0;
113  err += ParameterCheck::non_NULL(str_gconf_status);
114 
115  if (err) {
116  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
117  exit(EXIT_FAILURE);
118  }
119 
120 
121  RandomNumberManager::initialize(str_rand_type, seed);
122 
123 
124  // #### Set up a gauge configuration ####
125  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
126 
127  if (str_gconf_status == "Continue") {
128  GaugeConfig(str_gconf_read).read(U, readfile);
129  } else if (str_gconf_status == "Cold_start") {
130  GaugeConfig("Unit").read(U);
131  } else if (str_gconf_status == "Hot_start") {
132  GaugeConfig("Random").read(U);
133  } else {
134  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
135  exit(EXIT_FAILURE);
136  }
137 
138  unique_ptr<Projection> proj(Projection::New(str_proj_type));
139  proj->set_parameters(params_proj);
140 
141  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
142  smear->set_parameters(params_smear);
143 
144  unique_ptr<Director> dr_smear(new Director_Smear(smear));
145  dr_smear->set_parameters(params_dr_smear);
146 
147 
148  // #### object setup #####
149  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
150  fopr->set_parameters(params_fopr);
151 
152  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr, dr_smear));
153  fopr_smear->set_config(U);
154  fopr_smear->set_mode("H");
155 
156  const unique_ptr<Eigensolver> eigen(new Eigensolver_IRLanczos(fopr_smear));
157  eigen->set_parameters(params_irlanczos);
158 
159  const unique_ptr<Timer> timer(new Timer(test_name));
160 
161 
162  // #### Execution main part ####
163  timer->start();
164 
165  Field_F b2;
166  const int NFin = b2.nin();
167  const int NFvol = b2.nvol();
168  const int NFex = b2.nex();
169 
170  const int Nm = Nk + Np;
171  std::vector<double> TDa(Nm);
172 
173  std::vector<Field> vk(Nm);
174  for (int k = 0; k < Nm; ++k) {
175  vk[k].reset(NFin, NFvol, NFex);
176  }
177 
178  int Nsbt = -1;
179  int Nconv = -100;
180  eigen->solve(TDa, vk, Nsbt, Nconv, (Field)b2);
181 
182  for (int i = 0; i < Nsbt + 1; ++i) {
183  Field v(NFin, NFvol, NFex);
184 
185  fopr_smear->mult(v, vk[i]);
186  axpy(v, -TDa[i], vk[i]); // v -= TDa[i] * vk[i];
187  double vv = v.norm2(); // vv = v * v;
188 
189  vout.general(vl, "Eigenvalues: %4d %20.14f %20.15e \n", i, TDa[i], vv);
190  }
191 
192  const double result = TDa[0];
193 
194  timer->report();
195 
197 
198 
199  if (do_check) {
200  return Test::verify(result, expected_result);
201  } else {
202  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
203  return EXIT_SKIP;
204  }
205  }
206 } // namespace Test_Eigensolver
#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
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
const std::string test_name
virtual void set_config(Field *)=0
setting pointer to the gauge configuration.
Container of Field-type object.
Definition: field.h:45
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
virtual void solve(std::vector< double > &TDa, std::vector< Field > &vk, int &Nsbt, int &Nconv, const Field &b)=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
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
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
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
virtual void set_parameters(const Parameters &)=0
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131