Bridge++  Ver. 2.0.2
test_Spectrum_Wilson_2ptFunction.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
22 
23 #include "Tools/gammaMatrixSet.h"
25 
26 //====================================================================
28 
42  const std::string test_name = "Spectrum.Wilson.Hadron2ptFunction";
43 
44  //- test-private parameters
45  namespace {
46  const std::string filename_input = "test_Spectrum_Wilson_Hadron2ptFunction.yaml";
47  }
48 
49  //- prototype declaration
50  int hadron_2ptFunction(void);
51 
52 #ifdef USE_TESTMANAGER_AUTOREGISTER
53  namespace {
54 #if defined(USE_GROUP_SU2)
55  // Nc=2 is not available.
56 #else
57  static const bool is_registered = TestManager::RegisterTest(
58  test_name,
60  );
61 #endif
62  }
63 #endif
64 
65  //====================================================================
67  {
68  // #### parameter setup ####
69  const int Nc = CommonParameters::Nc();
70  const int Nd = CommonParameters::Nd();
71  const int Ndim = CommonParameters::Ndim();
72  const int Nvol = CommonParameters::Nvol();
73 
74  const Parameters params_all = ParameterManager::read(filename_input);
75 
76  const Parameters params_test = params_all.lookup("Test_Spectrum");
77  const Parameters params_gfix = params_all.lookup("GaugeFixing");
78  const Parameters params_fopr = params_all.lookup("Fopr");
79  const Parameters params_solver = params_all.lookup("Solver");
80  const Parameters params_source = params_all.lookup("Source");
81 
82  const string str_gconf_status = params_test.get_string("gauge_config_status");
83  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
84  const string readfile = params_test.get_string("config_filename_input");
85  const string str_rand_type = params_test.get_string("random_number_type");
86  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
87  const string str_vlevel = params_test.get_string("verbose_level");
88 
89  const bool do_check = params_test.is_set("expected_result");
90  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
91 
92  const string str_gfix_type = params_gfix.get_string("gauge_fixing_type");
93  const string str_fopr_type = params_fopr.get_string("fermion_type");
94  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
95  const string str_solver_type = params_solver.get_string("solver_type");
96  const string str_source_type = params_source.get_string("source_type");
97 
98  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
99 
100  //- print input parameters
101  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
102  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
103  vout.general(vl, " readfile = %s\n", readfile.c_str());
104  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
105  vout.general(vl, " seed = %lu\n", seed);
106  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
107  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
108  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
109  vout.general(vl, " solver_type = %s\n", str_solver_type.c_str());
110  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
111 
112  //- input parameter check
113  int err = 0;
114  err += ParameterCheck::non_NULL(str_gconf_status);
115 
116  if (err) {
117  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
118  exit(EXIT_FAILURE);
119  }
120 
121  if (str_solver_type == "CG") {
122  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
123  exit(EXIT_FAILURE);
124  }
125 
126  if ((str_gfix_type == "Coulomb") || (str_gfix_type == "Landau")) {
127  if (CommonParameters::Nc() != 3) {
128  vout.crucial(vl, "check skipped: Nc = 3 is needed, but Nc = %d.\n\n", CommonParameters::Nc());
129  return EXIT_SKIP;
130  }
131  }
132 
133 
134  RandomNumberManager::initialize(str_rand_type, seed);
135 
136 
137  // #### Set up a gauge configuration ####
138  Field_G U(Nvol, Ndim);
139 
140  if (str_gconf_status == "Continue") {
141  GaugeConfig(str_gconf_read).read(U, readfile);
142  } else if (str_gconf_status == "Cold_start") {
143  GaugeConfig("Unit").read(U);
144  } else if (str_gconf_status == "Hot_start") {
145  GaugeConfig("Random").read(U);
146  } else {
147  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
148  exit(EXIT_FAILURE);
149  }
150 
151  // #### Gauge fixing ####
152  {
153  Field_G Ufix(Nvol, Ndim);
154  unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type, params_gfix));
155 
156  gfix->fix(Ufix, U);
157  copy(U, Ufix);
158  }
159 
160 
161  // #### object setup #####
162  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
163 
164  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, params_fopr));
165  fopr->set_config(&U);
166 
167  unique_ptr<Solver> solver(Solver::New(str_solver_type, fopr.get(), params_solver));
168 
169  unique_ptr<Fprop> fprop_lex(new Fprop_Standard_lex(solver.get()));
170 
171  unique_ptr<Source> source(Source::New(str_source_type, params_source));
172 
173  Corr2pt_4spinor corr(gmset.get(), params_all.lookup("Corr2pt_4spinor"));
174 
175  Timer timer(test_name);
176 
177 
178  // #### Execution main part ####
179  timer.start();
180 
181  std::vector<Field_F> sq(Nc * Nd);
182  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
183  sq[i_cd].set(0.0);
184  }
185 
186  vout.general(vl, "\n");
187  vout.general(vl, "Solving quark propagator:\n");
188  vout.general(vl, " color spin Nconv diff diff2\n");
189 
190  for (int ispin = 0; ispin < Nd; ++ispin) {
191  for (int icolor = 0; icolor < Nc; ++icolor) {
192  int i_cd = icolor + Nc * ispin;
193 
194  Field_F b; // b.set(0.0);
195  source->set(b, i_cd);
196 
197  int Nconv;
198  double diff;
199  fprop_lex->invert_D(sq[i_cd], b, Nconv, diff);
200 
201  Field_F y(b);
202  fopr->set_mode("D");
203  fopr->mult(y, sq[i_cd]); // y = fopr->mult(sq[i_cd]);
204  axpy(y, -1.0, b); // y -= b;
205  double diff2 = y.norm2() / b.norm2();
206 
207  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
208  icolor, ispin, Nconv, diff, diff2);
209  }
210  }
211 
212  //- meson correlators
213  vout.general(vl, "\n");
214  vout.general(vl, "2-point correlator:\n");
215 
216  const double result = corr.meson_all(sq, sq);
217 
218  timer.report();
219 
221 
222 
223  if (do_check) {
224  return Test::verify(result, expected_result);
225  } else {
226  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
227  return EXIT_SKIP;
228  }
229  }
230 } // namespace Test_Spectrum_Wilson
Test_Spectrum_Wilson
Test of Spectrum with Wilson fermion, prepared for beginners.
Definition: test_Spectrum_Wilson_2ptFunction.cpp:41
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
Fprop_Standard_lex
Get quark propagator for Fopr with lexical site index.
Definition: fprop_Standard_lex.h:33
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
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
fprop_Standard_lex.h
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
Test_Spectrum_Wilson::test_name
const std::string test_name
Definition: test_Spectrum_Wilson_2ptFunction.cpp:42
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.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
Test_Spectrum_Wilson::hadron_2ptFunction
int hadron_2ptFunction(void)
Definition: test_Spectrum_Wilson_2ptFunction.cpp:66
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
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
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