DOLFIN
DOLFIN C++ interface
GenericLinearSolver.h
1 // Copyright (C) 2008-2013 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 __GENERIC_LINEAR_SOLVER_H
19 #define __GENERIC_LINEAR_SOLVER_H
20 
21 #include <vector>
22 #include <memory>
23 #include <dolfin/common/Variable.h>
24 #include <dolfin/log/log.h>
25 
26 namespace dolfin
27 {
28 
29  // Forward declarations
30  class GenericLinearOperator;
31  class GenericMatrix;
32  class GenericVector;
33  class VectorSpaceBasis;
34 
36 
38  {
39  public:
40 
42  virtual void
43  set_operator(std::shared_ptr<const GenericLinearOperator> A) = 0;
44 
46  virtual void
47  set_operators(std::shared_ptr<const GenericLinearOperator> A,
48  std::shared_ptr<const GenericLinearOperator> P)
49  {
50  dolfin_error("GenericLinearSolver.h",
51  "set operator and preconditioner for linear solver",
52  "Not supported by current linear algebra backend");
53  }
54 
56  virtual std::size_t solve(const GenericLinearOperator& A, GenericVector& x,
57  const GenericVector& b)
58  {
59  dolfin_error("GenericLinearSolver.h",
60  "solve linear system",
61  "Not supported by current linear algebra backend. Consider using solve(x, b)");
62  return 0;
63  }
64 
66  virtual std::size_t solve(GenericVector& x, const GenericVector& b) = 0;
67 
68  // FIXME: This should not be needed. Need to cleanup linear solver
69  // name jungle: default, lu, iterative, direct, krylov, etc
71  virtual std::string parameter_type() const
72  {
73  return "default";
74  }
75 
78  {
79  this->parameters.update(parameters);
80  }
81 
82  protected:
83 
84  // Developer note: The functions here provide similar
85  // functionality as the as_type functions in the
86  // LinearAlgebraObject base class. The difference is that they
87  // specifically complain that a matrix is required, which gives a
88  // user a more informative error message from solvers that don't
89  // support matrix-free representation of linear operators.
90 
94  static const GenericMatrix& require_matrix(const GenericLinearOperator& A);
95 
99  static std::shared_ptr<const GenericMatrix>
100  require_matrix(std::shared_ptr<const GenericLinearOperator> A);
101 
102  };
103 
104 }
105 
106 #endif
Common base class for DOLFIN variables.
Definition: Variable.h:35
virtual void update_parameters(const Parameters &parameters)
Update solver parameters (useful for LinearSolver wrapper)
Definition: GenericLinearSolver.h:77
virtual std::string parameter_type() const
Return parameter type: "krylov_solver" or "lu_solver".
Definition: GenericLinearSolver.h:71
Definition: adapt.h:29
Definition: GenericLinearOperator.h:42
virtual std::size_t solve(const GenericLinearOperator &A, GenericVector &x, const GenericVector &b)
Solve linear system Ax = b.
Definition: GenericLinearSolver.h:56
Parameters parameters
Parameters.
Definition: Variable.h:74
Definition: Parameters.h:94
static const GenericMatrix & require_matrix(const GenericLinearOperator &A)
Definition: GenericLinearSolver.cpp:25
virtual void set_operators(std::shared_ptr< const GenericLinearOperator > A, std::shared_ptr< const GenericLinearOperator > P)
Set operator (matrix) and preconditioner matrix.
Definition: GenericLinearSolver.h:47
virtual void set_operator(std::shared_ptr< const GenericLinearOperator > A)=0
Set operator (matrix)
This class defines a common interface for matrices.
Definition: GenericMatrix.h:46
This class provides a general solver for linear systems Ax = b.
Definition: GenericLinearSolver.h:37
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129
void update(const Parameters &parameters)
Update parameters with another set of parameters.
Definition: Parameters.cpp:245
This class defines a common interface for vectors.
Definition: GenericVector.h:47