Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Spectrum_CRSMatrix_Clover_Lexical.cpp
Go to the documentation of this file.
1 
14 #include "parameterManager_YAML.h"
15 
16 #include "bridgeIO.h"
17 using Bridge::vout;
18 
19 #include "fopr_CRS.h"
20 #include "fopr_Clover.h"
21 
22 #include "source_4spinor_Local.h"
23 
24 #include "solver_CG.h"
25 
26 #include "gaugeConfig.h"
27 
28 #include "test.h"
29 
30 #ifdef USE_TESTMANAGER_AUTOREGISTER
31 #include "testManager.h"
32 #endif
33 
34 //====================================================================
36 
51 namespace Test_Spectrum_CRSMatrix {
52  //- test-private parameters
53  namespace {
54  const std::string filename_input = "test_Spectrum_CRSMatrix_Clover_Lexical.yaml";
55  const std::string filename_output = "stdout";
56 
57  class Parameters_Test_Spectrum_CRSMatrix : public Parameters {
58  public:
59  Parameters_Test_Spectrum_CRSMatrix()
60  {
61  Register_string("gauge_config_type_input", "NULL");
62  Register_string("config_filename_input", "NULL");
63 
64  Register_string("matrix_output", "NULL");
65  Register_string("source_output", "NULL");
66  Register_string("solution_output", "NULL");
67 
68  Register_string("verbose_level", "NULL");
69 
70  Register_double("expected_result", 0.0);
71  }
72  };
73  }
74 
75  //- prototype declaration
76  int clover_lex(void);
77 
78  int CRSsolver(
79  const string& solution,
80  const string& matrix,
81  const string& source,
82  double& result /* return value */
83  );
84 
85  void write_text(const Field& f, const string& filename);
86  void read_text(Field& f, const string& filename);
87 
88 
89 #ifdef USE_TESTMANAGER_AUTOREGISTER
90 #ifdef USE_MPI
91  // this test runs only in single-node environment.
92 #else
93  //- NB. CRS test is skipped, because it is time-consuming.
94 #if 0
95  namespace {
96 #if defined(USE_GROUP_SU2)
97  // Nc=2 is not available.
98 #else
99  static const bool is_registered = TestManager::RegisterTest(
100  "Spectrum.CRSMatrix.Clover_Lexical",
101  clover_lex
102  );
103 #endif
104  }
105 #endif
106 #endif
107 #endif
108 
109  //====================================================================
110  int clover_lex(void)
111  {
112  // #### parameter setup ####
113  int Nc = CommonParameters::Nc();
114  int Nd = CommonParameters::Nd();
115  int Ndim = CommonParameters::Ndim();
116  int Nvol = CommonParameters::Nvol();
117 
118  Parameters_Test_Spectrum_CRSMatrix params_test;
119 
120  Parameters params_all;
121 
122  params_all.Register_Parameters("Test_Spectrum_CRSMatrix", &params_test);
123 
124  ParameterManager_YAML params_manager;
125  params_manager.read_params(filename_input, &params_all);
126 
127  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
128  const string readfile = params_test.get_string("config_filename_input");
129  const string matrix_file = params_test.get_string("matrix_output");
130  const string source_file = params_test.get_string("source_output");
131  const string solution_file = params_test.get_string("solution_output");
132  const string str_vlevel = params_test.get_string("verbose_level");
133 
134  const bool do_check = params_test.is_set("expected_result");
135  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
136 
138 
139  //- print input parameters
140  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
141  vout.general(vl, " readfile = %s\n", readfile.c_str());
142  vout.general(vl, " matrix_output = %s\n", matrix_file.c_str());
143  vout.general(vl, " source_output = %s\n", source_file.c_str());
144  vout.general(vl, " solution_output = %s\n", solution_file.c_str());
145  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
146  vout.general(vl, "\n");
147 
148  //- input parameter check
149  int err = 0;
150  err += ParameterCheck::non_NULL(str_gconf_read);
151  err += ParameterCheck::non_NULL(readfile);
152  err += ParameterCheck::non_NULL(matrix_file);
153  err += ParameterCheck::non_NULL(source_file);
154  err += ParameterCheck::non_NULL(solution_file);
155 
156  if (err) {
157  vout.crucial(vl, "Test_Spectrum_CRSMatrix: Input parameters have not been set.\n");
158  abort();
159  }
160 
161 
162  // #### Set up a gauge configuration ####
163  Field_G *U = new Field_G(Nvol, Ndim);
164  GaugeConfig *gconf_read = new GaugeConfig(str_gconf_read);
165  gconf_read->read_file((Field *)U, readfile);
166  // gconf_read->set_cold((Field*)U);
167 
168 
169  // #### object setup #####
170  Fopr_Clover *fopr_c = new Fopr_Clover();
171  double kappa = 0.12;
172  double cSW = 1.0;
173  valarray<int> boundary(Ndim);
174  boundary[0] = -1;
175  boundary[1] = -1;
176  boundary[2] = -1;
177  boundary[3] = -1;
178  fopr_c->set_parameters(kappa, cSW, boundary);
179  fopr_c->set_config(U);
180  fopr_c->set_mode("D");
181 
182  Fopr_CRS *fopr_crs = new Fopr_CRS(fopr_c);
183  fopr_crs->write_matrix(matrix_file);
184 
185  int Niter = 5000;
186  double Stop_cond = 1.0e-28;
187  Solver *solver = new Solver_CG((Fopr *)fopr_c);
188  solver->set_parameters(Niter, Stop_cond);
189 
190  valarray<int> source_position(Ndim);
191  source_position[0] = 0;
192  source_position[1] = 0;
193  source_position[2] = 0;
194  source_position[3] = 0;
195 
197  source->set_parameters(source_position);
198 
199 
200  // #### Execution main part ####
201  valarray<Field_F> sq(Nc * Nd);
202  Field_F xq, b, b2;
203 
204  {
205  int ispin = 0;
206  {
207  int icolor = 0;
208  //for(int ispin = 0; ispin < Nd; ++ispin){
209  // for(int icolor = 0; icolor < Nc; ++icolor){
210 
211  source->set(b, icolor, ispin);
212 
213 // b.write_text("source4x8_clover.crs");
214  write_text(b, "source4x8_clover.crs");
215 
216  fopr_c->set_mode("D");
217  fopr_c->mult_dag(b2, b);
218 
219  int Nconv;
220  double diff_CG;
221  fopr_c->set_mode("DdagD");
222  solver->solve(xq, b2, Nconv, diff_CG);
223  vout.general(vl, " ispin = %2d icolor = %2d Nconv = %4d diff = %12.6e\n",
224  ispin, icolor, Nconv, diff_CG);
225 
226 // xq.write_text("solution4x8_clover.crs");
227  write_text(xq, "solution4x8_clover.crs");
228 
229 // Field y(b);
230 // fopr_c->set_mode("D");
231 // y -= fopr_c->mult(xq);
232 
233  Field y(b);
234  fopr_c->set_mode("D");
235  fopr_c->mult(y, xq);
236  y -= b;
237  y *= -1.0;
238 
239  double yy = y.norm2();
240  vout.general(vl, " standard norm2 = %.8e\n", yy);
241 
242  sq[icolor + Nc * ispin] = xq;
243  }
244  }
245 
246 #if 0
247  // ### Solver for CRS version ###
248 
249  Solver *solver_crs = new Solver_CG((Fopr *)fopr_crs2);
250  solver_crs->set_parameters(Niter, Stop_cond);
251 
252  double yy = 0.0L;
253  {
254  int ispin = 0;
255  {
256  int icolor = 0;
257  //for(int ispin = 0; ispin < Nd; ++ispin){
258  // for(int icolor = 0; icolor < Nc; ++icolor){
259 
260  source->set(b, icolor, ispin);
261 
262  fopr_crs2->set_mode("Ddag");
263  b2 = (Field_F)fopr_crs2->mult((Field)b);
264 
265  int Nconv;
266  double diff_CG;
267  fopr_crs2->set_mode("DdagD");
268  solver_crs->solve(xq, b2, Nconv, diff_CG);
269  vout.general(vl, " ispin = %2d icolor = %2d Nconv = %4d diff = %12.6e\n",
270  ispin, icolor, Nconv, diff_CG);
271 
272  Field_F y(b);
273  fopr_crs2->set_mode("D");
274  y -= (Field_F)fopr_crs2->mult((Field)xq);
275  yy = y.norm2();
276  vout.general(vl, " standard norm2 = %.8e\n", yy);
277 
278  sq[icolor + Nc * ispin] = xq;
279  }
280  }
281 #endif
282 
283 
284  double result;
285  CRSsolver(solution_file, matrix_file, source_file, result);
286 
287 
288  // #### tidy up ####
289  delete U;
290  delete gconf_read;
291 
292  delete source;
293  delete solver;
294 
295  delete fopr_crs;
296  delete fopr_c;
297 
298 #if 0
299  delete solver_crs;
300  delete fopr_crs2;
301 #endif
302 
303 
304  if (do_check) {
305  return Test::verify(expected_result, result);
306  } else {
307  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
308  return EXIT_SKIP;
309  }
310  }
311 } // namespace Test_Spectrum_CRSMatrix
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:207
void read_params(const std::string &params_file, Parameters *params)
read parameters from file.
void detailed(const char *format,...)
Definition: bridgeIO.cpp:50
double norm2() const
Definition: field.cpp:469
void general(const char *format,...)
Definition: bridgeIO.cpp:38
const Field mult(const Field &f)
multiplies fermion operator to a given field and returns the resultant field.
Definition: fopr_Clover.h:107
Container of Field-type object.
Definition: field.h:37
const Field mult_dag(const Field &f)
hermitian conjugate of mult(const Field&amp;).
Definition: fopr_Clover.h:115
Class for parameters.
Definition: parameters.h:40
void set(Field_F &src, int ic, int id)
Standard Conjugate Gradient solver algorithm.
Definition: solver_CG.h:41
Wilson-type fermion field.
Definition: field_F.h:37
virtual void set_parameters(const Parameters &params)=0
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:79
void set_config(Field *U)
setting pointer to the gauge configuration.
Definition: fopr_Clover.h:90
SU(N) gauge field.
Definition: field_G.h:36
int CRSsolver(const string &solution, const string &matrix, const string &source, double &result)
void write_matrix(std::string)
Definition: fopr_CRS.cpp:260
int non_NULL(const std::string v)
Definition: checker.cpp:61
void write_text(const Field &f, const string &filename)
void crucial(const char *format,...)
Definition: bridgeIO.cpp:26
void Register_Parameters(const string &, Parameters *const)
Definition: parameters.cpp:359
void read_text(Field &f, const string &filename)
Base class for linear solver class family.
Definition: solver.h:37
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:25
Parameter manager with YAML parser.
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:56
Base class of fermion operator family.
Definition: fopr.h:39
int verify(const double expected, const double result)
Definition: test.cpp:27
void read_file(Field *u, const string &filename)
Definition: gaugeConfig.cpp:85
Fermion operator with CRS matrix format.
Definition: fopr_CRS.h:38
virtual void solve(Field &solution, const Field &source, int &Nconv, double &diff)=0
void set_parameters(const Parameters &params)
void set_mode(std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr_Clover.h:97
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:191
void set_parameters(const Parameters &params)
Definition: fopr_Clover.cpp:81