Bridge++  Ver. 1.1.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Spectrum_CRSMatrix_CRSsolver.cpp
Go to the documentation of this file.
1 
14 #include "commonParameters.h"
15 #include "communicator.h"
16 #include "bridgeIO.h"
17 using Bridge::vout;
18 
19 #include "field.h"
20 #include "fopr_CRS.h"
21 #include "solver_CG.h"
22 
23 #ifdef USE_TEST
24 #include "test.h"
25 #endif
26 
27 // // clover set
28 // string solution = "solution4x8_clover.crs";
29 // string matrix = "matrix4x8_clover.crs";
30 // string source = "source4x8_clover.crs";
31 
32 // // 5d-overlap set
33 // string solution = "solution4x4_ov5d.crs";
34 // string matrix = "matrix4x4_ov5d.crs";
35 // string source = "source4x4_ov5d.crs";
36 
37 // // domain-wall set
38 // string solution = "solution4x4_dw.crs";
39 // string matrix = "matrix4x4_dw.crs";
40 // string source = "source4x4_dw.crs";
41 
42 
43 namespace Test_Spectrum_CRSMatrix {
44  int CRSsolver(
45  const string& solution,
46  const string& matrix,
47  const string& source,
48  double& result /* return value */
49  )
50  {
52 
53  // ##### Following part is common #####
54 
55  // read source and solution vectors
56  Field b, xq;
57 
58  b.read_text(source);
59  xq.read_text(solution);
60 
61  // read CRS matrix
62  Fopr_CRS *fopr = new Fopr_CRS(matrix);
63 
64 
65  // setup of CG solver
66  int Niter = 2000;
67  double Stop_cond = 1.0e-28;
68  Solver *solver = new Solver_CG((Fopr *)fopr);
69  solver->set_parameters(Niter, Stop_cond);
70 
71  Field b2(b);
72  Field x(b);
73 
74  // setup of CGNE source
75  fopr->Ddag(b2, b);
76 
77  // CGNE solver
78  int Nconv;
79  double diff;
80  fopr->set_mode("DdagD");
81  solver->solve(x, b2, Nconv, diff);
82  vout.general(vl, "solver(CG): Nconv = %4d diff = %12.6e\n", Nconv, diff);
83 
84  // check
85  x -= xq;
86  double xx = x.norm2();
87  vout.general(vl, "standard norm2 = %.8e\n", xx);
88 
89  result = xx;
90 
91  delete solver;
92  delete fopr;
93 
94  return EXIT_SUCCESS;
95  }
96 } // namespace Test_Spectrum_CRSMatrix