Bridge++  Ver. 2.0.2
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  Field_G U(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", params_clover));
154 
155  unique_ptr<Projection> proj(Projection::New(str_proj_type, params_proj));
156  unique_ptr<Smear> smear(Smear::New(str_smear_type, proj.get(), params_smear));
157  unique_ptr<Director_Smear> dr_smear(new Director_Smear(smear.get(), params_dr_smear));
158 
159  unique_ptr<Fopr> fopr_r(Fopr::New("Rational", fopr_c.get(), params_rational));
160 
161  unique_ptr<Source> source(Source::New(str_source_type, params_source));
162 
163  //- Smeared-rational
164  Fopr_Smeared fopr_smear_1(fopr_c.get(), dr_smear.get());
165  Fopr_Smeared fopr_smear_2(fopr_r.get(), dr_smear.get());
166  fopr_smear_1.set_config(&U);
167  fopr_smear_2.set_config(&U);
168 
169  //- Rational-smeared
170  Fopr_Rational fopr_r_smear_1((Fopr *)&fopr_smear_1, params_rational);
171  fopr_r_smear_1.set_config(&U);
172 
173  Timer 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  const int ispin = 0;
189  {
190  const 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  const int ispin = 0;
218  {
219  const 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  const 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
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
AFopr< Field >
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
AFopr::mult
virtual void mult(AFIELD &, const AFIELD &)
multiplies fermion operator to a given field.
Definition: afopr.h:95
Parameters
Class for parameters.
Definition: parameters.h:46
AFopr_Rational::mult
void mult(AFIELD &v, const AFIELD &f)
multiplies fermion operator to a given field.
Definition: afopr_Rational-tmpl.h:180
fopr_Clover.h
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
GaugeConfig::read
void read(Field_G &U, const string &filename=string())
Definition: gaugeConfig.cpp:121
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
AFopr::set_mode
virtual void set_mode(std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: afopr.h:81
source.h
Timer
Definition: timer.h:31
RandomNumberManager::finalize
static void finalize()
Definition: randomNumberManager.cpp:80
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Test_Rational::test_name
const std::string test_name
Definition: test_Rational_Approx.cpp:30
Timer::start
void start()
Definition: timer.cpp:44
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
AIndex_eo_qxs::idx
int idx(const int in, const int Nin, const int ist, const int Nx2, const int Ny, const int leo, const int Nvol2, const int ex)
Definition: aindex_eo.h:27
test.h
ParameterManager::read
static void read(const std::string &params_file, Parameters &params)
Definition: parameterManager.cpp:33
Parameters::get_double
double get_double(const string &key) const
Definition: parameters.cpp:175
Fopr_Smeared
smeared fermion operator.
Definition: fopr_Smeared.h:41
Test_Rational::smeared_rational
int smeared_rational(void)
Definition: test_Rational_Smeared.cpp:66
AFopr_Rational
Fermion operator for rational approximation.
Definition: afopr_Rational.h:42
Director_Smear
Manager of smeared configurations.
Definition: director_Smear.h:39
Parameters::get_unsigned_long
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
EXIT_SKIP
#define EXIT_SKIP
Definition: test.h:17
Fopr_Smeared::set_config
void set_config(Field *U)
set pointer to original thin link variable
Definition: fopr_Smeared.cpp:42
CommonParameters::Nd
static int Nd()
Definition: commonParameters.h:116
randomNumberManager.h
GaugeConfig
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:80
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
Parameters::is_set
bool is_set(const string &key) const
Definition: parameters.cpp:525
AFopr_Rational::set_config
void set_config(Field *U)
sets the gauge configuration.
Definition: afopr_Rational-tmpl.h:129
fopr_Rational.h
Field_F
Wilson-type fermion field.
Definition: field_F.h:37
fopr_Smeared.h
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Test_Rational
Test of rational approximation of fermion operators.
Definition: test_Rational_Approx.cpp:29
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Field
Container of Field-type object.
Definition: field.h:46
Fopr_Smeared::mult
void mult(Field &v, const Field &f)
multiply smeared fermion operator
Definition: fopr_Smeared.h:71
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Parameters::lookup
Parameters lookup(const string &key) const
Definition: parameters.h:79
Timer::report
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
TestManager::RegisterTest
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69