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