DOLFIN
DOLFIN C++ interface
PETScLUSolver.h
1 // Copyright (C) 2005-2017 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 #ifndef __DOLFIN_PETSC_LU_SOLVER_H
19 #define __DOLFIN_PETSC_LU_SOLVER_H
20 
21 #ifdef HAS_PETSC
22 
23 #if PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR <= 8 && PETSC_VERSION_RELEASE == 1
24 #define MatSolverType MatSolverPackage
25 #define PCFactorGetMatSolverType PCFactorGetMatSolverPackage
26 #define PCFactorSetMatSolverType PCFactorSetMatSolverPackage
27 #endif
28 
29 
30 #include <map>
31 #include <memory>
32 #include <string>
33 #include <petscmat.h>
34 #include <petscpc.h>
35 #include <dolfin/common/MPI.h>
36 #include "PETScKrylovSolver.h"
37 
38 namespace dolfin
39 {
41  class GenericLinearOperator;
42  class GenericVector;
43  class PETScLinearOperator;
44  class PETScMatrix;
45  class PETScVector;
46 
50 
52  {
53  public:
54 
56  PETScLUSolver(MPI_Comm comm, std::string method="default");
57 
59  PETScLUSolver(std::string method="default");
60 
62  PETScLUSolver(MPI_Comm comm,
63  std::shared_ptr<const PETScMatrix> A,
64  std::string method="default");
65 
67  PETScLUSolver(std::shared_ptr<const PETScMatrix> A,
68  std::string method="default");
69 
72 
74  void set_operator(std::shared_ptr<const GenericLinearOperator> A);
75 
77  void set_operator(const PETScMatrix& A);
78 
80  std::size_t solve(GenericVector& x, const GenericVector& b);
81 
83  std::size_t solve(GenericVector& x, const GenericVector& b,
84  bool transpose);
85 
87  std::size_t solve(const GenericLinearOperator& A, GenericVector& x,
88  const GenericVector& b);
89 
91  std::size_t solve(const PETScMatrix& A, PETScVector& x,
92  const PETScVector& b);
93 
96  void set_options_prefix(std::string options_prefix);
97 
100  std::string get_options_prefix() const;
101 
103  void set_from_options() const;
104 
106  MPI_Comm mpi_comm() const;
107 
109  std::string str(bool verbose) const;
110 
112  KSP ksp() const;
113 
115  static std::map<std::string, std::string> methods();
116 
119 
121  std::string parameter_type() const
122  { return "lu_solver"; }
123 
124  // FIXME: These should not be friend classes
125  friend class PETScSNESSolver;
126  friend class PETScTAOSolver;
127 
128  private:
129 
130  // FIXME: Remove
131  // Available LU solvers
132  static std::map<std::string, const MatSolverType> lumethods;
133 
134  // Select LU solver type
135  static const MatSolverType select_solver(MPI_Comm comm,
136  std::string method);
137 
138  PETScKrylovSolver _solver;
139 
140  };
141 
142 }
143 
144 #endif
145 
146 #endif
~PETScLUSolver()
Destructor.
Definition: PETScLUSolver.cpp:213
Definition: PETScVector.h:60
Definition: adapt.h:29
PETScLUSolver(MPI_Comm comm, std::string method="default")
Constructor.
Definition: PETScLUSolver.cpp:129
Definition: PETScKrylovSolver.h:54
Definition: PETScTAOSolver.h:51
Definition: GenericLinearOperator.h:42
Definition: PETScMatrix.h:58
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: PETScLUSolver.cpp:292
KSP ksp() const
Return PETSc KSP pointer.
Definition: PETScLUSolver.cpp:308
static Parameters default_parameters()
Default parameter values.
Definition: PETScLUSolver.cpp:121
Definition: PETScLUSolver.h:51
static std::map< std::string, std::string > methods()
Return a list of available solver methods.
Definition: PETScLUSolver.cpp:116
Definition: Parameters.h:94
Definition: PETScSNESSolver.h:45
std::size_t solve(GenericVector &x, const GenericVector &b)
Solve linear system Ax = b.
Definition: PETScLUSolver.cpp:229
std::string parameter_type() const
Return parameter type: "krylov_solver" or "lu_solver".
Definition: PETScLUSolver.h:121
void set_from_options() const
Set options from the PETSc options database.
Definition: PETScLUSolver.cpp:282
void set_operator(std::shared_ptr< const GenericLinearOperator > A)
Set operator (matrix)
Definition: PETScLUSolver.cpp:219
This class provides a general solver for linear systems Ax = b.
Definition: GenericLinearSolver.h:37
void set_options_prefix(std::string options_prefix)
Definition: PETScLUSolver.cpp:272
This class defines a common interface for vectors.
Definition: GenericVector.h:47
std::string get_options_prefix() const
Definition: PETScLUSolver.cpp:277
MPI_Comm mpi_comm() const
Returns the MPI communicator.
Definition: PETScLUSolver.cpp:287