Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  unique_ptr<Field_G> U(new Field_G(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> fopr_w(Fopr::New("Wilson", str_gmset_type));
134  fopr_w->set_parameters(params_wilson);
135  fopr_w->set_config(U);
136 
137  const unique_ptr<Source> source(Source::New(str_source_type));
138  source->set_parameters(params_source);
139 
140  unique_ptr<Index_lex> index(new Index_lex);
141 
142  const unique_ptr<Fprop_Wilson_Shift> fprop_shift(new Fprop_Wilson_Shift(fopr_w, index));
143  fprop_shift->set_parameters(params_solver);
144 
145  const unique_ptr<Timer> timer(new Timer(test_name));
146 
147 
148  // #### Execution main part ####
149  timer->start();
150 
151  std::vector<Field_F> xq_shift(Nshift);
152  for (int i_shift = 0; i_shift < Nshift; ++i_shift) {
153  xq_shift[i_shift].set(0.0);
154  }
155 
156  double result;
157  {
158  const int ispin = 0;
159  {
160  const int icolor = 0;
161  // for(int ispin = 0; ispin < Nd; ++ispin){
162  // for(int icolor = 0; icolor < Nc; ++icolor){
163 
164  int idx = icolor + Nc * ispin;
165  Field_F b;
166  source->set(b, idx);
167 
168  result = fprop_shift->invert_D(&xq_shift, b);
169  }
170  }
171 
172  timer->report();
173 
175 
176 
177  if (do_check) {
178  return Test::verify(result, expected_result);
179  } else {
180  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
181  return EXIT_SKIP;
182  }
183  }
184 } // namespace Test_ShiftSolver
#define EXIT_SKIP
Definition: test.h:17
const std::string test_name
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
void general(const char *format,...)
Definition: bridgeIO.cpp:197
virtual void set_config(Field *)=0
setting pointer to the gauge configuration.
int get_int(const string &key) const
Definition: parameters.cpp:192
Class for parameters.
Definition: parameters.h:46
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
Lexical site index.
Definition: index_lex.h:34
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 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
VerboseLevel
Definition: bridgeIO.h:42
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
void set_parameters(const Parameters &params)
Definition: timer.h:31
double invert_D(std::vector< Field_F > *, const Field_F &)
string get_string(const string &key) const
Definition: parameters.cpp:221
Get shifted quark propagators.
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