BELFEM 0.9.3
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Solver.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_SOLVER_HPP
13#define BELFEM_CL_SOLVER_HPP
14#include "typedefs.hpp"
15#include "cl_Vector.hpp"
16#include "cl_Matrix.hpp"
18#include "cl_SpMatrix.hpp"
19
20#include "en_SolverEnums.hpp"
21#include "cl_SolverWrapper.hpp"
22
23namespace belfem
24{
25//------------------------------------------------------------------------------
26
33 class Solver
34 {
35 // the type of the chosen solver
36 const SolverType mType ;
37
38 SolverParameters mParams ;
39
40 // symmetry mode
42
43 solver::Wrapper * mWrapper ;
44
45//------------------------------------------------------------------------------
46 public :
47//------------------------------------------------------------------------------
48
53 Solver( const SolverType aSolverType = gDefaultSolver ) ;
54
55 Solver( const SolverParameters aParams ) ;
56
57//------------------------------------------------------------------------------
58
59 ~Solver() ;
60
61 // NON-COPYABLE, NON-MOVABLE. This class owns the raw pointer
62 // mWrapper and deletes it in its destructor, so the implicit copy
63 // would be a shallow pointer copy and the second destructor a
64 // double free. Copy assignment was already implicitly deleted by
65 // the const mType member, and the user-declared destructor
66 // suppressed the implicit moves -- which is why a move request
67 // used to bind to the implicit COPY constructor, the same hazard
68 // under another name. Nothing copies a Solver, which is exactly
69 // why this was latent rather than loud.
70 //
71 // Same shape and same remedy as EigenValues
72 // ( cl_FEM_DofMgr_EigenValues.hpp ). NOT the SpMatrix pattern:
73 // that one deletes the constructors but keeps assignment on
74 // purpose, because an empty SpMatrix is a usable target
75 Solver( const Solver & ) = delete ;
76 Solver( Solver && ) = delete ;
77 Solver & operator=( const Solver & ) = delete ;
78 Solver & operator=( Solver && ) = delete ;
79
80//------------------------------------------------------------------------------
81
83 type() const ;
84
85//------------------------------------------------------------------------------
86
92 const SolverParameters &
93 parameters() const ;
94
95//------------------------------------------------------------------------------
96
101 void
102 set_symmetry_mode( const SymmetryMode & aMode ) ;
103
104//------------------------------------------------------------------------------
105
115 void
116 solve( SpMatrix & aMatrix,
117 Vector< real > & aLHS,
118 Vector< real > & aRHS );
119
120//------------------------------------------------------------------------------
121
128 void
129 solve( SpMatrix & aMatrix,
130 Matrix< real > & aLHS,
131 Matrix< real > & aRHS );
132
133//------------------------------------------------------------------------------
134
142 void
143 set_petsc(
144 const Preconditioner aPreconditioner,
145 const KrylovMethod aKrylovMethod,
146 const real aEpsilon = 1e-8 );
147
148//------------------------------------------------------------------------------
149
154 void
156 const MumpsSerialReodrdering aSerial,
157 const MumpsParallelReodrdering aParallel );
158
159 void
161 const MumpsBlockLowRanking aBlr,
162 const real aEpsilon );
163
164 void
166 const MumpsErrorAnalysis aSetting );
167
168//------------------------------------------------------------------------------
169
170
171//------------------------------------------------------------------------------
172
177 void
178 free() ;
179
180//------------------------------------------------------------------------------
181
187 wrapper() ;
188
189//------------------------------------------------------------------------------
190 private:
191//------------------------------------------------------------------------------
192
193 void
194 create_wrapper();
195
196//------------------------------------------------------------------------------
197 };
198
199//------------------------------------------------------------------------------
200
201 inline solver::Wrapper *
203 {
204 return mWrapper ;
205 }
206
207//------------------------------------------------------------------------------
208}
209#endif //BELFEM_CL_SOLVER_HPP
Solver(Solver &&)=delete
void set_mumps_reordering(const MumpsSerialReodrdering aSerial, const MumpsParallelReodrdering aParallel)
Silently ignored unless the solver is MUMPS.
Definition cl_Solver.cpp:257
void set_symmetry_mode(const SymmetryMode &aMode)
symmetry mode, needed for some solvers
Definition cl_Solver.cpp:164
const SolverParameters & parameters() const
read-only view of the parameters this solver was built with ( e.g.
Definition cl_Solver.cpp:156
Solver(const SolverType aSolverType=gDefaultSolver)
Collective: the constructor synchronizes the solver settings ( not the solver type ) from rank 0 to e...
Definition cl_Solver.cpp:29
void solve(SpMatrix &aMatrix, Vector< real > &aLHS, Vector< real > &aRHS)
Solves A x = b.
Definition cl_Solver.cpp:172
Solver & operator=(const Solver &)=delete
Solver & operator=(Solver &&)=delete
void set_mumps_error_analysis(const MumpsErrorAnalysis aSetting)
Definition cl_Solver.cpp:303
void free()
Releases the factorization ( the destructor does it too ); the next solve() re-initializes from scrat...
Definition cl_Solver.cpp:229
void set_mumps_blr(const MumpsBlockLowRanking aBlr, const real aEpsilon)
Definition cl_Solver.cpp:275
solver::Wrapper * wrapper()
Borrowed: the Solver owns and deletes the wrapper; do not keep it past the Solver's lifetime.
Definition cl_Solver.hpp:202
void set_petsc(const Preconditioner aPreconditioner, const KrylovMethod aKrylovMethod, const real aEpsilon=1e-8)
this does only do something if PETSc is used
Definition cl_Solver.cpp:237
Solver(const Solver &)=delete
SolverType type() const
Definition cl_Solver.cpp:148
Configuration for a Solver.
Definition cl_SolverParameters.hpp:27
Sparse matrix in CSR or CSC format.
Definition cl_SpMatrix.hpp:52
parent class for solver specific data
Definition cl_SolverWrapper.hpp:31
USER GUIDES:
Definition cl_Capacitor.cpp:16
MumpsSerialReodrdering
MUMPS only.
Definition en_SolverEnums.hpp:142
MumpsErrorAnalysis
MUMPS only.
Definition en_SolverEnums.hpp:187
const SolverType gDefaultSolver
Definition en_SolverEnums.hpp:209
SolverType
Definition en_SolverEnums.hpp:23
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
MumpsBlockLowRanking
MUMPS only.
Definition en_SolverEnums.hpp:173
MumpsParallelReodrdering
MUMPS only.
Definition en_SolverEnums.hpp:160