Bridge++  Version 1.4.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 "Tests/test.h"
15 
17 
18 #include "Fopr/fopr_Smeared.h"
19 
20 #include "IO/gaugeConfig.h"
21 
22 #include "Smear/projection.h"
23 
25 #include "Tools/vec_SU_N.h"
26 
27 //====================================================================
29 
40 namespace Test_Eigensolver {
41  const std::string test_name = "Eigensolver.Test";
42 
43  //- test-private parameters
44  namespace {
45  const std::string filename_input = "test_Eigensolver.yaml";
46  }
47 
48  //- prototype declaration
49  int solve(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,
58  solve
59  );
60 #endif
61  }
62 #endif
63 
64  //====================================================================
65  //- Check of eigenvalue solver
66  int solve(void)
67  {
68  // ##### parameter setup #####
69  int Ndim = CommonParameters::Ndim();
70  int Nvol = CommonParameters::Nvol();
71 
72  Parameters params_all = ParameterManager::read(filename_input);
73 
74  Parameters params_test = params_all.lookup("Test_Eigensolver");
75  Parameters params_fopr = params_all.lookup("Fopr");
76  Parameters params_proj = params_all.lookup("Projection");
77  Parameters params_smear = params_all.lookup("Smear");
78  Parameters params_dr_smear = params_all.lookup("Director_Smear");
79  Parameters params_irlanczos = params_all.lookup("Eigensolver");
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 string str_sortfield_type = params_irlanczos.get_string("eigensolver_mode");
96  const int Nk = params_irlanczos.get_int("number_of_wanted_eigenvectors");
97  const int Np = params_irlanczos.get_int("number_of_working_eigenvectors");
98 
100 
101  //- print input parameters
102  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
103  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
104  vout.general(vl, " readfile = %s\n", readfile.c_str());
105  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
106  vout.general(vl, " seed = %lu\n", seed);
107  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
108  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
109  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
110  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
111  vout.general(vl, " sortfield_type = %s\n", str_sortfield_type.c_str());
112  vout.general(vl, "\n");
113 
114  //- input parameter check
115  int err = 0;
116  err += ParameterCheck::non_NULL(str_gconf_status);
117 
118  if (err) {
119  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
120  exit(EXIT_FAILURE);
121  }
122 
123 
124  RandomNumberManager::initialize(str_rand_type, seed);
125 
126 
127  // #### Set up a gauge configuration ####
128  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
129 
130  if (str_gconf_status == "Continue") {
131  GaugeConfig(str_gconf_read).read(U, readfile);
132  } else if (str_gconf_status == "Cold_start") {
133  GaugeConfig("Unit").read(U);
134  } else if (str_gconf_status == "Hot_start") {
135  GaugeConfig("Random").read(U);
136  } else {
137  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
138  exit(EXIT_FAILURE);
139  }
140 
141  unique_ptr<Projection> proj(Projection::New(str_proj_type));
142  proj->set_parameters(params_proj);
143 
144  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
145  smear->set_parameters(params_smear);
146 
147  unique_ptr<Director> dr_smear(new Director_Smear(smear));
148  dr_smear->set_parameters(params_dr_smear);
149 
150 
151  // #### object setup #####
152  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
153  fopr->set_parameters(params_fopr);
154 
155  unique_ptr<Fopr> fopr_smear(Fopr::New("Smeared", fopr, dr_smear));
156  fopr_smear->set_config(U);
157  fopr_smear->set_mode("H");
158 
159  unique_ptr<Eigensolver> eigen(new Eigensolver_IRLanczos(fopr_smear));
160  eigen->set_parameters(params_irlanczos);
161 
162  unique_ptr<Timer> timer(new Timer(test_name));
163 
164 
165  // #### Execution main part ####
166  timer->start();
167 
168  int Nm = Nk + Np;
169  std::vector<double> TDa(Nm);
170  std::vector<Field> vk(Nm);
171 
172  Field_F b2;
173  int NFin = b2.nin();
174  int NFvol = b2.nvol();
175  int NFex = b2.nex();
176  for (int k = 0; k < Nm; ++k) {
177  vk[k].reset(NFin, NFvol, NFex);
178  }
179 
180  int Nsbt = -1;
181  int Nconv = -100;
182  eigen->solve(TDa, vk, Nsbt, Nconv, (Field)b2);
183 
184  Field v;
185  v.reset(NFin, NFvol, NFex);
186  double vv = 0.0; // superficial initialization
187 
188  for (int i = 0; i < Nsbt + 1; ++i) {
189  fopr_smear->mult(v, vk[i]);
190  axpy(v, -TDa[i], vk[i]); // v -= TDa[i] * vk[i];
191  vv = v.norm2(); // vv = v * v;
192 
193  vout.general(vl, "Eigenvalues: %4d %20.14f %20.15e \n", i, TDa[i], vv);
194  }
195 
196  double result = TDa[0];
197 
198  timer->report();
199 
201 
202 
203  if (do_check) {
204  return Test::verify(result, expected_result);
205  } else {
206  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
207  return EXIT_SKIP;
208  }
209  }
210 } // namespace Test_Eigensolver
#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
void general(const char *format,...)
Definition: bridgeIO.cpp:195
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:39
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
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:104
double get_double(const string &key) const
Definition: parameters.cpp:70
void reset(const int Nin, const int Nvol, const int Nex, const element_type cmpl=COMPLEX)
Definition: field.h:84
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
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
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
virtual void set_parameters(const Parameters &)=0
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131