Bridge++  Version 1.4.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 "Tests/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 
24 #include "Smear/projection.h"
25 
27 
28 //====================================================================
30 
41 namespace Test_Rational {
42  const std::string test_name = "Rational.Smeared_Rational";
43 
44  //- test-private parameters
45  namespace {
46  const std::string filename_input = "test_Rational_Smeared.yaml";
47  }
48 
49  //- prototype declaration
50  int smeared_rational(void);
51 
52 #ifdef USE_TESTMANAGER_AUTOREGISTER
53  namespace {
54 #if defined(USE_GROUP_SU2)
55  // Nc=2 is not available.
56 #else
57  static const bool is_registered = TestManager::RegisterTest(
58  test_name,
60  );
61 #endif
62  }
63 #endif
64 
65  //====================================================================
66  int smeared_rational(void)
67  {
68  // ##### parameter setup #####
69  int Ndim = CommonParameters::Ndim();
70  int Nc = CommonParameters::Nc();
71  int Nd = CommonParameters::Nd();
72  int Nvol = CommonParameters::Nvol();
73  int NinF = 2 * Nc * Nd;
74 
75  Parameters params_all = ParameterManager::read(filename_input);
76 
77  Parameters params_test = params_all.lookup("Test_Rational");
78  Parameters params_clover = params_all.lookup("Fopr_Clover");
79  Parameters params_proj = params_all.lookup("Projection");
80  Parameters params_smear = params_all.lookup("Smear");
81  Parameters params_dr_smear = params_all.lookup("Director_Smear");
82  Parameters params_rational = params_all.lookup("Fopr_Rational");
83  Parameters params_source = params_all.lookup("Source");
84 
85  const string str_gconf_status = params_test.get_string("gauge_config_status");
86  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
87  const string readfile = params_test.get_string("config_filename_input");
88  const string str_rand_type = params_test.get_string("random_number_type");
89  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
90  const string str_vlevel = params_test.get_string("verbose_level");
91 
92  const bool do_check = params_test.is_set("expected_result");
93  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
94 
95  const string str_gmset_type = params_clover.get_string("gamma_matrix_type");
96  const string str_proj_type = params_proj.get_string("projection_type");
97  const string str_smear_type = params_smear.get_string("smear_type");
98  const string str_source_type = params_source.get_string("source_type");
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, " source_type = %s\n", str_source_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 
143  // ##### object setup #####
144  unique_ptr<Fopr> fopr_c(Fopr::New("Clover", str_gmset_type));
145  fopr_c->set_parameters(params_clover);
146 
147  unique_ptr<Projection> proj(Projection::New(str_proj_type));
148  proj->set_parameters(params_proj);
149 
150  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
151  smear->set_parameters(params_smear);
152 
153  unique_ptr<Director> dr_smear(new Director_Smear(smear));
154  dr_smear->set_parameters(params_dr_smear);
155 
156  unique_ptr<Fopr> fopr_r(Fopr::New("Rational", fopr_c));
157  fopr_r->set_parameters(params_rational);
158 
159  unique_ptr<Source> source(Source::New(str_source_type));
160  source->set_parameters(params_source);
161 
162  //- Smeared-rational
163  Fopr_Smeared fopr_smear_1(fopr_c, dr_smear);
164  Fopr_Smeared fopr_smear_2(fopr_r, dr_smear);
165  fopr_smear_1.set_config(U);
166  fopr_smear_2.set_config(U);
167 
168  //- Rational-smeared
169  Fopr_Rational fopr_r_smear_1((Fopr *)&fopr_smear_1);
170  fopr_r_smear_1.set_parameters(params_rational);
171  fopr_r_smear_1.set_config(U);
172 
173  unique_ptr<Timer> timer(new Timer(test_name));
174 
175 
176  // #### Execution main part ####
177  timer->start();
178 
179  Field xq(NinF, Nvol, 1), b(NinF, Nvol, 1);
180  Field v(NinF, Nvol, 1), w(NinF, Nvol, 1);
181  Field_F b2;
182 
183  vout.general(vl, "Consistency check of smeared-rational and rational-smeared.\n");
184 
185  vout.general(vl, "Smeared-rational:\n");
186 
187  {
188  int ispin = 0;
189  {
190  int icolor = 0;
191  //for(int ispin = 0; ispin < Nd; ++ispin){
192  // for(int icolor = 0; icolor < Nc; ++icolor){
193 
194  int idx = icolor + Nc * ispin;
195  source->set(b2, idx);
196 
197  b = (Field)b2;
198 
199  fopr_smear_2.mult(v, b);
200 
201  fopr_smear_1.set_mode("DdagD");
202  fopr_smear_1.mult(w, v);
203 
204  fopr_smear_2.mult(v, w);
205 
206  axpy(v, -1.0, b); // v -= b;
207  double vv = v.norm2();
208 
209  vout.general(vl, " standard norm2 = %.8e\n", vv);
210  }
211  }
212 
213  vout.general(vl, "Rational-smeared:\n");
214 
215  double vv;
216  {
217  int ispin = 0;
218  {
219  int icolor = 0;
220  //for(int ispin = 0; ispin < Nd; ++ispin){
221  // for(int icolor = 0; icolor < Nc; ++icolor){
222 
223  int idx = icolor + Nc * ispin;
224  source->set(b2, idx);
225 
226  b = (Field)b2;
227 
228  fopr_r_smear_1.mult(v, b);
229 
230  fopr_smear_1.set_mode("DdagD");
231  fopr_smear_1.mult(w, v);
232 
233  fopr_r_smear_1.mult(v, w);
234 
235  axpy(v, -1.0, b); // v -= b;
236  vv = v.norm2();
237 
238  vout.general(vl, " standard norm2 = %.8e\n", vv);
239  }
240  }
241 
242  double result = vv;
243 
244  timer->report();
245 
247 
248 
249  if (do_check) {
250  return Test::verify(result, expected_result);
251  } else {
252  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
253  return EXIT_SKIP;
254  }
255  }
256 } // 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:495
const std::string test_name
void detailed(const char *format,...)
Definition: bridgeIO.cpp:212
virtual void set_parameters(const Parameters &param)=0
void general(const char *format,...)
Definition: bridgeIO.cpp:195
Container of Field-type object.
Definition: field.h:39
virtual void set_parameters(const Parameters &)=0
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:42
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
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 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)
Definition: checker.cpp:61
bool is_set(const string &key) const
Definition: parameters.cpp:396
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: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: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
Bridge::VerboseLevel vl
Definition: checker.cpp:18
void set_parameters(const Parameters &params)
VerboseLevel
Definition: bridgeIO.h:42
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:75
Definition: timer.h:31
Base class of fermion operator family.
Definition: fopr.h:47
string get_string(const string &key) const
Definition: parameters.cpp:116
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