Bridge++  Ver. 1.1.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Spectrum_CRSMatrix_Domainwall.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_Wilson.h"
21 #include "fopr_Domainwall.h"
22 
23 #include "gaugeConfig.h"
24 
25 #include "source_4spinor_Local.h"
26 
27 #include "solver_CG.h"
28 
29 #ifdef USE_TEST
30 #include "test.h"
31 #endif
32 
33 #ifdef USE_TESTMANAGER_AUTOREGISTER
34 #include "testManager.h"
35 #endif
36 
37 //====================================================================
39 
54 namespace Test_Spectrum_CRSMatrix {
55  //- test-private parameters
56  namespace {
57  const std::string filename_input = "test_Spectrum_CRSMatrix_Domainwall.yaml";
58  const std::string filename_output = "stdout";
59 
60  class Parameters_Test_Spectrum_CRSMatrix : public Parameters {
61  public:
62  Parameters_Test_Spectrum_CRSMatrix()
63  {
64  Register_string("gauge_config_type_input", "NULL");
65  Register_string("config_filename_input", "NULL");
66 
67  Register_string("matrix_output", "NULL");
68  Register_string("source_output", "NULL");
69  Register_string("solution_output", "NULL");
70 
71  Register_string("verbose_level", "NULL");
72 
73  Register_double("expected_result", 0.0);
74  }
75  };
76  }
77 
78  //- prototype declaration
79  int domainwall(void);
80 
81  int CRSsolver(
82  const string& solution,
83  const string& matrix,
84  const string& source,
85  double& result /* return value */
86  );
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  // namespace {
95  // static const bool is_registered = TestManager::RegisterTest(
96  // "Spectrum.CRSMatrix.Domainwall",
97  // domainwall
98  // );
99  // }
100 #endif
101 #endif
102 
103  //====================================================================
104  int domainwall(void)
105  {
106  // #### parameter setup ####
107  int Nc = CommonParameters::Nc();
108  int Nd = CommonParameters::Nd();
109  int Nvol = CommonParameters::Nvol();
110  int Ndim = CommonParameters::Ndim();
111 
112  Parameters_Test_Spectrum_CRSMatrix params_test;
113 
114  Parameters params_all;
115 
116  params_all.Register_Parameters("Test_Spectrum_CRSMatrix", &params_test);
117 
118  ParameterManager_YAML params_manager;
119  params_manager.read_params(filename_input, &params_all);
120 
121  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
122  const string readfile = params_test.get_string("config_filename_input");
123  const string matrix_file = params_test.get_string("matrix_output");
124  const string source_file = params_test.get_string("source_output");
125  const string solution_file = params_test.get_string("solution_output");
126  const string str_vlevel = params_test.get_string("verbose_level");
127 #ifdef USE_TEST
128  const double expected_result = params_test.get_double("expected_result");
129 #endif
130 
132 
133  //- print input parameters
134  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
135  vout.general(vl, " readfile = %s\n", readfile.c_str());
136  vout.general(vl, " matrix_output = %s\n", matrix_file.c_str());
137  vout.general(vl, " source_output = %s\n", source_file.c_str());
138  vout.general(vl, " solution_output = %s\n", solution_file.c_str());
139  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
140  vout.general(vl, "\n");
141 
142  //- input parameter check
143  int err = 0;
144  err += ParameterCheck::non_NULL(str_gconf_read);
145  err += ParameterCheck::non_NULL(readfile);
146  err += ParameterCheck::non_NULL(matrix_file);
147  err += ParameterCheck::non_NULL(source_file);
148  err += ParameterCheck::non_NULL(solution_file);
149 
150  if (err) {
151  vout.crucial(vl, "Test_Spectrum_CRSMatrix: Input parameters have not been set.\n");
152  abort();
153  }
154 
155 
156  // #### Set up a gauge configuration ####
157  Field_G *U = new Field_G(Nvol, Ndim);
158  GaugeConfig *gconf_read = new GaugeConfig(str_gconf_read);
159  gconf_read->read_file((Field *)U, readfile);
160  // gconf_read->set_cold((Field*)U);
161 
162 
163  // #### object setup #####
164  Fopr_Wilson *fopr_w = new Fopr_Wilson;
165  Fopr_Domainwall *fopr_dw = new Fopr_Domainwall(fopr_w);
166  double mq = 0.1;
167  double M0 = 1.6;
168  int Ns = 8;
169  valarray<int> boundary(Ndim);
170  boundary[0] = 1;
171  boundary[1] = 1;
172  boundary[2] = 1;
173  boundary[3] = -1;
174  fopr_dw->set_parameters(mq, M0, Ns, boundary);
175  fopr_dw->set_config(U);
176 
177  fopr_dw->set_mode("D");
178  Fopr_CRS *fopr_crs = new Fopr_CRS(fopr_dw);
179  fopr_crs->write_matrix(matrix_file);
180 
181  valarray<int> source_position(Ndim);
182  source_position[0] = 0;
183  source_position[1] = 0;
184  source_position[2] = 0;
185  source_position[3] = 0;
187  source->set_parameters(source_position);
188 
189  //- CGNE solver
190  int Niter = 2000;
191  double Stop_cond = 1.0e-28;
192  Solver *solver = new Solver_CG(fopr_dw);
193  solver->set_parameters(Niter, Stop_cond);
194 
195 
196  // #### Execution main part ####
197  Field_F b(Nvol, 1);
198  Field_F xq(Nvol, 1);
199 
200  int Nin = 2 * Nc * Nd;
201  int Nex = Ns;
202 
203  Field bt(Nin, Nvol, 1);
204  Field xt(Nin, Nvol, 1), xt2(Nin, Nvol, 1);
205 
206  Field b_5d(Nin, Nvol, Nex), bt_5d(Nin, Nvol, Nex);
207  Field xq_5d(Nin, Nvol, Nex);
208 
209  double diff = 0.0L;
210  {
211  int ispin = 0;
212  {
213  int icolor = 0;
214  {
215  int ch = -1;
216  // for(int ispin = 0; ispin < Nd; ++ispin){
217  // for(int icolor = 0; icolor < Nc; ++icolor){
218  // for(int ch = -1; ch <= 1; ch = ch+2){
219 
220  // source->mksrc(b,ispin,icolor);
221  source->set(b, icolor, ispin);
222 
223  bt = fopr_dw->mult_chproj_4d(b, ch);
224 
225  bt_5d = 0.0;
226  if (ch == -1) {
227  bt_5d.setpart_ex(Nex - 1, bt, 0);
228  } else {
229  bt_5d.setpart_ex(0, bt, 0);
230  }
231 
232  //- save the source vector
233  bt_5d.write_text(source_file);
234 
235  fopr_dw->set_mode("Ddag");
236  b_5d = fopr_dw->mult(bt_5d);
237 
238  vout.general(vl, " b_5d norm2 = %14.6e\n", b_5d.norm2());
239 
240  int Nconv;
241  fopr_dw->set_mode("DdagD");
242  solver->solve(xq_5d, b_5d, Nconv, diff);
243  vout.general(vl, " chirality: %2d\n", ch);
244  vout.general(vl, " Nconv = %d, diff = %16.8e\n", Nconv, diff);
245 
246  //- save the solution vector
247  xq_5d.write_text(solution_file);
248  }
249  }
250  }
251 
252 
253  double result;
254  CRSsolver(solution_file, matrix_file, source_file, result);
255 
256 
257  // #### tidy up ####
258  delete U;
259  delete gconf_read;
260 
261  delete solver;
262  delete source;
263  delete fopr_crs;
264  delete fopr_dw;
265  delete fopr_w;
266 
267 
268 #ifdef USE_TEST
269  return Test::verify(expected_result, result);
270 
271 #else
272  return EXIT_SUCCESS;
273 #endif
274  }
275 } // namespace Test_Spectrum_CRSMatrix