Bridge++  Ver. 2.0.2
test_Spectrum_CRSMatrix_Domainwall.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "Fopr/fopr_CRS.h"
17 #include "Field/field_F.h"
18 #include "Fopr/fopr_Domainwall.h"
19 
20 #include "IO/gaugeConfig.h"
21 
23 
24 #include "Solver/solver_CG.h"
25 
26 //====================================================================
28 
45 namespace Test_Spectrum_CRSMatrix {
46  //- test-private parameters
47  namespace {
48  const std::string filename_input = "test_Spectrum_CRSMatrix_Domainwall.yaml";
49  const std::string filename_output = "stdout";
50  }
51 
52  //- prototype declaration
53  int domainwall(void);
54 
55  int CRSsolver(
56  const string& solution,
57  const string& matrix,
58  const string& source,
59  double& result /* return value */
60  );
61 
62  void write_text(const Field& f, const string& filename);
63  void read_text(Field& f, const string& filename);
64 
65 #ifdef USE_TESTMANAGER_AUTOREGISTER
66 #ifdef USE_MPI
67  // this test runs only in single-node environment.
68 #else
69  //- NB. CRS test is skipped, because it is time-consuming.
70 #if 0
71  namespace {
72  static const bool is_registered = TestManager::RegisterTest(
73  "Spectrum.CRSMatrix.Domainwall",
75  );
76  }
77 #endif
78 #endif
79 #endif
80 
81  //====================================================================
82  int domainwall(void)
83  {
84  // #### parameter setup ####
85  const int Nc = CommonParameters::Nc();
86  const int Nd = CommonParameters::Nd();
87  const int Nvol = CommonParameters::Nvol();
88  const int Ndim = CommonParameters::Ndim();
89 
90  const Parameters params_all = ParameterManager::read(filename_input);
91 
92  const Parameters params_test = params_all.lookup("Test_Spectrum_CRSMatrix");
93 
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 matrix_file = params_test.get_string("matrix_output");
97  const string source_file = params_test.get_string("source_output");
98  const string solution_file = params_test.get_string("solution_output");
99  const string str_vlevel = params_test.get_string("verbose_level");
100 
101  const bool do_check = params_test.is_set("expected_result");
102  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
103 
104  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
105 
106  //- print input parameters
107  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
108  vout.general(vl, " readfile = %s\n", readfile.c_str());
109  vout.general(vl, " matrix_output = %s\n", matrix_file.c_str());
110  vout.general(vl, " source_output = %s\n", source_file.c_str());
111  vout.general(vl, " solution_output = %s\n", solution_file.c_str());
112  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
113  vout.general(vl, "\n");
114 
115  //- input parameter check
116  int err = 0;
117  err += ParameterCheck::non_NULL(str_gconf_read);
118  err += ParameterCheck::non_NULL(readfile);
119  err += ParameterCheck::non_NULL(matrix_file);
120  err += ParameterCheck::non_NULL(source_file);
121  err += ParameterCheck::non_NULL(solution_file);
122 
123  if (err) {
124  vout.crucial(vl, "Error: Test_Spectrum_CRSMatrix: input parameters have not been set\n");
125  exit(EXIT_FAILURE);
126  }
127 
128 
129  // #### Set up a gauge configuration ####
130  Field_G U(Nvol, Ndim);
131  GaugeConfig gconf_read(str_gconf_read);
132  gconf_read.read_file(U, readfile);
133 
134 
135  // #### object setup #####
136  const double mq = 0.1;
137  const double M0 = 1.6;
138  const int Ns = 8;
139  std::vector<int> boundary(Ndim);
140  boundary[0] = 1;
141  boundary[1] = 1;
142  boundary[2] = 1;
143  boundary[3] = -1;
144 
145 
146  Parameters params_dw;
147  params_dw.set_double("quark_mass", mq);
148  params_dw.set_double("domain_wall_height", M0);
149  params_dw.set_int("extent_of_5th_dimension", Ns);
150  params_dw.set_int_vector("boundary_condition", boundary);
151 
152 
153  // Fopr_Wilson fopr_w("Dirac");
154  // Fopr_Domainwall *fopr_dw = new Fopr_Domainwall(&fopr_w);
155  // fopr_dw->set_parameters(params_dw);
156 
157  // Fopr_Wilson *fopr_w = new Fopr_Wilson("Dirac");
158  // Fopr_Domainwall *fopr_dw = new Fopr_Domainwall(fopr_w, params_dw);
159 
160  unique_ptr<Fopr_Domainwall> fopr_dw(new Fopr_Domainwall(params_dw));
161 
162  fopr_dw->set_config(&U);
163  fopr_dw->set_mode("D");
164 
165  unique_ptr<Fopr_CRS> fopr_crs(new Fopr_CRS(fopr_dw.get()));
166  fopr_crs->write_matrix(matrix_file);
167 
168  // std::vector<int> source_position(Ndim);
169  // source_position[0] = 0;
170  // source_position[1] = 0;
171  // source_position[2] = 0;
172  // source_position[3] = 0;
173  std::vector<int> source_position { 0, 0, 0, 0 };
174  Parameters params_source;
175  params_source.set_int_vector("source_position", source_position);
176 
177  unique_ptr<Source> source(Source::New("Local", params_source));
178 
179 
180  //- CGNE solver
181  int Niter = 100;
182  int Nrestart = 40;
183  double Stop_cond = 1.0e-28;
184  bool use_init_guess = false;
185 
186  Parameters params_solver;
187  params_solver.set_int("maximum_number_of_iteration", Niter);
188  params_solver.set_int("maximum_number_of_restart", Nrestart);
189  params_solver.set_double("convergence_criterion_squared", Stop_cond);
190  params_solver.set_double("use_initial_guess", use_init_guess);
191 
192  unique_ptr<Solver> solver(new Solver_CG(fopr_dw.get(), params_solver));
193 
194 
195  // #### Execution main part ####
196  const int Nin = 2 * Nc * Nd;
197  const int Nex = Ns;
198 
199  for (int ispin = 0; ispin < Nd; ++ispin) {
200  for (int icolor = 0; icolor < Nc; ++icolor) {
201  for (int ch = -1; ch <= 1; ch = ch + 2) {
202  int idx = icolor + Nc * ispin;
203 
204  Field_F b;
205  source->set(b, idx);
206 
207  Field bt(Nin, Nvol, 1);
208  fopr_dw->mult_chproj_4d(bt, b, ch);
209 
210  Field bt_5d(Nin, Nvol, Nex);
211  bt_5d.set(0.0);
212  if (ch == -1) {
213  bt_5d.setpart_ex(Nex - 1, bt, 0);
214  } else {
215  bt_5d.setpart_ex(0, bt, 0);
216  }
217 
218  //- save the source vector
219  write_text(bt_5d, source_file);
220 
221  Field b_5d(Nin, Nvol, Nex);
222  fopr_dw->set_mode("Ddag");
223  fopr_dw->mult(b_5d, bt_5d);
224 
225  vout.general(vl, " b_5d norm2 = %14.6e\n", b_5d.norm2());
226 
227  Field xq_5d(Nin, Nvol, Nex);
228  int Nconv;
229  double diff;
230  fopr_dw->set_mode("DdagD");
231  solver->solve(xq_5d, b_5d, Nconv, diff);
232  vout.general(vl, " chirality: %2d\n", ch);
233  vout.general(vl, " Nconv = %d, diff = %16.8e\n", Nconv, diff);
234 
235  //- save the solution vector
236  write_text(xq_5d, solution_file);
237  }
238  }
239  }
240 
241  double result = 0.0;
242  CRSsolver(solution_file, matrix_file, source_file, result);
243 
244 
245  if (do_check) {
246  return Test::verify(result, expected_result);
247  } else {
248  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
249  return EXIT_SKIP;
250  }
251  }
252 } // namespace Test_Spectrum_CRSMatrix
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Field::setpart_ex
void setpart_ex(int ex, const Field &w, int exw)
Definition: field.h:201
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
field_F.h
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::set_double
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
fopr_Domainwall.h
source.h
Test_Spectrum_CRSMatrix::domainwall
int domainwall(void)
Definition: test_Spectrum_CRSMatrix_Domainwall.cpp:82
Field::norm2
double norm2() const
Definition: field.cpp:113
Test_Spectrum_CRSMatrix
Test of CRS matrix format.
Definition: test_Spectrum_CRSMatrix_Clover_Lexical.cpp:45
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
Fopr_Domainwall
AFopr_Domainwall< Field > Fopr_Domainwall
Domain-wall fermion operator.
Definition: fopr_Domainwall.h:33
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
fopr_CRS.h
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_Solver_Wilson::solver
int solver(const std::string &)
Definition: test_Solver_Wilson.cpp:134
Parameters::set_int_vector
void set_int_vector(const string &key, const vector< int > &value)
Definition: parameters.cpp:45
Test_Spectrum_CRSMatrix::CRSsolver
int CRSsolver(const string &solution, const string &matrix, const string &source, double &result)
Definition: test_Spectrum_CRSMatrix_CRSsolver.cpp:41
EXIT_SKIP
#define EXIT_SKIP
Definition: test.h:17
CommonParameters::Nd
static int Nd()
Definition: commonParameters.h:116
Test_Spectrum_CRSMatrix::read_text
void read_text(Field &f, const string &filename)
Definition: test_Spectrum_CRSMatrix_CRSsolver.cpp:134
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
Fopr_CRS
Fermion operator with CRS matrix format.
Definition: fopr_CRS.h:37
GaugeConfig::read_file
void read_file(Field_G &U, const string &filename)
Definition: gaugeConfig.h:100
Parameters::set_int
void set_int(const string &key, const int value)
Definition: parameters.cpp:36
Test_Spectrum_CRSMatrix::write_text
void write_text(const Field &f, const string &filename)
Definition: test_Spectrum_CRSMatrix_CRSsolver.cpp:103
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
solver_CG.h
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Solver_CG
Standard Conjugate Gradient solver algorithm.
Definition: solver_CG.h:38
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
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