Bridge++  Version 1.6.1
 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 
38 namespace Test_Eigensolver {
39  const std::string test_name = "Eigensolver.Test";
40 
41  //- test-private parameters
42  namespace {
43  const std::string filename_input = "test_Eigensolver.yaml";
44  }
45 
46  //- prototype declaration
47  int solve(void);
48 
49 #ifdef USE_TESTMANAGER_AUTOREGISTER
50  namespace {
51 #if defined(USE_GROUP_SU2)
52  // Nc=2 is not available.
53 #else
54  static const bool is_registered = TestManager::RegisterTest(
55  test_name,
56  solve
57  );
58 #endif
59  }
60 #endif
61 
62  //====================================================================
63  //- Check of eigenvalue solver
64  int solve(void)
65  {
66  // ##### parameter setup #####
67  const int Ndim = CommonParameters::Ndim();
68  const int Nvol = CommonParameters::Nvol();
69 
70  const Parameters params_all = ParameterManager::read(filename_input);
71 
72  const Parameters params_test = params_all.lookup("Test_Eigensolver");
73  const Parameters params_fopr = params_all.lookup("Fopr");
74  const Parameters params_proj = params_all.lookup("Projection");
75  const Parameters params_smear = params_all.lookup("Smear");
76  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
77  const Parameters params_irlanczos = params_all.lookup("Eigensolver");
78 
79  const string str_gconf_status = params_test.get_string("gauge_config_status");
80  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
81  const string readfile = params_test.get_string("config_filename_input");
82  const string str_rand_type = params_test.get_string("random_number_type");
83  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
84  const string str_vlevel = params_test.get_string("verbose_level");
85 
86  const bool do_check = params_test.is_set("expected_result");
87  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
88 
89  const string str_fopr_type = params_fopr.get_string("fermion_type");
90  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
91  const string str_proj_type = params_proj.get_string("projection_type");
92  const string str_smear_type = params_smear.get_string("smear_type");
93  const int Nsmear = params_dr_smear.get_int("number_of_smearing");
94  const string str_sortfield_type = params_irlanczos.get_string("eigensolver_mode");
95  const int Nk = params_irlanczos.get_int("number_of_wanted_eigenvectors");
96  const int Np = params_irlanczos.get_int("number_of_working_eigenvectors");
97 
98  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
99 
100  //- print input parameters
101  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
102  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
103  vout.general(vl, " readfile = %s\n", readfile.c_str());
104  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
105  vout.general(vl, " seed = %lu\n", seed);
106  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
107  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
108  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
109  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
110  vout.general(vl, " sortfield_type = %s\n", str_sortfield_type.c_str());
111  vout.general(vl, "\n");
112 
113  //- input parameter check
114  int err = 0;
115  err += ParameterCheck::non_NULL(str_gconf_status);
116 
117  if (err) {
118  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
119  exit(EXIT_FAILURE);
120  }
121 
122  if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
123  if (CommonParameters::Nc() != 3) {
124  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
125  return EXIT_SKIP;
126  }
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  if (Nsmear > 0) {
148  unique_ptr<Projection> proj(Projection::New(str_proj_type));
149  proj->set_parameters(params_all.lookup("Projection"));
150 
151  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
152  smear->set_parameters(params_all.lookup("Smear"));
153 
154  const unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear));
155  dr_smear->set_parameters(params_all.lookup("Director_Smear"));
156  dr_smear->set_config(U);
157 
158  const Field_G *Usmear = (Field_G *)dr_smear->getptr_smearedConfig(Nsmear);
159  copy(*U, *Usmear);
160  }
161 
162 
163  // #### object setup #####
164  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
165  fopr->set_parameters(params_fopr);
166  fopr->set_config(U);
167  fopr->set_mode("H");
168 
169  const unique_ptr<Eigensolver> eigen(new Eigensolver_IRLanczos(fopr));
170  eigen->set_parameters(params_irlanczos);
171 
172  const unique_ptr<Timer> timer(new Timer(test_name));
173 
174 
175  // #### Execution main part ####
176  timer->start();
177 
178  Field_F b2;
179  const int NFin = b2.nin();
180  const int NFvol = b2.nvol();
181  const int NFex = b2.nex();
182 
183  const int Nm = Nk + Np;
184  std::vector<double> TDa(Nm);
185 
186  std::vector<Field> vk(Nm);
187  for (int k = 0; k < Nm; ++k) {
188  vk[k].reset(NFin, NFvol, NFex);
189  }
190 
191  int Nsbt = -1;
192  int Nconv = -100;
193  eigen->solve(TDa, vk, Nsbt, Nconv, (Field)b2);
194 
195  for (int i = 0; i < Nsbt + 1; ++i) {
196  Field v(NFin, NFvol, NFex);
197 
198  fopr->mult(v, vk[i]);
199  axpy(v, -TDa[i], vk[i]); // v -= TDa[i] * vk[i];
200  double vv = v.norm2(); // vv = v * v;
201 
202  vout.general(vl, "Eigenvalues: %4d %20.14f %20.15e \n", i, TDa[i], vv);
203  }
204 
205  const double result = TDa[0];
206 
207  timer->report();
208 
210 
211 
212  if (do_check) {
213  return Test::verify(result, expected_result);
214  } else {
215  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
216  return EXIT_SKIP;
217  }
218  }
219 } // 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:637
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:46
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
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: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
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)
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
virtual void set_parameters(const Parameters &)=0
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131