Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Rational_Inverse.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 
22 
24 
25 //====================================================================
27 
38 namespace Test_Rational {
39  const std::string test_name = "Rational.Inverse";
40 
41  //- test-private parameters
42  namespace {
43  const std::string filename_input = "test_Rational_Inverse.yaml";
44  }
45 
46  //- prototype declaration
47  int inverse(void);
48 
49 #ifdef USE_TESTMANAGER_AUTOREGISTER
50  namespace {
51 #if defined(USE_GROUP_SU2)
52  // Nc=2 is not available.
53 #else
54  static const bool is_registered = TestManager::RegisterTest(
55  test_name,
56  inverse
57  );
58 #endif
59  }
60 #endif
61 
62  //====================================================================
63  int inverse(void)
64  {
65  // ##### parameter setup #####
66  const int Ndim = CommonParameters::Ndim();
67  const int Nc = CommonParameters::Nc();
68  const int Nd = CommonParameters::Nd();
69  const int Nvol = CommonParameters::Nvol();
70  const int NinF = 2 * Nc * Nd;
71 
72  const Parameters params_all = ParameterManager::read(filename_input);
73 
74  const Parameters params_test = params_all.lookup("Test_Rational");
75  const Parameters params_clover = params_all.lookup("Fopr_Clover");
76  const Parameters params_rational = params_all.lookup("Fopr_Rational");
77  const Parameters params_source = params_all.lookup("Source");
78 
79  const string str_gconf_status = params_test.get_string("gauge_config_status");
80  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
81  const string readfile = params_test.get_string("config_filename_input");
82  const string str_rand_type = params_test.get_string("random_number_type");
83  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
84  const string str_vlevel = params_test.get_string("verbose_level");
85 
86  const bool do_check = params_test.is_set("expected_result");
87  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
88 
89  const string str_gmset_type = params_clover.get_string("gamma_matrix_type");
90  const string str_source_type = params_source.get_string("source_type");
91 
92  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
93 
94  //- print input parameters
95  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
96  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
97  vout.general(vl, " readfile = %s\n", readfile.c_str());
98  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
99  vout.general(vl, " seed = %lu\n", seed);
100  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
101  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
102  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
103  vout.general(vl, "\n");
104 
105  //- input parameter check
106  int err = 0;
107  err += ParameterCheck::non_NULL(str_gconf_status);
108 
109  if (err) {
110  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
111  exit(EXIT_FAILURE);
112  }
113 
114 
115  RandomNumberManager::initialize(str_rand_type, seed);
116 
117 
118  // #### Set up a gauge configuration ####
119  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
120 
121  if (str_gconf_status == "Continue") {
122  GaugeConfig(str_gconf_read).read(U, readfile);
123  } else if (str_gconf_status == "Cold_start") {
124  GaugeConfig("Unit").read(U);
125  } else if (str_gconf_status == "Hot_start") {
126  GaugeConfig("Random").read(U);
127  } else {
128  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
129  exit(EXIT_FAILURE);
130  }
131 
132 
133  // #### object setup ####
134  unique_ptr<Fopr> fopr_c(Fopr::New("Clover", str_gmset_type));
135  fopr_c->set_parameters(params_clover);
136  fopr_c->set_config(U);
137 
138  const unique_ptr<Fopr_Rational> fopr_r(new Fopr_Rational(fopr_c));
139  fopr_r->set_parameters(params_rational);
140 
141  const unique_ptr<Source> source(Source::New(str_source_type));
142  source->set_parameters(params_source);
143 
144  const unique_ptr<Timer> timer(new Timer(test_name));
145 
146 
147  // #### Execution main part ####
148  timer->start();
149 
150  Field xq(NinF, Nvol, 1), b(NinF, Nvol, 1);
151  Field v(NinF, Nvol, 1), w(NinF, Nvol, 1);
152  Field_F b2;
153 
154  double vv;
155  {
156  const int ispin = 0;
157  {
158  const int icolor = 0;
159  //for(int ispin = 0; ispin < Nd; ++ispin){
160  // for(int icolor = 0; icolor < Nc; ++icolor){
161 
162  int idx = icolor + Nc * ispin;
163  source->set(b2, idx);
164 
165  b = (Field)b2;
166 
167  fopr_r->mult(v, b);
168 
169  fopr_c->set_mode("DdagD");
170  fopr_c->mult(w, v);
171 
172  fopr_r->mult(v, w);
173  axpy(v, -1.0, b); // v -= b;
174  vv = v.norm2();
175 
176  vout.general(vl, " standard norm2 = %.8e\n", vv);
177  }
178  }
179 
180  const double result = vv;
181 
182  timer->report();
183 
185 
186 
187  if (do_check) {
188  return Test::verify(result, expected_result);
189  } else {
190  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
191  return EXIT_SKIP;
192  }
193  }
194 } // 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
void general(const char *format,...)
Definition: bridgeIO.cpp:197
virtual void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr.h:94
virtual void set_config(Field *)=0
setting pointer to the gauge configuration.
Container of Field-type object.
Definition: field.h:45
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
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
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
static void read(const std::string &params_file, Parameters &params)
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
virtual void mult(Field &, const Field &)=0
multiplies fermion operator to a given field (2nd argument)
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:221
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
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