DOLFIN-X
DOLFIN-X C++ interface
PETScKrylovSolver.h
1 // Copyright (C) 2004-2015 Johan Jansson and Garth N. Wells
2 //
3 // This file is part of DOLFINX (https://www.fenicsproject.org)
4 //
5 // SPDX-License-Identifier: LGPL-3.0-or-later
6 
7 #pragma once
8 
9 #include "PETScVector.h"
10 #include <dolfinx/common/MPI.h>
11 #include <petscksp.h>
12 #include <petscmat.h>
13 #include <petscvec.h>
14 #include <string>
15 
16 namespace dolfinx
17 {
18 namespace fem
19 {
20 class PETScDMCollection;
21 }
22 
23 namespace la
24 {
25 
28 
30 {
31 public:
34  explicit PETScKrylovSolver(MPI_Comm comm);
35 
37  explicit PETScKrylovSolver(KSP ksp, bool inc_ref_count = true);
38 
40  virtual ~PETScKrylovSolver();
41 
43  void set_operator(const Mat A);
44 
46  void set_operators(const Mat A, const Mat P);
47 
50  int solve(Vec x, const Vec b, bool transpose = false);
51 
54  void set_options_prefix(std::string options_prefix);
55 
58  std::string get_options_prefix() const;
59 
61  void set_from_options() const;
62 
64  KSP ksp() const;
65 
67  void set_dm(DM dm);
68 
70  void set_dm_active(bool val);
71 
72 private:
73  // PETSc solver pointer
74  KSP _ksp;
75 };
76 } // namespace la
77 } // namespace dolfinx
This class implements Krylov methods for linear systems of the form Ax = b. It is a wrapper for the K...
Definition: PETScKrylovSolver.h:30
void set_dm(DM dm)
Set the DM.
Definition: PETScKrylovSolver.cpp:162
void set_operator(const Mat A)
Set operator (Mat)
Definition: PETScKrylovSolver.cpp:45
void set_operators(const Mat A, const Mat P)
Set operator and preconditioner matrix (Mat)
Definition: PETScKrylovSolver.cpp:47
void set_options_prefix(std::string options_prefix)
Sets the prefix used by PETSc when searching the PETSc options database.
Definition: PETScKrylovSolver.cpp:177
int solve(Vec x, const Vec b, bool transpose=false)
Solve linear system Ax = b and return number of iterations (A^t x = b if transpose is true)
Definition: PETScKrylovSolver.cpp:57
virtual ~PETScKrylovSolver()
Destructor.
Definition: PETScKrylovSolver.cpp:39
KSP ksp() const
Return PETSc KSP pointer.
Definition: PETScKrylovSolver.cpp:204
std::string get_options_prefix() const
Returns the prefix used by PETSc when searching the PETSc options database.
Definition: PETScKrylovSolver.cpp:186
void set_from_options() const
Set options from PETSc options database.
Definition: PETScKrylovSolver.cpp:196
PETScKrylovSolver(MPI_Comm comm)
Create Krylov solver for a particular method and named preconditioner.
Definition: PETScKrylovSolver.cpp:18
void set_dm_active(bool val)
Activate/deactivate DM.
Definition: PETScKrylovSolver.cpp:168