Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Rational_Smeared.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
18 #include "Fopr/fopr_Clover.h"
19 #include "Fopr/fopr_Rational.h"
20 #include "Fopr/fopr_Smeared.h"
21 
23 
25 
26 //====================================================================
28 
39 namespace Test_Rational {
40  const std::string test_name = "Rational.Smeared_Rational";
41 
42  //- test-private parameters
43  namespace {
44  const std::string filename_input = "test_Rational_Smeared.yaml";
45  }
46 
47  //- prototype declaration
48  int smeared_rational(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,
58  );
59 #endif
60  }
61 #endif
62 
63  //====================================================================
64  int smeared_rational(void)
65  {
66  // ##### parameter setup #####
67  const int Ndim = CommonParameters::Ndim();
68  const int Nc = CommonParameters::Nc();
69  const int Nd = CommonParameters::Nd();
70  const int Nvol = CommonParameters::Nvol();
71  const int NinF = 2 * Nc * Nd;
72 
73  const Parameters params_all = ParameterManager::read(filename_input);
74 
75  const Parameters params_test = params_all.lookup("Test_Rational");
76  const Parameters params_clover = params_all.lookup("Fopr_Clover");
77  const Parameters params_proj = params_all.lookup("Projection");
78  const Parameters params_smear = params_all.lookup("Smear");
79  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
80  const Parameters params_rational = params_all.lookup("Fopr_Rational");
81  const Parameters params_source = params_all.lookup("Source");
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_clover.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_source_type = params_source.get_string("source_type");
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, " source_type = %s\n", str_source_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 
123  RandomNumberManager::initialize(str_rand_type, seed);
124 
125 
126  // ##### Set up a gauge configuration ####
127  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
128 
129  if (str_gconf_status == "Continue") {
130  GaugeConfig(str_gconf_read).read(U, readfile);
131  } else if (str_gconf_status == "Cold_start") {
132  GaugeConfig("Unit").read(U);
133  } else if (str_gconf_status == "Hot_start") {
134  GaugeConfig("Random").read(U);
135  } else {
136  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
137  exit(EXIT_FAILURE);
138  }
139 
140 
141  // ##### object setup #####
142  unique_ptr<Fopr> fopr_c(Fopr::New("Clover", str_gmset_type));
143  fopr_c->set_parameters(params_clover);
144 
145  unique_ptr<Projection> proj(Projection::New(str_proj_type));
146  proj->set_parameters(params_proj);
147 
148  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
149  smear->set_parameters(params_smear);
150 
151  unique_ptr<Director> dr_smear(new Director_Smear(smear));
152  dr_smear->set_parameters(params_dr_smear);
153 
154  unique_ptr<Fopr> fopr_r(Fopr::New("Rational", fopr_c));
155  fopr_r->set_parameters(params_rational);
156 
157  const unique_ptr<Source> source(Source::New(str_source_type));
158  source->set_parameters(params_source);
159 
160  //- Smeared-rational
161  Fopr_Smeared fopr_smear_1(fopr_c, dr_smear);
162  Fopr_Smeared fopr_smear_2(fopr_r, dr_smear);
163  fopr_smear_1.set_config(U);
164  fopr_smear_2.set_config(U);
165 
166  //- Rational-smeared
167  Fopr_Rational fopr_r_smear_1((Fopr *)&fopr_smear_1);
168  fopr_r_smear_1.set_parameters(params_rational);
169  fopr_r_smear_1.set_config(U);
170 
171  const unique_ptr<Timer> timer(new Timer(test_name));
172 
173 
174  // #### Execution main part ####
175  timer->start();
176 
177  Field xq(NinF, Nvol, 1), b(NinF, Nvol, 1);
178  Field v(NinF, Nvol, 1), w(NinF, Nvol, 1);
179  Field_F b2;
180 
181  vout.general(vl, "Consistency check of smeared-rational and rational-smeared.\n");
182 
183  vout.general(vl, "Smeared-rational:\n");
184 
185  {
186  const int ispin = 0;
187  {
188  const int icolor = 0;
189  //for(int ispin = 0; ispin < Nd; ++ispin){
190  // for(int icolor = 0; icolor < Nc; ++icolor){
191 
192  int idx = icolor + Nc * ispin;
193  source->set(b2, idx);
194 
195  b = (Field)b2;
196 
197  fopr_smear_2.mult(v, b);
198 
199  fopr_smear_1.set_mode("DdagD");
200  fopr_smear_1.mult(w, v);
201 
202  fopr_smear_2.mult(v, w);
203 
204  axpy(v, -1.0, b); // v -= b;
205  double vv = v.norm2();
206 
207  vout.general(vl, " standard norm2 = %.8e\n", vv);
208  }
209  }
210 
211  vout.general(vl, "Rational-smeared:\n");
212 
213  double vv;
214  {
215  const int ispin = 0;
216  {
217  const int icolor = 0;
218  //for(int ispin = 0; ispin < Nd; ++ispin){
219  // for(int icolor = 0; icolor < Nc; ++icolor){
220 
221  int idx = icolor + Nc * ispin;
222  source->set(b2, idx);
223 
224  b = (Field)b2;
225 
226  fopr_r_smear_1.mult(v, b);
227 
228  fopr_smear_1.set_mode("DdagD");
229  fopr_smear_1.mult(w, v);
230 
231  fopr_r_smear_1.mult(v, w);
232 
233  axpy(v, -1.0, b); // v -= b;
234  vv = v.norm2();
235 
236  vout.general(vl, " standard norm2 = %.8e\n", vv);
237  }
238  }
239 
240  const double result = vv;
241 
242  timer->report();
243 
245 
246 
247  if (do_check) {
248  return Test::verify(result, expected_result);
249  } else {
250  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
251  return EXIT_SKIP;
252  }
253  }
254 } // namespace Test_Rational
#define EXIT_SKIP
Definition: test.h:17
Fermion operator for rational approximation.
Definition: fopr_Rational.h:41
BridgeIO vout
Definition: bridgeIO.cpp:503
const std::string test_name
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
virtual void set_parameters(const Parameters &param)=0
void general(const char *format,...)
Definition: bridgeIO.cpp:197
Container of Field-type object.
Definition: field.h:45
virtual void set_parameters(const Parameters &)=0
void set_mode(const std::string mode)
set the mode of fermion operator
Definition: fopr_Smeared.h:82
Class for parameters.
Definition: parameters.h:46
void mult(Field &v, const Field &f)
multiplies fermion operator to a given field (2nd argument)
Wilson-type fermion field.
Definition: field_F.h:37
smeared fermion operator.
Definition: fopr_Smeared.h:41
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
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
void set_config(Field *U)
setting pointer to the gauge configuration.
Definition: fopr_Rational.h:77
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:319
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)
void mult(Field &v, const Field &f)
multiply smeared fermion operator
Definition: fopr_Smeared.h:70
Manager of smeared configurations.
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
void set_parameters(const Parameters &params)
VerboseLevel
Definition: bridgeIO.h:42
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
Base class of fermion operator family.
Definition: fopr.h:46
string get_string(const string &key) const
Definition: parameters.cpp:221
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:131
virtual void set(Field &, const int)=0