G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsTrilinosSolvers.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsTrilinos/Vector.h>
17 #include <gsIO/gsOptionList.h>
18 
19 
20 
21 namespace gismo
22 {
23 
24 namespace trilinos
25 {
26 
32 namespace solver
33 {
34 
36 class AmesosSolver;
37 class AztecSolver;
38 class BelosSolver;
39 class MLSolver;
40 
43 {
44  enum {
45  Lapack = 1,
46  KLU = 2,
47  Umfpack = 3,
48  Pardiso = 4,
49  Taucs = 5,
50  SuperLU = 6,
52  Mumps = 8,
53  Dscpack = 9
54  };
55 };
56 
57 //constants for solver types - from az_aztec_defs.h
58 #define AZ_cg 0 /* preconditioned conjugate gradient method */
59 #define AZ_gmres 1 /* preconditioned gmres method */
60 #define AZ_cgs 2 /* preconditioned cg squared method */
61 #define AZ_tfqmr 3 /* preconditioned transpose-free qmr method */
62 #define AZ_bicgstab 4 /* preconditioned stabilized bi-cg method */
63 #define AZ_slu 5 /* super LU direct method. */
64 #define AZ_symmlq 6 /* indefinite symmetric like symmlq */
65 #define AZ_GMRESR 7 /* recursive GMRES (not supported) */
66 #define AZ_fixed_pt 8 /* fixed point iteration */
67 #define AZ_analyze 9 /* fixed point iteration */
68 #define AZ_lu 10 /* sparse LU direct method. Also used for a */
69 #define AZ_cg_condnum 11
70 #define AZ_gmres_condnum 12
71 
72 //constants for preconditioners - from az_aztec_defs.h
73 #define AZ_none 0 /* no preconditioning. Note: also used for */
74 /* scaling, output, overlap options options */
75 #define AZ_Jacobi 1 /* Jacobi preconditioning. Note: also used for */
76 /* scaling options */
77 #define AZ_sym_GS 2 /* symmetric Gauss-Siedel preconditioning */
78 #define AZ_Neumann 3 /* Neumann series polynomial preconditioning */
79 #define AZ_ls 4 /* least-squares polynomial preconditioning */
80 #define AZ_ilu 6 /* domain decomp with ilu in subdomains */
81 #define AZ_bilu 7 /* domain decomp with block ilu in subdomains */
82 /* #define AZ_lu 10 domain decomp with lu in subdomains */
83 #define AZ_icc 8 /* domain decomp with incomp Choleski in domains*/
84 #define AZ_ilut 9 /* domain decomp with ilut in subdomains */
85 #define AZ_rilu 11 /* domain decomp with rilu in subdomains */
86 #define AZ_recursive 12 /* Recursive call to AZ_iterate() */
87 #define AZ_smoother 13 /* Recursive call to AZ_iterate() */
88 #define AZ_dom_decomp 14 /* Domain decomposition using subdomain solver */
89 /* given by options[AZ_subdomain_solve] */
90 #define AZ_multilevel 15 /* Do multiplicative domain decomp with coarse */
91 /* grid (not supported). */
92 #define AZ_user_precond 16 /* user's preconditioning */
93 /* Begin Aztec 2.1 mheroux mod */
94 #define AZ_bilu_ifp 17 /* dom decomp with bilu using ifpack in subdom */
95 /* End Aztec 2.1 mheroux mod */
96 
99 {
100  enum {
101  CG = AZ_cg,
102  CGCondNum = AZ_cg_condnum,
103  Gmres = AZ_gmres,
104  GmresCondNum = AZ_gmres_condnum,
105  GmresR = AZ_GMRESR,
106  CGS = AZ_cgs,
107  TFQMR = AZ_tfqmr,
108  BiCGStab = AZ_bicgstab,
109  LU = AZ_lu,
110  SLU = AZ_slu,
111  SymmLQ = AZ_symmlq,
112  FixedPoint = AZ_fixed_pt,
113  Analyze = AZ_analyze
114  };
115 };
116 
119 {
120  enum {
121  None = AZ_none,
122  Jacobi = AZ_Jacobi,
123  Neumann = AZ_Neumann,
124  LS = AZ_ls,
125  GS = AZ_sym_GS,
126  DD = AZ_dom_decomp,
127  ILU = AZ_ilu,
128  BILU = AZ_bilu,
129  ICC = AZ_icc,
130  ILUT = AZ_ilut,
131  RILU = AZ_rilu,
132  Recursive = AZ_recursive,
133  Smoother = AZ_smoother,
134  Multilevel = AZ_multilevel,
135  UserDefined = AZ_user_precond,
136  IfpackBILU = AZ_bilu_ifp
137  };
138 };
139 
142 {
143  enum {
144  LU = AZ_lu,
145  ILUT = AZ_ilut,
146  ILU = AZ_ilu,
147  RILU = AZ_rilu,
148  BILU = AZ_bilu,
149  ICC = AZ_icc
150  };
151 };
152 
153 #undef AZ_cg
154 #undef AZ_gmres
155 #undef AZ_cgs
156 #undef AZ_tfqmr
157 #undef AZ_bicgstab
158 #undef AZ_slu
159 #undef AZ_symmlq
160 #undef AZ_GMRESR
161 #undef AZ_fixed_pt
162 #undef AZ_analyze
163 #undef AZ_lu
164 #undef AZ_cg_condnum
165 #undef AZ_gmres_condnum
166 //
167 #undef AZ_none
168 #undef AZ_Jacobi
169 #undef AZ_sym_GS
170 #undef AZ_Neumann
171 #undef AZ_ls
172 #undef AZ_ilu
173 #undef AZ_bilu
174 #undef AZ_icc
175 #undef AZ_ilut
176 #undef AZ_rilu
177 #undef AZ_recursive
178 #undef AZ_smoother
179 #undef AZ_dom_decomp
180 #undef AZ_multilevel
181 #undef AZ_user_precond
182 #undef AZ_bilu_ifp
183 
184 
187 {
188  enum {
189  BiCGStab = 1,
190  BlockCG = 2,
191 #ifdef Belos_ENABLE_Experimental
192  BlockGCRODR = 3,
193 #endif
196  GCRODR = 6,
197  GmresPoly = 7,
198  LSQR = 8,
199  Minres = 9,
200  PCPG = 10,
205  RCG = 15,
206  TFQMR = 16
207  };
208 };
209 
210 struct MLSolvers
211 {
212  enum {
213  SA = 1,
214  NSSA = 2,
215  DD = 3,
216  DDLU = 4,
218  DDML = 5,
219  DDMLLU = 6
221  };
224 };
225 
226 struct AbstractSolverPrivate;
227 
233 class GISMO_EXPORT AbstractSolver
234 {
235  public:
236 
238  AbstractSolver();
239  explicit AbstractSolver(const SparseMatrix & A);
240 
242  ~AbstractSolver();
243 
245  const Vector & solve(const Vector & b);
246 
248  void getSolution(gsVector<real_t> & sol, const int rank = 0) const;
249 
251  virtual std::string validParams() const = 0;
252 
254  virtual std::string currentParams() const = 0;
255 
257  virtual std::string status() const = 0;
258 
260  virtual std::string timing() const = 0;
261 
263  virtual void set(const std::string & name, const int & value) = 0;
264  virtual void set(const std::string & name, const bool & value) = 0;
265  virtual void set(const std::string & name, const double & value) = 0;
266  virtual void set(const std::string & name, const std::string & value) = 0;
267 
269  void setOptions(const gsOptionList & opt);
270 
273 
274  protected:
276  virtual void solveProblem() = 0;
277 
278  protected:
279  AbstractSolverPrivate * my;
280 };
281 
287 class GISMO_EXPORT AbstractDirectSolver : public AbstractSolver
288 {
289  public:
290 
292  explicit AbstractDirectSolver(const SparseMatrix & A)
293  : AbstractSolver(A) { }
294 
295 };
296 
302 class GISMO_EXPORT AbstractIterativeSolver : public AbstractSolver
303 {
304  public:
305 
308  explicit AbstractIterativeSolver(const SparseMatrix & A);
309 
310  protected:
311 
313  virtual int numIterations() const = 0;
314 
315 protected:
316 
318  double tolerance;
319 
321  int maxIter;
322 };
323 
324 /* --- Amesos solver --- */
325 
326 struct AmesosSolverPrivate;
327 
332 class GISMO_EXPORT AmesosSolver : public AbstractDirectSolver
333 {
334  public:
335  typedef AbstractDirectSolver Base;
336 
337  public:
338 
340  explicit AmesosSolver(const SparseMatrix & A,
341  const int solver = AmesosSolvers::KLU);
342 
344  ~AmesosSolver();
345 
347  std::string validParams() const;
348  std::string currentParams() const;
349 
351  std::string status() const;
352  std::string timing() const;
353 
355  void set(const std::string & name, const int & value);
356  void set(const std::string & name, const bool & value);
357  void set(const std::string & name, const double & value);
358  void set(const std::string & name, const std::string & value);
359 
360  private:
361 
363  void solveProblem();
364  void solveProblem(const bool noSymbolicFactorization,
365  const bool noNumericFactorization);
366 
367 private:
368 
369  AmesosSolverPrivate * myAmesos;
370 };
371 
372 /* --- Aztec solver --- */
373 
374 struct AztecSolverPrivate;
375 
380 class GISMO_EXPORT AztecSolver : public AbstractIterativeSolver
381 {
382  public:
384 
385  public:
386 
388  explicit AztecSolver(const SparseMatrix & A,
389  const int solver = AztecSolvers::Gmres,
390  const int precond = AztecPreconds::None,
391  const int subdomain_solver = AztecSubdomainSolvers::ILUT);
392 
394  ~AztecSolver();
395 
397  void setPreconditioner(const BelosSolver & Belos);
398 
400  void setPreconditioner(const MLSolver & ML);
401 
403  std::string validParams() const;
404  std::string currentParams() const;
405 
407  std::string status() const;
408  std::string timing() const;
409 
411  void set(const std::string & name, const int & value);
412  void set(const std::string & name, const bool & value);
413  void set(const std::string & name, const double & value);
414  void set(const std::string & name, const std::string & value);
415 
417  void set(const int & option, const int & value);
418  void set(const int & param, const double & value);
419 
421  int numIterations() const;
422 
423  private:
424 
426  void solveProblem();
427 
428  private:
429 
430  AztecSolverPrivate * myAztec;
431 };
432 
433 /* --- Belos solver --- */
434 
435 struct BelosSolverPrivate;
436 
441 class GISMO_EXPORT BelosSolver : public AbstractIterativeSolver
442 {
443  public:
445 
447  explicit BelosSolver(const SparseMatrix & A,
448  const int solver = BelosSolvers::BiCGStab);
449 
451  ~BelosSolver();
452 
454  std::string validParams() const;
455  std::string currentParams() const;
456 
458  std::string status() const;
459  std::string timing() const;
460 
462  void set(const std::string & name, const int & value);
463  void set(const std::string & name, const bool & value);
464  void set(const std::string & name, const double & value);
465  void set(const std::string & name, const std::string & value);
466 
469  void setHermitian();
470 
472  int setPreconditioner(const std::string & precType, const SparseMatrix &A,
473  const bool & leftprec, const int & OverlapLevel=0);
474 
475  // void setMLPreconditioner(const SparseMatrix &A);
476 
478  int numIterations() const;
479 
480  private:
481 
483  void solveProblem();
484 
485  private:
486 
487  BelosSolverPrivate * myBelos;
488 
489 public:
490 
492  Epetra_Operator * getPrecOperator() const;
493 };
494 
495 /* --- Multi Level (ML) --- */
496 
497 struct MLSolverPrivate;
498 
503 class GISMO_EXPORT MLSolver : public AbstractIterativeSolver
504 {
505 
506  public:
508 
509  public:
510 
512  explicit MLSolver(const SparseMatrix &A,
513  const int solver = MLSolvers::SA);
514 
516  ~MLSolver();
517 
519  std::string validParams() const;
520  std::string currentParams() const;
521 
523  std::string status() const;
524  std::string timing() const;
525 
527  void set(const std::string & name, const int & value);
528  void set(const std::string & name, const bool & value);
529  void set(const std::string & name, const double & value);
530  void set(const std::string & name, const std::string & value);
531 
533  void set(const int & option, const int & value);
534 
536  int numIterations() const;
537 
538  private:
539 
541  void solveProblem();
542 
543  private:
544 
545  MLSolverPrivate * myML;
546 
547  public:
548 
550  Epetra_Operator * getPrecOperator() const;
551 };
552 
553 }// namespace solver
554 }// namespace trilinos
555 }// namespace gismo
Fixed-point iteration.
Definition: gsTrilinosSolvers.h:113
Sparse LU decomposition.
Definition: gsTrilinosSolvers.h:144
Belos solvers.
Definition: gsTrilinosSolvers.h:186
TFQMR solver.
Definition: gsTrilinosSolvers.h:206
User defined preconditioner.
Definition: gsTrilinosSolvers.h:135
Pseudo Block CG solver.
Definition: gsTrilinosSolvers.h:201
DD with block-ILU in subdomains.
Definition: gsTrilinosSolvers.h:128
Fixed-point iteration.
Definition: gsTrilinosSolvers.h:112
SuperLU (parallel)
Definition: gsTrilinosSolvers.h:51
Sparse direct LU solver.
Definition: gsTrilinosSolvers.h:109
Aztec preconditioners.
Definition: gsTrilinosSolvers.h:118
Sparse ILUT decomposition (Saad)
Definition: gsTrilinosSolvers.h:145
Recursive call to iteration.
Definition: gsTrilinosSolvers.h:132
Sparse ILU(k,w) decomposition.
Definition: gsTrilinosSolvers.h:147
Lapack (serial)
Definition: gsTrilinosSolvers.h:45
GMRES solver with cond.num. estimation.
Definition: gsTrilinosSolvers.h:104
Non-overlapping domain decomposition.
Definition: gsTrilinosSolvers.h:126
Abstract direct solver base class.
Definition: gsTrilinosSolvers.h:287
Super LU direct solver.
Definition: gsTrilinosSolvers.h:110
Sparse ICC(k) decomposition.
Definition: gsTrilinosSolvers.h:149
Pseudo Block TFQMR solver.
Definition: gsTrilinosSolvers.h:204
Indefinite symmetric like SymmLQ.
Definition: gsTrilinosSolvers.h:111
DD with RILU in subdomains.
Definition: gsTrilinosSolvers.h:131
Belos solver class.
Definition: gsTrilinosSolvers.h:441
BiCGStab solver.
Definition: gsTrilinosSolvers.h:108
ML solver class.
Definition: gsTrilinosSolvers.h:503
Amesos sparse direct solvers.
Definition: gsTrilinosSolvers.h:42
Recycling GMRES solver.
Definition: gsTrilinosSolvers.h:196
CG squared solver.
Definition: gsTrilinosSolvers.h:106
DD with ILUT in subdomains.
Definition: gsTrilinosSolvers.h:130
DD with ILU in subdomains.
Definition: gsTrilinosSolvers.h:127
Sparse ILU(k) decomposition.
Definition: gsTrilinosSolvers.h:146
Umfpack (serial)
Definition: gsTrilinosSolvers.h:47
LSQR solver.
Definition: gsTrilinosSolvers.h:198
Sparse block ILU(k) decomposition.
Definition: gsTrilinosSolvers.h:148
Pardiso (serial/OpenMP)
Definition: gsTrilinosSolvers.h:48
Dscpack (parallel)
Definition: gsTrilinosSolvers.h:53
DD with incomplete Choleski in subdomains.
Definition: gsTrilinosSolvers.h:129
KLU (serial)
Definition: gsTrilinosSolvers.h:46
DD with coarse grid.
Definition: gsTrilinosSolvers.h:134
Jacobi.
Definition: gsTrilinosSolvers.h:122
Fixed-point solver.
Definition: gsTrilinosSolvers.h:195
Amesos solver class.
Definition: gsTrilinosSolvers.h:332
Provides a list of labeled parameters/options that can be set and accessed easily.
Neumann series polynomial.
Definition: gsTrilinosSolvers.h:123
No preconditioning.
Definition: gsTrilinosSolvers.h:121
Mumps (parallel)
Definition: gsTrilinosSolvers.h:52
int maxIter
Default maximum number of iterations for all iterative solvers.
Definition: gsTrilinosSolvers.h:321
CG solver with cond. num. estimation.
Definition: gsTrilinosSolvers.h:102
Pseudo Block GMRES solver.
Definition: gsTrilinosSolvers.h:202
CG solver.
Definition: gsTrilinosSolvers.h:101
Minres solver.
Definition: gsTrilinosSolvers.h:199
PCPG solver.
Definition: gsTrilinosSolvers.h:200
SuperLU (serial)
Definition: gsTrilinosSolvers.h:50
Symmetric Gauss-Seidel.
Definition: gsTrilinosSolvers.h:125
BiCGStab solver.
Definition: gsTrilinosSolvers.h:189
Wrapper for Trilinos/Epetra vector.
RCG solver.
Definition: gsTrilinosSolvers.h:205
Block GC solver.
Definition: gsTrilinosSolvers.h:190
Recursive call to iteration.
Definition: gsTrilinosSolvers.h:133
Aztec solvers.
Definition: gsTrilinosSolvers.h:98
Hybrid block GMRES solver.
Definition: gsTrilinosSolvers.h:197
Abstract solver base class.
Definition: gsTrilinosSolvers.h:233
GMRES solver.
Definition: gsTrilinosSolvers.h:103
double tolerance
Default tolerance for all iterative solvers.
Definition: gsTrilinosSolvers.h:318
Actez solver class.
Definition: gsTrilinosSolvers.h:380
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
TFQMR solver.
Definition: gsTrilinosSolvers.h:107
Block GMRES solver.
Definition: gsTrilinosSolvers.h:194
Pseudo Block CG solver.
Definition: gsTrilinosSolvers.h:203
recursive GMRES
Definition: gsTrilinosSolvers.h:105
Taucs (serial)
Definition: gsTrilinosSolvers.h:49
Least-squares polynomial.
Definition: gsTrilinosSolvers.h:124
DD with BILU (Ifpack version)
Definition: gsTrilinosSolvers.h:136
Aztec subdomain solver.
Definition: gsTrilinosSolvers.h:141
Abstract iterative solver base class.
Definition: gsTrilinosSolvers.h:302