Bridge++  Ver. 2.0.2
test_Solver_Wilson_ShiftCG.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
20 
22 
23 //====================================================================
25 
36 namespace Test_Solver_Wilson {
37  const std::string test_name = "Solver.Wilson.ShiftCG";
38 
39  //- test-private parameters
40  namespace {
41  const std::string filename_input = "test_Solver_Wilson_ShiftCG.yaml";
42  }
43 
44  //- prototype declaration
45  int solver_ShiftCG(void);
46 
47 #ifdef USE_TESTMANAGER_AUTOREGISTER
48  namespace {
49 #if defined(USE_GROUP_SU2)
50  // Nc=2 is not available.
51 #else
52  static const bool is_registered = TestManager::RegisterTest(
53  test_name,
55  );
56 #endif
57  }
58 #endif
59 
60  //====================================================================
61  int solver_ShiftCG(void)
62  {
63  // #### parameter setup ####
64  const int Nc = CommonParameters::Nc();
65  const int Nd = CommonParameters::Nd();
66  const int Ndim = CommonParameters::Ndim();
67  const int Nvol = CommonParameters::Nvol();
68 
69  const Parameters params_all = ParameterManager::read(filename_input);
70 
71  const Parameters params_test = params_all.lookup("Test_ShiftSolver");
72  const Parameters params_wilson = params_all.lookup("Fopr_Wilson");
73  const Parameters params_solver = params_all.lookup("Fprop_Shift");
74  const Parameters params_source = params_all.lookup("Source");
75 
76  const string str_gconf_status = params_test.get_string("gauge_config_status");
77  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
78  const string readfile = params_test.get_string("config_filename_input");
79  const string str_rand_type = params_test.get_string("random_number_type");
80  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
81  const string str_vlevel = params_test.get_string("verbose_level");
82 
83  const bool do_check = params_test.is_set("expected_result");
84  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
85 
86  const string str_gmset_type = params_wilson.get_string("gamma_matrix_type");
87  const int Nshift = params_solver.get_int("number_of_shifts");
88  const string str_source_type = params_source.get_string("source_type");
89 
90  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
91 
92  //- print input parameters
93  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
94  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
95  vout.general(vl, " readfile = %s\n", readfile.c_str());
96  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
97  vout.general(vl, " seed = %lu\n", seed);
98  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
99  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
100  vout.general(vl, " Nshift = %d\n", Nshift);
101  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
102  vout.general(vl, "\n");
103 
104  //- input parameter check
105  int err = 0;
106  err += ParameterCheck::non_NULL(str_gconf_status);
107 
108  if (err) {
109  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
110  exit(EXIT_FAILURE);
111  }
112 
113 
114  RandomNumberManager::initialize(str_rand_type, seed);
115 
116 
117  // #### Set up a gauge configuration ####
118  Field_G U(Nvol, Ndim);
119 
120  if (str_gconf_status == "Continue") {
121  GaugeConfig(str_gconf_read).read(U, readfile);
122  } else if (str_gconf_status == "Cold_start") {
123  GaugeConfig("Unit").read(U);
124  } else if (str_gconf_status == "Hot_start") {
125  GaugeConfig("Random").read(U);
126  } else {
127  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
128  exit(EXIT_FAILURE);
129  }
130 
131 
132  // #### object setup ####
133  unique_ptr<Fopr_Wilson> fopr_w(new Fopr_Wilson(params_wilson));
134  fopr_w->set_config(&U);
135 
136  unique_ptr<Source> source(Source::New(str_source_type, params_source));
137 
138  unique_ptr<Fprop_Wilson_Shift> fprop_shift(new Fprop_Wilson_Shift(fopr_w.get(), params_solver));
139 
140  Timer timer(test_name);
141 
142 
143  // #### Execution main part ####
144  timer.start();
145 
146  std::vector<Field_F> xq_shift(Nshift);
147  for (int i_shift = 0; i_shift < Nshift; ++i_shift) {
148  xq_shift[i_shift].set(0.0);
149  }
150 
151  double result;
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  Field_F b;
161  source->set(b, idx);
162 
163  result = fprop_shift->invert_D(&xq_shift, b);
164  }
165  }
166 
167  timer.report();
168 
169 
170  //- Flops counting in giga unit
171  vout.general(vl, "Warning at %s: flop_count has not been implemented.\n", test_name.c_str());
172  vout.general(vl, "\n");
173 
174 
176 
177 
178  if (do_check) {
179  return Test::verify(result, expected_result);
180  } else {
181  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
182  return EXIT_SKIP;
183  }
184  }
185 } // namespace Test_ShiftSolver
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
Field::set
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
Parameters
Class for parameters.
Definition: parameters.h:46
Parameters::get_int
int get_int(const string &key) const
Definition: parameters.cpp:192
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
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
Timer::start
void start()
Definition: timer.cpp:44
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
fprop_Wilson_Shift.h
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
Fprop_Wilson_Shift
Get shifted quark propagators.
Definition: fprop_Wilson_Shift.h:37
Test_Solver_Wilson::solver_ShiftCG
int solver_ShiftCG(void)
Definition: test_Solver_Wilson_ShiftCG.cpp:61
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
Test_Solver_Wilson::test_name
const std::string test_name
Definition: test_Solver_Wilson.cpp:37
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
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
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
Test_Solver_Wilson
Test of Solver with Wilson fermion.
Definition: test_Solver_Wilson.cpp:36
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
Fopr_Wilson
Org::Fopr_Wilson Fopr_Wilson
Wilson fermion operator.
Definition: fopr_Wilson.h:50