BELFEM 0.9.3
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
52 PETSC( const SolverParameters * aParams );
53
54//------------------------------------------------------------------------------
55
56 ~PETSC() override;
57
58//------------------------------------------------------------------------------
59
60 void
61 set(
62 const Preconditioner aPreconditioner,
63 const KrylovMethod aKrylovMethod,
64 const real aEpsilon = 1e-8 );
65
66//------------------------------------------------------------------------------
67
72 void
73 solve(
74 SpMatrix & aMatrix,
75 Vector <real> & aLHS,
76 Vector <real> & aRHS ) override ;
77
78//------------------------------------------------------------------------------
79
80 void
81 free() override ;
82
83//------------------------------------------------------------------------------
84 protected :
85//------------------------------------------------------------------------------
86
87 void
89 SpMatrix & aMatrix,
90 const SymmetryMode aSymmetryMode = SymmetryMode::Unsymmetric,
91 const int_t aNumRhsColumns = 1 ) override ;
92
93
94//------------------------------------------------------------------------------
95 private :
96//------------------------------------------------------------------------------
97
98 /*
99 * populates the index vector
100 */
101 void
102 create_indices( const PetscInt & aLength, const PetscInt aOffset = 0 );
103
104//------------------------------------------------------------------------------
105
109 void
110 create_pc_and_ksp();
111
112//------------------------------------------------------------------------------
113
119 void
120 link_matrix( SpMatrix & aMatrix );
121
122//------------------------------------------------------------------------------
123
125 set_preconditioner( const Preconditioner aPreconditioner );
126
127//------------------------------------------------------------------------------
128
130 set_krylovmethod( const KrylovMethod aKrylovMethod );
131
132//------------------------------------------------------------------------------
133
135 set_initial_guess_flag( const bool aSwitch );
136
137//------------------------------------------------------------------------------
138
140 set_matrix_ordering( const ReorderingMethod aReorderingMethod );
141
142//------------------------------------------------------------------------------
143 };
144
145//------------------------------------------------------------------------------
146 }
147}
148
149#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:371
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
Collective.
Definition cl_SolverPETSC.cpp:66
PETSC(const SolverParameters *aParams)
aParams is borrowed and must outlive the wrapper.
Definition cl_SolverPETSC.cpp:28
void free() override
Definition cl_SolverPETSC.cpp:454
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