Bridge++  Ver. 1.3.x
test_Rational_Smeared.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "gaugeConfig.h"
17 
18 #include "fopr_Clover.h"
19 #include "fopr_Rational.h"
20 
21 #include "director_Smear.h"
22 #include "fopr_Smeared.h"
23 
24 #include "projection.h"
25 #include "smear.h"
26 #include "source.h"
27 
28 #include "randomNumbers_Mseries.h"
29 
30 //====================================================================
32 
43 namespace Test_Rational {
44  const std::string test_name = "Rational.Smeared_Rational";
45 
46  //- test-private parameters
47  namespace {
48  const std::string filename_input = "test_Rational_Smeared.yaml";
49  const std::string filename_output = "stdout";
50 
51  class Parameters_Test_Rational : public Parameters {
52  public:
53  Parameters_Test_Rational()
54  {
55  Register_string("gauge_config_status", "NULL");
56  Register_string("gauge_config_type_input", "NULL");
57  Register_string("config_filename_input", "NULL");
58 
59  Register_string("verbose_level", "NULL");
60 
61  Register_double("expected_result", 0.0);
62  }
63  };
64  }
65 
66  //- prototype declaration
67  int smeared_rational(void);
68 
69 #ifdef USE_TESTMANAGER_AUTOREGISTER
70  namespace {
71 #if defined(USE_GROUP_SU2)
72  // Nc=2 is not available.
73 #else
74  static const bool is_registered = TestManager::RegisterTest(
75  test_name,
77  );
78 #endif
79  }
80 #endif
81 
82  //====================================================================
83  int smeared_rational(void)
84  {
85  // ##### parameter setup #####
86  int Ndim = CommonParameters::Ndim();
87  int Nc = CommonParameters::Nc();
88  int Nd = CommonParameters::Nd();
89  int Nvol = CommonParameters::Nvol();
90  int NinF = 2 * Nc * Nd;
91 
92  unique_ptr<Parameters> params_test(new Parameters_Test_Rational);
93  unique_ptr<Parameters> params_clover(ParametersFactory::New("Fopr.Clover"));
94  unique_ptr<Parameters> params_proj(ParametersFactory::New("Projection"));
95  unique_ptr<Parameters> params_smear(ParametersFactory::New("Smear"));
96  unique_ptr<Parameters> params_dr_smear(ParametersFactory::New("Director_Smear"));
97  unique_ptr<Parameters> params_rational(ParametersFactory::New("Fopr.Rational"));
98  unique_ptr<Parameters> params_source(ParametersFactory::New("Source"));
99  unique_ptr<Parameters> params_all(new Parameters);
100 
101  params_all->Register_Parameters("Test_Rational", params_test);
102  params_all->Register_Parameters("Fopr_Clover", params_clover);
103  params_all->Register_Parameters("Projection", params_proj);
104  params_all->Register_Parameters("Smear", params_smear);
105  params_all->Register_Parameters("Director_Smear", params_dr_smear);
106  params_all->Register_Parameters("Fopr_Rational", params_rational);
107  params_all->Register_Parameters("Source", params_source);
108 
109  ParameterManager::read(filename_input, params_all);
110 
111  const string str_gconf_status = params_test->get_string("gauge_config_status");
112  const string str_gconf_read = params_test->get_string("gauge_config_type_input");
113  const string readfile = params_test->get_string("config_filename_input");
114  const string str_vlevel = params_test->get_string("verbose_level");
115 
116  const bool do_check = params_test->is_set("expected_result");
117  const double expected_result = do_check ? params_test->get_double("expected_result") : 0.0;
118 
119  const string str_gmset_type = params_clover->get_string("gamma_matrix_type");
120  const string str_proj_type = params_proj->get_string("projection_type");
121  const string str_smear_type = params_smear->get_string("smear_type");
122  const string str_source_type = params_source->get_string("source_type");
123 
125 
126  //- print input parameters
127  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
128  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
129  vout.general(vl, " readfile = %s\n", readfile.c_str());
130  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
131  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
132  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
133  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
134  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
135  vout.general(vl, "\n");
136 
137  //- input parameter check
138  int err = 0;
139  err += ParameterCheck::non_NULL(str_gconf_status);
140 
141  if (err) {
142  vout.crucial(vl, "%s: Input parameters have not been set.\n", test_name.c_str());
143  exit(EXIT_FAILURE);
144  }
145 
146 
147  // ##### Set up a gauge configuration ####
148  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
149  unique_ptr<GaugeConfig> gconf_read(new GaugeConfig(str_gconf_read));
150 
151  if (str_gconf_status == "Continue") {
152  gconf_read->read_file(U, readfile);
153  } else if (str_gconf_status == "Cold_start") {
154  U->set_unit();
155  } else if (str_gconf_status == "Hot_start") {
156  int i_seed_noise = 1234567;
157  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_seed_noise));
158  U->set_random(rand);
159  } else {
160  vout.crucial(vl, "%s: unsupported gconf status \"%s\".\n", test_name.c_str(), str_gconf_status.c_str());
161  exit(EXIT_FAILURE);
162  }
163 
164 
165  // ##### object setup #####
166  unique_ptr<Fopr> fopr_c(Fopr::New("Clover", str_gmset_type));
167  fopr_c->set_parameters(*params_clover);
168 
169  unique_ptr<Projection> proj(Projection::New(str_proj_type));
170  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
171  smear->set_parameters(*params_smear);
172 
173  unique_ptr<Director> dr_smear(new Director_Smear(smear));
174  dr_smear->set_parameters(*params_dr_smear);
175 
176  unique_ptr<Fopr> fopr_r(Fopr::New("Rational", fopr_c));
177  fopr_r->set_parameters(*params_rational);
178 
179  unique_ptr<Source> source(Source::New(str_source_type));
180  source->set_parameters(*params_source);
181 
182  //- Smeared-rational
183  Fopr_Smeared fopr_smear_1(fopr_c, dr_smear);
184  Fopr_Smeared fopr_smear_2(fopr_r, dr_smear);
185  fopr_smear_1.set_config(U);
186  fopr_smear_2.set_config(U);
187 
188  //- Rational-smeared
189  Fopr_Rational fopr_r_smear_1((Fopr *)&fopr_smear_1);
190  fopr_r_smear_1.set_parameters(*params_rational);
191  fopr_r_smear_1.set_config(U);
192 
193  unique_ptr<Timer> timer(new Timer(test_name));
194 
195 
196  // #### Execution main part ####
197  timer->start();
198 
199  Field xq(NinF, Nvol, 1), b(NinF, Nvol, 1);
200  Field v(NinF, Nvol, 1), w(NinF, Nvol, 1);
201  Field_F b2;
202 
203  vout.general(vl, "Consistency check of smeared-rational and rational-smeared.\n");
204 
205  vout.general(vl, "Smeared-rational:\n");
206 
207  {
208  int ispin = 0;
209  {
210  int icolor = 0;
211  //for(int ispin = 0; ispin < Nd; ++ispin){
212  // for(int icolor = 0; icolor < Nc; ++icolor){
213 
214  int idx = icolor + Nc * ispin;
215  source->set(b2, idx);
216 
217  b = (Field)b2;
218 
219  fopr_smear_2.mult(v, b);
220 
221  fopr_smear_1.set_mode("DdagD");
222  fopr_smear_1.mult(w, v);
223 
224  fopr_smear_2.mult(v, w);
225 
226  axpy(v, -1.0, b); // v -= b;
227  double vv = v.norm2();
228 
229  vout.general(vl, " standard norm2 = %.8e\n", vv);
230  }
231  }
232 
233  vout.general(vl, "Rational-smeared:\n");
234 
235  double vv;
236  {
237  int ispin = 0;
238  {
239  int icolor = 0;
240  //for(int ispin = 0; ispin < Nd; ++ispin){
241  // for(int icolor = 0; icolor < Nc; ++icolor){
242 
243  int idx = icolor + Nc * ispin;
244  source->set(b2, idx);
245 
246  b = (Field)b2;
247 
248  fopr_r_smear_1.mult(v, b);
249 
250  fopr_smear_1.set_mode("DdagD");
251  fopr_smear_1.mult(w, v);
252 
253  fopr_r_smear_1.mult(v, w);
254 
255  axpy(v, -1.0, b); // v -= b;
256  vv = v.norm2();
257 
258  vout.general(vl, " standard norm2 = %.8e\n", vv);
259  }
260  }
261 
262  double result = vv;
263 
264  timer->report();
265 
266 
267  if (do_check) {
268  return Test::verify(result, expected_result);
269  } else {
270  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
271  return EXIT_SKIP;
272  }
273  }
274 } // namespace Test_Rational
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
Fermion operator for rational approximation.
Definition: fopr_Rational.h:48
BridgeIO vout
Definition: bridgeIO.cpp:278
const std::string test_name
void detailed(const char *format,...)
Definition: bridgeIO.cpp:82
void general(const char *format,...)
Definition: bridgeIO.cpp:65
Container of Field-type object.
Definition: field.h:39
virtual void set_parameters(const Parameters &)=0
Class for parameters.
Definition: parameters.h:38
void mult(Field &v, const Field &f)
multiplies fermion operator to a given field (2nd argument)
static Parameters * New(const std::string &realm)
void read_file(Field *U, const string &filename)
Definition: gaugeConfig.cpp:56
void set_random(RandomNumbers *rand)
Definition: field_G_imp.cpp:62
Wilson-type fermion field.
Definition: field_F.h:37
smeared fermion operator.
Definition: fopr_Smeared.h:42
void set_unit()
Definition: field_G_imp.cpp:39
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:80
SU(N) gauge field.
Definition: field_G.h:38
bool is_set(const string &) const
Definition: parameters.cpp:372
double get_double(const string &key) const
Definition: parameters.cpp:27
void set_config(Field *U)
setting pointer to the gauge configuration.
Definition: fopr_Rational.h:84
virtual void set_parameters(const Parameters &)=0
int non_NULL(const std::string v)
Definition: checker.cpp:61
virtual void set(Field &, int)=0
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:48
virtual void set_parameters(const Parameters &params)=0
void Register_Parameters(const string &, Parameters *const)
Definition: parameters.cpp:358
void mult(Field &v, const Field &f)
multiply smeared fermion operator
Definition: fopr_Smeared.h:71
Manager of smeared configurations.
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
void set_mode(std::string mode)
set the mode of fermion operator
Definition: fopr_Smeared.h:83
Test of rational approximation of fermion operators.
Bridge::VerboseLevel vl
Definition: checker.cpp:18
void set_parameters(const Parameters &params)
VerboseLevel
Definition: bridgeIO.h:39
static void read(const std::string &params_file, Parameters *params)
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:61
Definition: timer.h:31
Base class of fermion operator family.
Definition: fopr.h:49
string get_string(const string &key) const
Definition: parameters.cpp:87
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
void set_config(Field *U)
set pointer to original thin link variable
virtual void set_parameters(const Parameters &)=0
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:28