Bridge++  Ver. 2.0.2
test_Eigensolver.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_Smeared.h"
20 
21 #include "IO/gaugeConfig.h"
22 
24 
25 //====================================================================
27 
39 namespace Test_Eigensolver {
40  const std::string test_name = "Eigensolver.Test";
41 
42  //- test-private parameters
43  namespace {
44  const std::string filename_input = "test_Eigensolver.yaml";
45  }
46 
47  //- prototype declaration
48  int solve(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,
57  solve
58  );
59 #endif
60  }
61 #endif
62 
63  //====================================================================
64  //- Check of eigenvalue solver
65  int solve(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_proj = params_all.lookup("Projection");
76  const Parameters params_smear = params_all.lookup("Smear");
77  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
78  const Parameters params_irlanczos = params_all.lookup("Eigensolver");
79 
80  const string str_gconf_status = params_test.get_string("gauge_config_status");
81  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
82  const string readfile = params_test.get_string("config_filename_input");
83  const string str_rand_type = params_test.get_string("random_number_type");
84  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
85  const string str_vlevel = params_test.get_string("verbose_level");
86 
87  const bool do_check = params_test.is_set("expected_result");
88  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
89 
90  const string str_fopr_type = params_fopr.get_string("fermion_type");
91  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
92  const string str_proj_type = params_proj.get_string("projection_type");
93  const string str_smear_type = params_smear.get_string("smear_type");
94  const int Nsmear = params_dr_smear.get_int("number_of_smearing");
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 
99  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
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  if ((Nsmear > 0) && (str_proj_type == "Stout_SU3")) {
124  if (CommonParameters::Nc() != 3) {
125  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
126  return EXIT_SKIP;
127  }
128  }
129 
130 
131  RandomNumberManager::initialize(str_rand_type, seed);
132 
133 
134  // #### Set up a gauge configuration ####
135  Field_G U(Nvol, Ndim);
136 
137  if (str_gconf_status == "Continue") {
138  GaugeConfig(str_gconf_read).read(U, readfile);
139  } else if (str_gconf_status == "Cold_start") {
140  GaugeConfig("Unit").read(U);
141  } else if (str_gconf_status == "Hot_start") {
142  GaugeConfig("Random").read(U);
143  } else {
144  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
145  exit(EXIT_FAILURE);
146  }
147 
148  if (Nsmear > 0) {
149  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_all.lookup("Projection")));
150  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_all.lookup("Smear")));
151  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear.get(), params_all.lookup("Director_Smear")));
152  dr_smear->set_config(&U);
153 
154  const Field_G *Usmear = (Field_G *)dr_smear->getptr_smearedConfig(Nsmear);
155  copy(U, *Usmear);
156  }
157 
158 
159  // #### object setup #####
160  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, params_fopr));
161  fopr->set_config(&U);
162  fopr->set_mode("H");
163 
164  unique_ptr<Eigensolver> eigen(new Eigensolver_IRLanczos(fopr.get(), params_irlanczos));
165 
166  Timer timer(test_name);
167 
168 
169  // #### Execution main part ####
170  timer.start();
171 
172  Field_F b2;
173  const int NFin = b2.nin();
174  const int NFvol = b2.nvol();
175  const int NFex = b2.nex();
176 
177  const int Nm = Nk + Np;
178  std::vector<double> TDa(Nm);
179 
180  std::vector<Field> vk(Nm);
181  for (int k = 0; k < Nm; ++k) {
182  vk[k].reset(NFin, NFvol, NFex);
183  }
184 
185  int Nsbt = -1;
186  int Nconv = -100;
187  eigen->solve(TDa, vk, Nsbt, Nconv, (Field)b2);
188 
189  for (int i = 0; i < Nsbt + 1; ++i) {
190  Field v(NFin, NFvol, NFex);
191 
192  fopr->mult(v, vk[i]);
193  axpy(v, -TDa[i], vk[i]); // v -= TDa[i] * vk[i];
194  double vv = v.norm2(); // vv = v * v;
195 
196  vout.general(vl, "Eigenvalues: %4d %20.14f %20.15e \n", i, TDa[i], vv);
197  }
198 
199  const double result = TDa[0];
200 
201  timer.report();
202 
204 
205 
206  if (do_check) {
207  return Test::verify(result, expected_result);
208  } else {
209  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
210  return EXIT_SKIP;
211  }
212  }
213 } // namespace Test_Eigensolver
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Test_Eigensolver::test_name
const std::string test_name
Definition: test_Eigensolver.cpp:40
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
Parameters
Class for parameters.
Definition: parameters.h:46
Parameters::get_int
int get_int(const string &key) const
Definition: parameters.cpp:192
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
Test_Eigensolver
Test of eigenvalue solver.
Definition: test_Eigensolver.cpp:39
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
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
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
Test_Eigensolver::solve
int solve(void)
Definition: test_Eigensolver.cpp:65
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
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