DOLFIN
DOLFIN C++ interface
EigenKrylovSolver.h
1 // Copyright (C) 2015 Chris Richardson
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // First added: 2005-02-04
19 
20 #ifndef __DOLFIN_EIGEN_KRYLOV_SOLVER_H
21 #define __DOLFIN_EIGEN_KRYLOV_SOLVER_H
22 
23 #include <map>
24 #include <memory>
25 #include <dolfin/common/types.h>
26 #include "GenericLinearSolver.h"
27 
28 namespace dolfin
29 {
30 
32  class EigenMatrix;
33  class EigenVector;
34  class GenericMatrix;
35  class GenericVector;
36 
39 
41  {
42  public:
43 
46  EigenKrylovSolver(std::string method="default",
47  std::string preconditioner="default");
48 
51 
53  void set_operator(std::shared_ptr<const GenericLinearOperator> A);
54 
56  void set_operator(std::shared_ptr<const EigenMatrix> A);
57 
59  void set_operators(std::shared_ptr<const GenericLinearOperator> A,
60  std::shared_ptr<const GenericLinearOperator> P);
61 
63  void set_operators(std::shared_ptr<const EigenMatrix> A,
64  std::shared_ptr<const EigenMatrix> P);
65 
67  std::shared_ptr<const EigenMatrix> get_operator() const;
68 
70  std::size_t solve(GenericVector& x, const GenericVector& b);
71 
73  std::size_t solve(EigenVector& x, const EigenVector& b);
74 
76  std::size_t solve(const GenericLinearOperator& A, GenericVector& x,
77  const GenericVector& b);
78 
80  std::size_t solve(const EigenMatrix& A, EigenVector& x,
81  const EigenVector& b);
82 
84  std::string str(bool verbose) const;
85 
87  static std::map<std::string, std::string> methods();
88 
90  static std::map<std::string, std::string> preconditioners();
91 
94 
96  std::string parameter_type() const
97  { return "krylov_solver"; }
98 
99  private:
100 
101  // Initialize solver
102  void init(const std::string method, const std::string pc="default");
103 
104  // Call with an actual solver
105  template <typename Solver>
106  std::size_t call_solver(Solver& solver, GenericVector& x,
107  const GenericVector& b);
108 
109  // Chosen Krylov method
110  std::string _method;
111 
112  // Chosen Eigen precondtioner method
113  std::string _pc;
114 
115  // Available solvers and preconditioner descriptions
116  static const std::map<std::string, std::string> _methods_descr;
117  static const std::map<std::string, std::string> _pcs_descr;
118 
119  // Operator (the matrix)
120  std::shared_ptr<const EigenMatrix> _matA;
121 
122  // Matrix used to construct the preconditioner
123  std::shared_ptr<const EigenMatrix> _matP;
124 
125  };
126 
127 }
128 
129 #endif
void set_operator(std::shared_ptr< const GenericLinearOperator > A)
Set operator (matrix)
Definition: EigenKrylovSolver.cpp:91
Definition: adapt.h:29
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: EigenKrylovSolver.cpp:291
static std::map< std::string, std::string > methods()
Return a list of available solver methods.
Definition: EigenKrylovSolver.cpp:58
~EigenKrylovSolver()
Destructor.
Definition: EigenKrylovSolver.cpp:85
Definition: GenericLinearOperator.h:42
Definition: EigenMatrix.h:46
static Parameters default_parameters()
Default parameter values.
Definition: EigenKrylovSolver.cpp:68
Definition: Parameters.h:94
std::size_t solve(GenericVector &x, const GenericVector &b)
Solve linear system Ax = b and return number of iterations.
Definition: EigenKrylovSolver.cpp:129
static std::map< std::string, std::string > preconditioners()
Return a list of available preconditioners.
Definition: EigenKrylovSolver.cpp:63
EigenKrylovSolver(std::string method="default", std::string preconditioner="default")
Definition: EigenKrylovSolver.cpp:75
std::string parameter_type() const
Return parameter type: "krylov_solver" or "lu_solver".
Definition: EigenKrylovSolver.h:96
std::shared_ptr< const EigenMatrix > get_operator() const
Get operator (matrix)
Definition: EigenKrylovSolver.cpp:118
Definition: EigenVector.h:45
This class provides a general solver for linear systems Ax = b.
Definition: GenericLinearSolver.h:37
void set_operators(std::shared_ptr< const GenericLinearOperator > A, std::shared_ptr< const GenericLinearOperator > P)
Set operator (matrix) and preconditioner matrix.
Definition: EigenKrylovSolver.cpp:101
This class defines a common interface for vectors.
Definition: GenericVector.h:47
Definition: EigenKrylovSolver.h:40