Bridge++  Ver. 2.0.2
test_Spectrum_Overlap_2ptFunction.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
17 
18 #include "Fopr/fopr_Overlap.h"
19 
20 #include "IO/gaugeConfig.h"
21 
25 
26 #include "Solver/solver.h"
27 
28 #include "Tools/gammaMatrixSet.h"
30 
31 //====================================================================
33 
51  const std::string test_name = "Spectrum.Overlap.Hadron2ptFunction";
52 
53  //- test-private parameters
54  namespace {
55  const std::string filename_input = "test_Spectrum_Overlap_Hadron2ptFunction.yaml";
56  }
57 
58  //- prototype declaration
59  int hadron_2ptFunction(void);
60 
61 #ifdef USE_TESTMANAGER_AUTOREGISTER
62  namespace {
63 #if defined(USE_GROUP_SU2)
64  // Nc=2 is not available.
65 #else
66  static const bool is_registered = TestManager::RegisterTest(
67  test_name,
69  );
70 #endif
71  }
72 #endif
73 
74  //====================================================================
76  {
77  // #### parameter setup ####
78  const int Ndim = CommonParameters::Ndim();
79  const int Nc = CommonParameters::Nc();
80  const int Nd = CommonParameters::Nd();
81  const int Nvol = CommonParameters::Nvol();
82 
83  const Parameters params_all = ParameterManager::read(filename_input);
84 
85  const Parameters params_test = params_all.lookup("Test_Spectrum_Overlap");
86  const Parameters params_gfix = params_all.lookup("GaugeFixing");
87  const Parameters params_wilson = params_all.lookup("Fopr_Wilson");
88  const Parameters params_overlap = params_all.lookup("Fopr_Overlap");
89  const Parameters params_irlanczos = params_all.lookup("Eigensolver");
90  const Parameters params_solver = params_all.lookup("Solver");
91  const Parameters params_source = params_all.lookup("Source");
92 
93  const string str_gconf_status = params_test.get_string("gauge_config_status");
94  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
95  const string readfile = params_test.get_string("config_filename_input");
96  const string str_rand_type = params_test.get_string("random_number_type");
97  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
98  const string str_vlevel = params_test.get_string("verbose_level");
99 
100  const bool do_check = params_test.is_set("expected_result");
101  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
102 
103  const string str_gfix_type = params_gfix.get_string("gauge_fixing_type");
104  //const string str_gmset_type = params_wilson.get_string("gamma_matrix_type");
105  const string str_gmset_type = params_overlap.get_string("gamma_matrix_type");
106  const string str_solver_type = params_solver.get_string("solver_type");
107  const string str_source_type = params_source.get_string("source_type");
108 
109  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
110 
111  //- print input parameters
112  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
113  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
114  vout.general(vl, " readfile = %s\n", readfile.c_str());
115  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
116  vout.general(vl, " seed = %lu\n", seed);
117  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
118  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
119  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
120  vout.general(vl, " solver_type = %s\n", str_solver_type.c_str());
121  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
122 
123  //- input parameter check
124  int err = 0;
125  err += ParameterCheck::non_NULL(str_gconf_status);
126 
127  if (err) {
128  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
129  exit(EXIT_FAILURE);
130  }
131 
132  if (str_solver_type == "CG") {
133  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
134  exit(EXIT_FAILURE);
135  }
136 
137  if ((str_gfix_type == "Coulomb") || (str_gfix_type == "Landau")) {
138  if (CommonParameters::Nc() != 3) {
139  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
140  return EXIT_SKIP;
141  }
142  }
143 
144 
145  RandomNumberManager::initialize(str_rand_type, seed);
146 
147 
148  // #### Set up a gauge configuration ####
149  Field_G U(Nvol, Ndim);
150 
151  if (str_gconf_status == "Continue") {
152  GaugeConfig(str_gconf_read).read(U, readfile);
153  } else if (str_gconf_status == "Cold_start") {
154  GaugeConfig("Unit").read(U);
155  } else if (str_gconf_status == "Hot_start") {
156  GaugeConfig("Random").read(U);
157  } else {
158  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
159  exit(EXIT_FAILURE);
160  }
161 
162 
163  // #### Gauge fixing ####
164  {
165  Field_G Ufix(Nvol, Ndim);
166  unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type, params_gfix));
167 
168  gfix->fix(Ufix, U);
169  copy(U, Ufix);
170  }
171 
172 
173  // #### object setup ####
174  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
175 
176  // unique_ptr<Fopr> fopr_w(Fopr::New("Wilson", params_wilson));
177  // fopr_w->set_config(&U);
178 
179  //- with low-mode subtraction
180  // int Nsbt = 0;
181  // std::vector<double> TDa;
182  // std::vector<Field> vk;
183  // calc_lowmodes(params_irlanczos, Nsbt, TDa, vk, fopr_w);
184 
185  // unique_ptr<Fopr> fopr_overlap(Fopr::New("Overlap", fopr_w.get(), params_overlap));
186  unique_ptr<Fopr> fopr_overlap(Fopr::New("Overlap", params_overlap));
187  fopr_overlap->set_config(&U);
188  // fopr_overlap->set_lowmodes(Nsbt, &TDa, &vk);
189 
190  unique_ptr<Solver> solver(Solver::New(str_solver_type, fopr_overlap.get(), params_solver));
191 
192  unique_ptr<Source> source(Source::New(str_source_type, params_source));
193 
194  Corr2pt_4spinor corr(gmset.get(), params_all.lookup("Corr2pt_4spinor"));
195 
196  Timer timer(test_name);
197 
198 
199  // #### Execution main part ####
200  timer.start();
201 
202  std::vector<Field_F> sq(Nc * Nd);
203  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
204  sq[i_cd].set(0.0);
205  }
206 
207  vout.general(vl, "\n");
208  vout.general(vl, "Solving quark propagator:\n");
209  vout.general(vl, " color spin Nconv diff diff2\n");
210 
211  int Nin = fopr_overlap->field_nin();
212  int Nex = fopr_overlap->field_nex();
213 
214  Field b(Nin, Nvol, Nex);
215  Field y(Nin, Nvol, Nex);
216 
217 #pragma omp parallel
218  {
219  for (int ispin = 0; ispin < Nd; ++ispin) {
220  for (int icolor = 0; icolor < Nc; ++icolor) {
221  int icd = icolor + Nc * ispin;
222 
223  source->set(b, icd);
224 
225  int Nconv;
226  double diff;
227  fopr_overlap->set_mode("D");
228  solver->solve(sq[icd], b, Nconv, diff);
229 
230  fopr_overlap->set_mode("D");
231  fopr_overlap->mult(y, sq[icd]);
232  axpy(y, -1.0, b); // y -= b;
233  double diff2 = y.norm2() / b.norm2();
234 
235  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
236  icolor, ispin, Nconv, diff, diff2);
237  }
238  }
239  }
240 
241  //- meson correlators
242  vout.general(vl, "\n");
243  vout.general(vl, "2-point correlator:\n");
244 
245  const double result = corr.meson_all(sq, sq);
246 
247 
248  timer.report();
249 
251 
252 
253  if (do_check) {
254  return Test::verify(result, expected_result);
255  } else {
256  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
257  return EXIT_SKIP;
258  }
259  }
260 } // namespace Test_Spectrum_Overlap
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
solver.h
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
Test_Spectrum_Overlap::test_name
const std::string test_name
Definition: test_Spectrum_Overlap_2ptFunction.cpp:51
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
fopr_Overlap.h
Parameters
Class for parameters.
Definition: parameters.h:46
Test_Spectrum_Overlap::hadron_2ptFunction
int hadron_2ptFunction(void)
Definition: test_Spectrum_Overlap_2ptFunction.cpp:75
Corr2pt_4spinor::meson_all
double meson_all(const std::vector< Field_F > &sq1, const std::vector< Field_F > &sq2)
Definition: corr2pt_4spinor.cpp:53
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
source.h
Timer
Definition: timer.h:31
RandomNumberManager::finalize
static void finalize()
Definition: randomNumberManager.cpp:80
copy
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:212
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Field::norm2
double norm2() const
Definition: field.cpp:113
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
Test_Spectrum_Overlap
Test class of overlap fermion operators.
Definition: test_Spectrum_Overlap_2ptFunction.cpp:50
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
Corr2pt_4spinor
Two-point correlator for Wilson-type fermions.
Definition: corr2pt_4spinor.h:42
Test_Solver_Wilson::solver
int solver(const std::string &)
Definition: test_Solver_Wilson.cpp:134
eigensolver_IRLanczos.h
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
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
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
gaugeFixing.h
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
corr2pt_4spinor.h
gammaMatrixSet.h
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