DOLFIN
DOLFIN C++ interface
LinearSolver.h
1 // Copyright (C) 2004-2016 Anders Logg and 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 // Modified by Garth N. Wells 2006-2010
19 // Modified by Ola Skavhaug 2008
20 //
21 // First added: 2004-06-19
22 // Last changed: 2016-06-22
23 
24 #ifndef __LINEAR_SOLVER_H
25 #define __LINEAR_SOLVER_H
26 
27 #include <memory>
28 #include <string>
29 #include <memory>
30 #include <dolfin/common/types.h>
31 #include "GenericLinearSolver.h"
32 #include <dolfin/common/MPI.h>
33 
34 namespace dolfin
35 {
36 
37  class GenericLinearOperator;
38  class GenericVector;
39  class LUSolver;
40  class KrylovSolver;
41  class LinearVariationalSolver;
42 
44 
46  {
47  public:
48 
50  explicit LinearSolver(std::string method="default",
51  std::string preconditioner="default")
52  : LinearSolver(MPI_COMM_WORLD, method, preconditioner) {}
53 
55  explicit LinearSolver(MPI_Comm comm,
56  std::string method="default",
57  std::string preconditioner="default");
58 
60  ~LinearSolver();
61 
63  void set_operator(std::shared_ptr<const GenericLinearOperator> A);
64 
66  void set_operators(std::shared_ptr<const GenericLinearOperator> A,
67  std::shared_ptr<const GenericLinearOperator> P);
68 
70  std::size_t solve(const GenericLinearOperator& A,
71  GenericVector& x, const GenericVector& b);
72 
74  std::size_t solve(GenericVector& x, const GenericVector& b);
75 
78  {
79  Parameters p("linear_solver");
80  return p;
81  }
82 
86  {
87  this->parameters.update(parameters);
88  solver->update_parameters(parameters);
89  }
90 
91  // FIXME: This should not be needed. Need to cleanup linear solver
92  // name jungle: default, lu, iterative, direct, krylov, etc
94  std::string parameter_type() const
95  { return _parameter_type; }
96 
97  private:
98 
99  // Friends
100  friend class LUSolver;
101  friend class KrylovSolver;
102  friend class LinearVariationalSolver;
103  friend class NewtonSolver;
104 
105  // Check whether string is contained in list
106  static bool in_list(const std::string& method,
107  const std::map<std::string, std::string>& methods);
108 
109  // Solver
110  std::unique_ptr<GenericLinearSolver> solver;
111 
112  // FIXME: This should not be needed
113  // Parameter type
114  std::string _parameter_type;
115 
116  };
117 
118 }
119 
120 #endif
Definition: adapt.h:29
std::size_t solve(const GenericLinearOperator &A, GenericVector &x, const GenericVector &b)
Solve linear system Ax = b.
Definition: LinearSolver.cpp:125
Definition: GenericLinearOperator.h:42
This class implements a solver for linear variational problems.
Definition: LinearVariationalSolver.h:38
LU solver for the built-in LA backends.
Definition: LUSolver.h:35
Definition: KrylovSolver.h:38
This class provides a general solver for linear systems Ax = b.
Definition: LinearSolver.h:45
~LinearSolver()
Destructor.
Definition: LinearSolver.cpp:103
std::string parameter_type() const
Return parameter type: "krylov_solver" or "lu_solver".
Definition: LinearSolver.h:94
Parameters parameters
Parameters.
Definition: Variable.h:74
Definition: Parameters.h:94
virtual void update_parameters(const Parameters &parameters)
Definition: LinearSolver.h:85
This class provides a general solver for linear systems Ax = b.
Definition: GenericLinearSolver.h:37
Definition: NewtonSolver.h:45
void update(const Parameters &parameters)
Update parameters with another set of parameters.
Definition: Parameters.cpp:245
static Parameters default_parameters()
Default parameter values.
Definition: LinearSolver.h:77
void set_operator(std::shared_ptr< const GenericLinearOperator > A)
Set the operator (matrix)
Definition: LinearSolver.cpp:109
This class defines a common interface for vectors.
Definition: GenericVector.h:47
LinearSolver(std::string method="default", std::string preconditioner="default")
Create linear solver.
Definition: LinearSolver.h:50
void set_operators(std::shared_ptr< const GenericLinearOperator > A, std::shared_ptr< const GenericLinearOperator > P)
Set the operator (matrix) and preconditioner matrix.
Definition: LinearSolver.cpp:117