PolyDiM
C++ library for POLYtopal DIscretization Methods
Loading...
Searching...
No Matches
PETSc_KSPSolver.hpp
Go to the documentation of this file.
1// _LICENSE_HEADER_
2//
3// Copyright (C) 2019 - 2025.
4// Terms register on the GPL-3.0 license.
5//
6// This file can be redistributed and/or modified under the license terms.
7//
8// See top level LICENSE file for more details.
9//
10// This file can be used citing references in CITATION.cff file.
11
12#ifndef __PETSCKSPSOLVER_H
13#define __PETSCKSPSOLVER_H
14
15#include "Gedim_Macro.hpp"
16
17#if ENABLE_PETSC == 1
18
19#include "petscksp.h"
20#include "petscmat.h"
21#include "petscvec.h"
22
23#include "ILinearSolver.hpp"
24
25namespace Gedim
26{
27enum struct PETSc_SolverTypes
28{
29 PETSc_KSPCG = 0,
30 PETSc_KSPBICG = 1,
31 PETSc_KSPGMRES = 2,
32 PETSc_KSPBICGS = 3
33};
34
35enum struct PETSc_Preconditioners
36{
37 PETSc_DEFAULT = -1,
38 PETSc_PCNONE = 0,
39 PETSc_PCILU = 1,
40 PETSc_PCJACOBI = 2,
41 PETSc_PCFIELDSPLIT = 3
42};
43
45template <typename PETSc_ArrayType = Vec, typename PETSc_SparseArrayType = Mat, PETSc_SolverTypes PETSc_SolverType = PETSc_SolverTypes::PETSc_KSPGMRES, PETSc_Preconditioners PETSc_Preconditioner = PETSc_Preconditioners::PETSc_DEFAULT>
46class PETSc_KSPSolver final : public ILinearSolver
47{
48 private:
50 KSP linearSolver;
51 const IArray *_rightHandSide;
52 IArray *_solution;
53 Configuration _config;
54
55 public:
58
59 void Initialize(const ISparseArray &matrix, const IArray &rightHandSide, IArray &solution, const Configuration &config = {100, 1e-6});
60
61 ILinearSolver::SolutionInfo Solve() const;
62
63 void Initialize(const ISparseArray &matrix, const Configuration &config = {100, 1e-6});
64 ILinearSolver::SolutionInfo Solve(const IArray &rightHandSide, IArray &solution) const;
65};
66} // namespace Gedim
67
68#endif // ENABLE_PETSC
69
70#endif // __PETScPCGSOLVER_H
Eigen_Array()
Definition Eigen_Array.hpp:28
Definition Eigen_Array.cpp:22