DOLFIN
DOLFIN C++ interface
KrylovSolver.h
1 // Copyright (C) 2007-2009 Garth N. Wells
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 #ifndef __KRYLOV_SOLVER_H
19 #define __KRYLOV_SOLVER_H
20 
21 #include <string>
22 #include <vector>
23 #include <memory>
24 #include "GenericLinearSolver.h"
25 #include <dolfin/common/MPI.h>
26 
27 namespace dolfin
28 {
29 
30  class GenericLinearOperator;
31  class GenericVector;
32  class VectorSpaceBasis;
33 
37 
39  {
40  public:
41 
43  KrylovSolver(MPI_Comm comm,
44  std::string method="default",
45  std::string preconditioner="default");
46 
48  KrylovSolver(std::string method="default",
49  std::string preconditioner="default");
50 
52  KrylovSolver(MPI_Comm comm,
53  std::shared_ptr<const GenericLinearOperator> A,
54  std::string method="default",
55  std::string preconditioner="default");
56 
58  KrylovSolver(std::shared_ptr<const GenericLinearOperator> A,
59  std::string method="default",
60  std::string preconditioner="default");
61 
63  ~KrylovSolver();
64 
66  void set_operator(std::shared_ptr<const GenericLinearOperator> A);
67 
69  void set_operators(std::shared_ptr<const GenericLinearOperator> A,
70  std::shared_ptr<const GenericLinearOperator> P);
71 
73  std::size_t solve(GenericVector& x, const GenericVector& b);
74 
76  std::size_t solve(const GenericLinearOperator& A,
77  GenericVector& x, const GenericVector& b);
78 
81 
85  {
86  this->parameters.update(parameters);
87  solver->parameters.update(parameters);
88  }
89 
90  // FIXME: This should not be needed. Need to cleanup linear solver
91  // name jungle: default, lu, iterative, direct, krylov, etc /
92  // Return parameter type: "krylov_solver" or "lu_solver"
93  std::string parameter_type() const
94  {
95  return "krylov_solver";
96  }
97 
98  private:
99 
100  // Initialize solver
101  void init(std::string method, std::string preconditioner, MPI_Comm comm);
102 
103  // Solver
104  std::shared_ptr<GenericLinearSolver> solver;
105 
106  };
107 }
108 
109 #endif
std::string parameter_type() const
Return parameter type: "krylov_solver" or "lu_solver".
Definition: KrylovSolver.h:93
virtual void update_parameters(const Parameters &parameters)
Definition: KrylovSolver.h:84
Definition: adapt.h:29
void set_operators(std::shared_ptr< const GenericLinearOperator > A, std::shared_ptr< const GenericLinearOperator > P)
Set operator (matrix) and preconditioner matrix.
Definition: KrylovSolver.cpp:93
void set_operator(std::shared_ptr< const GenericLinearOperator > A)
Set operator (matrix)
Definition: KrylovSolver.cpp:85
Definition: GenericLinearOperator.h:42
Definition: KrylovSolver.h:38
Parameters parameters
Parameters.
Definition: Variable.h:74
Definition: Parameters.h:94
std::size_t solve(GenericVector &x, const GenericVector &b)
Solve linear system Ax = b.
Definition: KrylovSolver.cpp:101
This class provides a general solver for linear systems Ax = b.
Definition: GenericLinearSolver.h:37
~KrylovSolver()
Destructor.
Definition: KrylovSolver.cpp:79
void update(const Parameters &parameters)
Update parameters with another set of parameters.
Definition: Parameters.cpp:245
static Parameters default_parameters()
Default parameter values.
Definition: KrylovSolver.cpp:32
This class defines a common interface for vectors.
Definition: GenericVector.h:47
KrylovSolver(MPI_Comm comm, std::string method="default", std::string preconditioner="default")
Constructor.
Definition: KrylovSolver.cpp:48