BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_SolverPETSC.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_SOLVERPETSC_HPP
13#define BELFEM_CL_SOLVERPETSC_HPP
14
15#include "petsctools.hpp"
16#include "cl_SolverWrapper.hpp"
19
20namespace belfem
21{
22
23 namespace solver
24 {
25 class PETSC : public Wrapper
26 {
27 const SolverParameters * mParams ;
28
29 // selected preconditioner
30 Preconditioner mPreconditioner =mParams->preconditioner() ;
31
32 // selected krylov method
33 KrylovMethod mKrylovMethod = mParams->krylov_method() ;
34
35 // relative tolerance for iterative solver
36 real mEpsilon = mParams->relative_tolerance() ;
37
38#ifdef BELFEM_PETSC
39 // number of colums for RHS and LHS
40 PetscInt mNumCols;
41
42 PetscData mData ;
43
44 sparse::PETScAIJ * mDistMatrix = nullptr ;
45
46#endif
47//------------------------------------------------------------------------------
48 public:
49//------------------------------------------------------------------------------
50
51 PETSC( const SolverParameters * aParams );
52
53//------------------------------------------------------------------------------
54
55 ~PETSC() override;
56
57//------------------------------------------------------------------------------
58
59 void
60 set(
61 const Preconditioner aPreconditioner,
62 const KrylovMethod aKrylovMethod,
63 const real aEpsilon = 1e-8 );
64
65//------------------------------------------------------------------------------
66
67 void
68 solve(
69 SpMatrix & aMatrix,
70 Vector <real> & aLHS,
71 Vector <real> & aRHS ) override ;
72
73//------------------------------------------------------------------------------
74
75 void
76 free() override ;
77
78//------------------------------------------------------------------------------
79 protected :
80//------------------------------------------------------------------------------
81
82 void
84 SpMatrix & aMatrix,
85 const SymmetryMode aSymmetryMode = SymmetryMode::Unsymmetric,
86 const int_t aNumRhsColumns = 1 ) override ;
87
88
89//------------------------------------------------------------------------------
90 private :
91//------------------------------------------------------------------------------
92
93 /*
94 * populates the index vector
95 */
96 void
97 create_indices( const PetscInt & aLength, const PetscInt aOffset = 0 );
98
99//------------------------------------------------------------------------------
100
104 void
105 create_pc_and_ksp();
106
107//------------------------------------------------------------------------------
108
114 void
115 link_matrix( SpMatrix & aMatrix );
116
117//------------------------------------------------------------------------------
118
120 set_preconditioner( const Preconditioner aPreconditioner );
121
122//------------------------------------------------------------------------------
123
125 set_krylovmethod( const KrylovMethod aKrylovMethod );
126
127//------------------------------------------------------------------------------
128
130 set_initial_guess_flag( const bool aSwitch );
131
132//------------------------------------------------------------------------------
133
135 set_matrix_ordering( const ReorderingMethod aReorderingMethod );
136
137//------------------------------------------------------------------------------
138 };
139
140//------------------------------------------------------------------------------
141 }
142}
143
144#endif //BELFEM_CL_SOLVERPETSC_HPP
Configuration for a Solver.
Definition cl_SolverParameters.hpp:27
Sparse matrix in CSR or CSC format.
Definition cl_SpMatrix.hpp:52
void initialize(SpMatrix &aMatrix, const SymmetryMode aSymmetryMode=SymmetryMode::Unsymmetric, const int_t aNumRhsColumns=1) override
Definition cl_SolverPETSC.cpp:379
void set(const Preconditioner aPreconditioner, const KrylovMethod aKrylovMethod, const real aEpsilon=1e-8)
Definition cl_SolverPETSC.cpp:53
void solve(SpMatrix &aMatrix, Vector< real > &aLHS, Vector< real > &aRHS) override
Definition cl_SolverPETSC.cpp:66
PETSC(const SolverParameters *aParams)
Definition cl_SolverPETSC.cpp:28
void free() override
Definition cl_SolverPETSC.cpp:468
Wrapper(const string &aLabel, const bool aUsesMPI)
Definition cl_SolverWrapper.cpp:44
Definition cl_SolverMUMPS.cpp:26
void PETScAIJ
Definition petsctools.hpp:56
USER GUIDES:
Definition cl_Capacitor.cpp:16
ReorderingMethod
Definition en_SolverEnums.hpp:116
KrylovMethod
PETSC only.
Definition en_SolverEnums.hpp:101
SymmetryMode
Definition en_SolverEnums.hpp:36
@ Unsymmetric
Definition en_SolverEnums.hpp:37
Preconditioner
PETSC only.
Definition en_SolverEnums.hpp:79
double real
Definition typedefs.hpp:36
int32_t int_t
Definition typedefs.hpp:51
int PetscInt
Definition petsctools.hpp:20
int PetscErrorCode
Definition petsctools.hpp:22
this struct contains the variables needed by PETSc
Definition st_SolverPetscData.hpp:28