Bridge++  Version 1.6.1
 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 
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  const int Ndim = CommonParameters::Ndim();
70  const int Nc = CommonParameters::Nc();
71  const int Nd = CommonParameters::Nd();
72  const int Nvol = CommonParameters::Nvol();
73  const int NinF = 2 * Nc * Nd;
74 
75  const Parameters params_all = ParameterManager::read(filename_input);
76 
77  const Parameters params_test = params_all.lookup("Test_Rational");
78  const Parameters params_clover = params_all.lookup("Fopr_Clover");
79  const Parameters params_proj = params_all.lookup("Projection");
80  const Parameters params_smear = params_all.lookup("Smear");
81  const Parameters params_dr_smear = params_all.lookup("Director_Smear");
82  const Parameters params_rational = params_all.lookup("Fopr_Rational");
83  const 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 int Nsmear = params_dr_smear.get_int("number_of_smearing");
99  const string str_source_type = params_source.get_string("source_type");
100 
101  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
102 
103  //- print input parameters
104  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
105  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
106  vout.general(vl, " readfile = %s\n", readfile.c_str());
107  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
108  vout.general(vl, " seed = %lu\n", seed);
109  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
110  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
111  vout.general(vl, " proj_type = %s\n", str_proj_type.c_str());
112  vout.general(vl, " smear_type = %s\n", str_smear_type.c_str());
113  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
114  vout.general(vl, "\n");
115 
116  //- input parameter check
117  int err = 0;
118  err += ParameterCheck::non_NULL(str_gconf_status);
119 
120  if (err) {
121  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
122  exit(EXIT_FAILURE);
123  }
124 
125  // if ( (Nsmear > 0) && (str_proj_type == "Stout_SU3") ) {
126  if (str_proj_type == "Stout_SU3") {
127  if (CommonParameters::Nc() != 3) {
128  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
129  return EXIT_SKIP;
130  }
131  }
132 
133 
134  RandomNumberManager::initialize(str_rand_type, seed);
135 
136 
137  // ##### Set up a gauge configuration ####
138  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
139 
140  if (str_gconf_status == "Continue") {
141  GaugeConfig(str_gconf_read).read(U, readfile);
142  } else if (str_gconf_status == "Cold_start") {
143  GaugeConfig("Unit").read(U);
144  } else if (str_gconf_status == "Hot_start") {
145  GaugeConfig("Random").read(U);
146  } else {
147  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
148  exit(EXIT_FAILURE);
149  }
150 
151 
152  // ##### object setup #####
153  unique_ptr<Fopr> fopr_c(Fopr::New("Clover", str_gmset_type));
154  fopr_c->set_parameters(params_clover);
155 
156  unique_ptr<Projection> proj(Projection::New(str_proj_type));
157  proj->set_parameters(params_proj);
158 
159  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj));
160  smear->set_parameters(params_smear);
161 
162  unique_ptr<Director> dr_smear(new Director_Smear(smear));
163  dr_smear->set_parameters(params_dr_smear);
164 
165  unique_ptr<Fopr> fopr_r(Fopr::New("Rational", fopr_c));
166  fopr_r->set_parameters(params_rational);
167 
168  const unique_ptr<Source> source(Source::New(str_source_type));
169  source->set_parameters(params_source);
170 
171  //- Smeared-rational
172  Fopr_Smeared fopr_smear_1(fopr_c, dr_smear);
173  Fopr_Smeared fopr_smear_2(fopr_r, dr_smear);
174  fopr_smear_1.set_config(U);
175  fopr_smear_2.set_config(U);
176 
177  //- Rational-smeared
178  Fopr_Rational fopr_r_smear_1((Fopr *)&fopr_smear_1);
179  fopr_r_smear_1.set_parameters(params_rational);
180  fopr_r_smear_1.set_config(U);
181 
182  const unique_ptr<Timer> timer(new Timer(test_name));
183 
184 
185  // #### Execution main part ####
186  timer->start();
187 
188  Field xq(NinF, Nvol, 1), b(NinF, Nvol, 1);
189  Field v(NinF, Nvol, 1), w(NinF, Nvol, 1);
190  Field_F b2;
191 
192  vout.general(vl, "Consistency check of smeared-rational and rational-smeared.\n");
193 
194  vout.general(vl, "Smeared-rational:\n");
195 
196  {
197  const int ispin = 0;
198  {
199  const int icolor = 0;
200  //for(int ispin = 0; ispin < Nd; ++ispin){
201  // for(int icolor = 0; icolor < Nc; ++icolor){
202 
203  int idx = icolor + Nc * ispin;
204  source->set(b2, idx);
205 
206  b = (Field)b2;
207 
208  fopr_smear_2.mult(v, b);
209 
210  fopr_smear_1.set_mode("DdagD");
211  fopr_smear_1.mult(w, v);
212 
213  fopr_smear_2.mult(v, w);
214 
215  axpy(v, -1.0, b); // v -= b;
216  double vv = v.norm2();
217 
218  vout.general(vl, " standard norm2 = %.8e\n", vv);
219  }
220  }
221 
222  vout.general(vl, "Rational-smeared:\n");
223 
224  double vv;
225  {
226  const int ispin = 0;
227  {
228  const int icolor = 0;
229  //for(int ispin = 0; ispin < Nd; ++ispin){
230  // for(int icolor = 0; icolor < Nc; ++icolor){
231 
232  int idx = icolor + Nc * ispin;
233  source->set(b2, idx);
234 
235  b = (Field)b2;
236 
237  fopr_r_smear_1.mult(v, b);
238 
239  fopr_smear_1.set_mode("DdagD");
240  fopr_smear_1.mult(w, v);
241 
242  fopr_r_smear_1.mult(v, w);
243 
244  axpy(v, -1.0, b); // v -= b;
245  vv = v.norm2();
246 
247  vout.general(vl, " standard norm2 = %.8e\n", vv);
248  }
249  }
250 
251  const double result = vv;
252 
253  timer->report();
254 
256 
257 
258  if (do_check) {
259  return Test::verify(result, expected_result);
260  } else {
261  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
262  return EXIT_SKIP;
263  }
264  }
265 } // 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:46
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:320
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:79
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