Bridge++  Ver. 2.0.2
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  Field_G U(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(new Fopr_Clover(params_clover));
135  fopr_c->set_config(&U);
136 
137  unique_ptr<Fopr_Rational> fopr_r(new Fopr_Rational(fopr_c.get(), params_rational));
138 
139  unique_ptr<Source> source(Source::New(str_source_type, params_source));
140 
141  Timer timer(test_name);
142 
143 
144  // #### Execution main part ####
145  timer.start();
146 
147  Field xq(NinF, Nvol, 1), b(NinF, Nvol, 1);
148  Field v(NinF, Nvol, 1), w(NinF, Nvol, 1);
149  Field_F b2;
150 
151  double vv;
152  {
153  const int ispin = 0;
154  {
155  const int icolor = 0;
156  //for(int ispin = 0; ispin < Nd; ++ispin){
157  // for(int icolor = 0; icolor < Nc; ++icolor){
158 
159  int idx = icolor + Nc * ispin;
160  source->set(b2, idx);
161 
162  b = (Field)b2;
163 
164  fopr_r->mult(v, b);
165 
166  fopr_c->set_mode("DdagD");
167  fopr_c->mult(w, v);
168 
169  fopr_r->mult(v, w);
170  axpy(v, -1.0, b); // v -= b;
171  vv = v.norm2();
172 
173  vout.general(vl, " standard norm2 = %.8e\n", vv);
174  }
175  }
176 
177  const double result = vv;
178 
179  timer.report();
180 
182 
183 
184  if (do_check) {
185  return Test::verify(result, expected_result);
186  } else {
187  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
188  return EXIT_SKIP;
189  }
190  }
191 } // 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
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
Parameters
Class for parameters.
Definition: parameters.h:46
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
Fopr_Clover
Clover fermion operator.
Definition: fopr_Clover.h:43
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
Fopr_Rational
AFopr_Rational< Field > Fopr_Rational
Fermion operator for rational approximation.
Definition: fopr_Rational.h:46
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
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
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
Test_Rational::inverse
int inverse(void)
Definition: test_Rational_Inverse.cpp:63
fopr_Rational.h
Field_F
Wilson-type fermion field.
Definition: field_F.h:37
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
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