Bridge++  Ver. 2.0.2
asolver_MG.h
Go to the documentation of this file.
1 
14 //====================================================================
15 #ifndef ASOLVER_MG_H
16 #define ASOLVER_MG_H
17 
18 #include <cstdio>
19 #include <cstdlib>
20 #include <vector>
21 using std::vector;
22 #include <string>
23 using std::string;
24 
25 #include "lib_alt/Solver/asolver.h"
26 #include "lib/Fopr/afopr.h"
27 #include "lib_alt/Fopr/afopr_dd.h"
31 
32 //====================================================================
33 template<typename AFIELD>
34 class ASolver_MG : public ASolver<AFIELD>
35 {
36  public:
37  typedef typename AFIELD::real_t real_t;
39  // fopr types: should be given in the .cpp file
40  //using FoprD_t = AFopr_Clover<AFIELD>;
41  //using FoprF_t = AFopr_Clover_dd<AFIELD_f>;
42  //using FoprCoarse_t = AFopr_Clover_coarse<AFIELD_f >;
43 
44  // solver types: should be given in the .cpp file
45  //using OuterSolver_t = ASolver_FBiCGStab<AFIELD>;
46  //using CoarseSolver_t = ASolver_BiCGStab_Cmplx< AFIELD_f>;
47  //using Smoother_t = ASolver_SAP<AFIELD_f>;
48 
49 
50  // index
51  // using MultiGrid_t = MultiGrid_Clover<AFIELD_f, AFIELD_f>;
52 
54  static const std::string class_name;
55 
56  protected:
57 
58  // preconditinor: I am the owener
59  unique_ptr<APrecond_MG<AFIELD, AFIELD_f> > m_prec_mg;
60  std::vector<int> m_sap_block_size;
61 
62  // fine grid fermion operators: only references
63  AFopr<AFIELD> *m_afopr_fineD; // assumes double prec.
64  AFopr_dd<AFIELD_f> *m_afopr_fineF; // a block version is required
65  AFopr_dd<AFIELD_f> *m_afopr_smoother; // a block version is required
66 
67  // coarse grid fermion operator: I am the owner
68  unique_ptr<AFopr<AFIELD_f> > m_afopr_coarse;
69 
70  // solvers: I am the owner
71  unique_ptr<ASolver<AFIELD_f> > m_asolver_coarse;
72  unique_ptr<ASolver<AFIELD_f> > m_asolver_smoother;
73  unique_ptr<ASolver<AFIELD> > m_outer_solver;
74 
75  // multigrid converter: I am the owner
76  unique_ptr<MultiGrid<AFIELD_f, AFIELD_f> > m_multigrid;
77 
78  int m_Niter;
80  int m_Nconv;
81 
82  int m_nvec;
83  int m_nsetup;
84 
85  static constexpr int m_min_res_iter = 6;
88 
91  // Parameters m_params_fopr_dd; //!< parameters for fopr, used to generated dd op.
92 
93  std::string m_mode;
94 
96  int m_nconv;
97 
99  //ASolver_MG(){ };
100 
103 
104 
105  public:
108  : m_Niter(0), m_Stop_cond(0.0L)
109  {
110  this->init();
111  }
112 
114  ~ASolver_MG() { this->tidyup(); }
115 
117  void set_parameters(const Parameters& params);
118 
120  void set_parameters_level0(const Parameters& params);
121 
123  void set_parameters_level1(const Parameters& params);
124 
126  void set_parameters(const int Niter, const real_t Stop_cond, const std::vector<int>& sap_block_size, const int nvec);
127 
128  void set_parameters(const int Niter, const real_t Stop_cond, const std::string& outer_vlevel,
129  const std::vector<int>& sap_block_size, const int nvec, const int nsetup,
130  const int coarse_niter, const real_t coarse_stop_cond, const std::string& coarse_vlevel,
131  const int smoother_niter, const real_t smoother_stop_cond);
132 
134  void run_setup();
135  void run_setup(std::vector<AFIELD_f>& testvec_work);
136  void run_setup_initial(std::vector<AFIELD_f>& testvec_work);
137  void run_setup_iterative(int niter, std::vector<AFIELD_f>& testvec_work);
138 
139 
141  void solve(AFIELD& xq, const AFIELD& b, int& nconv, real_t& diff);
142 
148 
149  AFopr_dd<AFIELD_f> *new_fopr_smoother(const Parameters& param) const;
150 
152 
153  // ! set fopr
154  void set_foprD(AFopr<AFIELD> *foprD);
155 
156  void set_foprF(AFopr_dd<AFIELD_f> *foprF);
157 
159 
160  void set_lattice(const vector<int>& sap_block_size);
161 
162  // ! initialize internal solvers
163  void init_solver(std::string mode);
164 
165  // ! initialize internal solvers
166  void init_solver()
167  {
168  init_solver("D");
169  }
170 
172  double flop_count();
173 
175  double flop_count_setup();
176 
177  void reset_flop_count();
178 
179  bool use_fopr_for_smoother() const;
180 
181  protected:
182 
183  void init_coarse_grid();
184 
185  void init(void);
186 
187  void tidyup(void);
188 
189  void solve_MG_init(real_t& rrp, real_t& rr);
190 
191  void solve_MG_step(real_t& rrp, real_t& rr);
192 
193  std::vector<int> m_coarse_lattice;
194 
195  unique_ptr<Timer> m_timer_gramschmidt;
196  unique_ptr<Timer> m_timer_generate_coarse_op;
197 };
198 
199 #endif // include gurad
200 //============================================================END=====
ASolver_MG::m_Stop_cond
real_t m_Stop_cond
stopping criterion (squared).
Definition: asolver_MG.h:79
ASolver_MG::set_foprF
void set_foprF(AFopr_dd< AFIELD_f > *foprF)
Definition: asolver_MG-tmpl.h:216
aprecond_MG.h
Multigrid preconditionor (SIMD version)
AFopr
Definition: afopr.h:48
ASolver
Definition: asolver.h:23
ASolver_MG::m_Niter
int m_Niter
maximum iteration number.
Definition: asolver_MG.h:78
ASolver_MG
Definition: asolver_MG.h:34
ASolver_MG::new_fopr_smoother
AFopr_dd< AFIELD_f > * new_fopr_smoother(const Parameters &param) const
Definition: asolver_MG-tmpl.h:186
Parameters
Class for parameters.
Definition: parameters.h:46
ASolver_MG::m_nsetup
int m_nsetup
setup iterations
Definition: asolver_MG.h:83
ASolver_MG::solve
void solve(AFIELD &xq, const AFIELD &b, int &nconv, real_t &diff)
solver main.
Definition: asolver_MG-tmpl.h:578
ASolver_MG::m_params_asolver_outer
Parameters m_params_asolver_outer
parameters for outer solver
Definition: asolver_MG.h:90
afield_base.h
AField
Definition: afield_base.h:16
ASolver_MG::reset_flop_count
void reset_flop_count()
Definition: asolver_MG-tmpl.h:587
ASolver_MG::m_afopr_fineF
AFopr_dd< AFIELD_f > * m_afopr_fineF
Definition: asolver_MG.h:64
ASolver_MG::m_outer_solver
unique_ptr< ASolver< AFIELD > > m_outer_solver
Definition: asolver_MG.h:73
ASolver_MG::get_foprD
AFopr< AFIELD > * get_foprD()
Definition: asolver_MG.h:145
ASolver_MG::flop_count_setup
double flop_count_setup()
returns the floating point operation count [setup].
ASolver_MG::m_Nconv
int m_Nconv
iteratoin number to calculate flop
Definition: asolver_MG.h:80
real_t
double real_t
Definition: bridgeQXS_Clover_coarse_double.cpp:16
ASolver_MG::use_fopr_for_smoother
bool use_fopr_for_smoother() const
Definition: asolver_MG-tmpl.h:174
ASolver_MG::set_parameters
void set_parameters(const Parameters &params)
setting parameters by a Parameter object.
Definition: asolver_MG-tmpl.h:63
ASolver_MG::solve_MG_init
void solve_MG_init(real_t &rrp, real_t &rr)
ASolver_MG::run_setup
void run_setup()
setup
Definition: asolver_MG-tmpl.h:412
ASolver_MG::m_afopr_smoother
AFopr_dd< AFIELD_f > * m_afopr_smoother
Definition: asolver_MG.h:65
AFopr_dd
Base class of fermion operator family.
Definition: afopr_dd.h:24
ASolver_MG::m_vec_work
AFIELD m_vec_work
calling constructor without fermion operator is forbidden.
Definition: asolver_MG.h:102
ASolver_MG::m_smoother_niter
int m_smoother_niter
Definition: asolver_MG.h:86
MultiGrid.h
ASolver_MG::m_multigrid
unique_ptr< MultiGrid< AFIELD_f, AFIELD_f > > m_multigrid
Definition: asolver_MG.h:76
Field::real_t
double real_t
Definition: field.h:51
ASolver_MG::tidyup
void tidyup(void)
Definition: asolver_MG-tmpl.h:56
ASolver_MG::set_lattice
void set_lattice(const vector< int > &sap_block_size)
Definition: asolver_MG-tmpl.h:342
ASolver_MG::flop_count
double flop_count()
returns the floating point operation count.
Definition: asolver_MG-tmpl.h:596
ASolver_MG::m_mode
std::string m_mode
Definition: asolver_MG.h:93
ASolver_MG::get_fopr_coarse
AFopr< AFIELD_f > * get_fopr_coarse()
Definition: asolver_MG.h:151
afopr_dd.h
ASolver_MG::m_sap_block_size
std::vector< int > m_sap_block_size
Definition: asolver_MG.h:60
ASolver_MG::get_foprF
AFopr_dd< AFIELD_f > * get_foprF()
Definition: asolver_MG.h:146
ASolver_MG::get_fopr_smoother
AFopr_dd< AFIELD_f > * get_fopr_smoother()
Definition: asolver_MG.h:147
ASolver_MG::m_min_res_iter
static constexpr int m_min_res_iter
Definition: asolver_MG.h:85
ASolver_MG::m_nvec
int m_nvec
number of testvectors
Definition: asolver_MG.h:82
ASolver_MG::set_parameters_level0
void set_parameters_level0(const Parameters &params)
setting parameters by a Parameter object.
Definition: asolver_MG-tmpl.h:99
ASolver_MG::m_timer_generate_coarse_op
unique_ptr< Timer > m_timer_generate_coarse_op
Definition: asolver_MG.h:196
ASolver_MG::m_asolver_coarse
unique_ptr< ASolver< AFIELD_f > > m_asolver_coarse
Definition: asolver_MG.h:71
ASolver_MG::m_prec_mg
unique_ptr< APrecond_MG< AFIELD, AFIELD_f > > m_prec_mg
Definition: asolver_MG.h:59
ASolver_MG::~ASolver_MG
~ASolver_MG()
destructor.
Definition: asolver_MG.h:114
ASolver_MG::class_name
static const std::string class_name
Definition: asolver_MG.h:54
ASolver_MG::m_params_asolver_coarse
Parameters m_params_asolver_coarse
parameters for coarse grid solver
Definition: asolver_MG.h:89
ASolver_MG::init_solver
void init_solver()
Definition: asolver_MG.h:166
ASolver_MG::m_afopr_coarse
unique_ptr< AFopr< AFIELD_f > > m_afopr_coarse
Definition: asolver_MG.h:68
ASolver_MG::init
void init(void)
Definition: asolver_MG-tmpl.h:43
ASolver_MG::set_foprD
void set_foprD(AFopr< AFIELD > *foprD)
Definition: asolver_MG-tmpl.h:198
ASolver_MG::m_smoother_stop_cond
int m_smoother_stop_cond
Definition: asolver_MG.h:87
ASolver_MG::m_nconv
int m_nconv
set "D" for colver (default), "DdagD" for domainwall
Definition: asolver_MG.h:96
ASolver_MG::m_asolver_smoother
unique_ptr< ASolver< AFIELD_f > > m_asolver_smoother
Definition: asolver_MG.h:72
ASolver_MG::run_setup_initial
void run_setup_initial(std::vector< AFIELD_f > &testvec_work)
Definition: asolver_MG-tmpl.h:441
ASolver_MG::m_afopr_fineD
AFopr< AFIELD > * m_afopr_fineD
Definition: asolver_MG.h:63
ASolver_MG::run_setup_iterative
void run_setup_iterative(int niter, std::vector< AFIELD_f > &testvec_work)
Definition: asolver_MG-tmpl.h:511
ASolver_MG::get_fopr
AFopr< AFIELD > * get_fopr()
returns the pointer to the fermion operator.
Definition: asolver_MG.h:144
ASolver_MG::m_timer_gramschmidt
unique_ptr< Timer > m_timer_gramschmidt
Definition: asolver_MG.h:195
ASolver_MG::set_fopr_smoother
void set_fopr_smoother(AFopr_dd< AFIELD_f > *foprF)
Definition: asolver_MG-tmpl.h:232
Field
Container of Field-type object.
Definition: field.h:46
afopr.h
ASolver_MG::m_coarse_lattice
std::vector< int > m_coarse_lattice
Definition: asolver_MG.h:193
ASolver_MG::solve_MG_step
void solve_MG_step(real_t &rrp, real_t &rr)
ASolver_MG::real_t
AFIELD::real_t real_t
Definition: asolver_MG.h:37
asolver.h
ASolver::real_t
AFIELD::real_t real_t
Definition: asolver.h:29
ASolver_MG::ASolver_MG
ASolver_MG()
constructor.
Definition: asolver_MG.h:107
ASolver_MG::init_coarse_grid
void init_coarse_grid()
Definition: asolver_MG-tmpl.h:282
ASolver_MG::set_parameters_level1
void set_parameters_level1(const Parameters &params)
setting parameters by a Parameter object.
Definition: asolver_MG-tmpl.h:107