BELFEM 0.9.3
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_SolverWrapper.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_SOLVERWRAPPER_HPP
13#define BELFEM_CL_SOLVERWRAPPER_HPP
14
15#include "typedefs.hpp"
16#include "cl_Vector.hpp"
17#include "cl_Matrix.hpp"
18#include "cl_SpMatrix.hpp"
19#include "en_SolverEnums.hpp"
21#include "cl_Communicator.hpp"
22
23namespace belfem
24{
25 namespace solver
26 {
31 {
32//------------------------------------------------------------------------------
33
34 // rank of this proc
35 const proc_t mCommRank ;
36
37 const proc_t mCommSize ;
38
39 const bool mUsesMPI ;
40
41 // label of this solver type
42 const string mLabel ;
43
44 // flag telling if we have been initialized
45 bool mIsInitialized = false ;
46
57 bool mSoftFail = false ;
58 bool mFailed = false ;
59
60 protected:
61
63 bool
64 soft_fail() const
65 {
66 return mSoftFail ;
67 }
68
69 void
71 {
72 mFailed = true ;
73 }
74
77 SpMatrix * mMatrix = nullptr ;
78
79//------------------------------------------------------------------------------
80 public:
81//------------------------------------------------------------------------------
82
83 Wrapper( const string & aLabel, const bool aUsesMPI );
84
85//------------------------------------------------------------------------------
86
87 virtual ~Wrapper();
88
89//------------------------------------------------------------------------------
90
91 const string &
92 label() const ;
93
94//------------------------------------------------------------------------------
95
99 void
100 set_soft_fail( const bool aFlag )
101 {
102 mSoftFail = aFlag ;
103 }
104
110 bool
111 failed() const
112 {
113 return mFailed ;
114 }
115
119 void
121 {
122 mFailed = false ;
123 }
124
125//------------------------------------------------------------------------------
126
133 virtual void
134 solve( SpMatrix & aMatrix,
135 Vector <real> & aLHS,
136 Vector <real> & aRHS );
137
138//------------------------------------------------------------------------------
139
140 virtual void
141 solve( SpMatrix & aMatrix,
142 Matrix <real> & aLHS,
143 Matrix <real> & aRHS );
144
145//------------------------------------------------------------------------------
146
150 bool
151 is_initialized() const ;
152
153//------------------------------------------------------------------------------
154
158 proc_t
159 rank() const ;
160
161//------------------------------------------------------------------------------
162
166 proc_t
167 comm_size() const ;
168
169//------------------------------------------------------------------------------
170
171 bool
172 uses_mpi() const ;
173
174//------------------------------------------------------------------------------
175
176 virtual void
178 SpMatrix & aMatrix,
179 // UNSYMMETRIC, and it must stay identical to the MUMPS override's
180 // default: default arguments bind STATICALLY, so a base/derived
181 // mismatch would silently change the mode with the static type
182 // of the pointer the call goes through
183 const SymmetryMode aSymmetryMode = SymmetryMode::Unsymmetric,
184 const int_t aNumRhsColumns = 1 );
185
186//------------------------------------------------------------------------------
187
188 void
189 free() override;
190
191//------------------------------------------------------------------------------
192
198 virtual real
199 get_determinant() const ;
200
201//------------------------------------------------------------------------------
202
206 virtual real
207 get_cond1() const ;
208
209//------------------------------------------------------------------------------
210
215 virtual real
216 get_cond2() const ;
217
218//------------------------------------------------------------------------------
219
230 virtual real
231 get_forward_error() const ;
232
233//------------------------------------------------------------------------------
234
242 virtual real
243 get_backward_error() const ;
244
245//------------------------------------------------------------------------------
246
256 virtual real
257 get_omega2() const ;
258
259//------------------------------------------------------------------------------
260
266 virtual bool
268
269//------------------------------------------------------------------------------
270
306 virtual void
307 freeze_factorization( const SpMatrix & aMatrix );
308
309//------------------------------------------------------------------------------
310
316 virtual void
318
319//------------------------------------------------------------------------------
320
324 virtual bool
326
327//------------------------------------------------------------------------------
328 protected:
329//------------------------------------------------------------------------------
330
331 virtual void
332 initialize();
333
334//------------------------------------------------------------------------------
335
368 void
369 hatch_turtle();
370
371//------------------------------------------------------------------------------
372
376 void
377 mat2vec( const Matrix< real > & aM,
378 Vector< real > & aV );
379
380//------------------------------------------------------------------------------
381
382 void
383 vec2mat( const Vector< real > & aV,
384 Matrix< real > & aM );
385
386
387//------------------------------------------------------------------------------
388
390 SpMatrix *
391 matrix() ;
392
393//------------------------------------------------------------------------------
394 };
395
396//------------------------------------------------------------------------------
397
398 inline bool
400 {
401 return mIsInitialized ;
402 }
403
404//------------------------------------------------------------------------------
405
406 inline proc_t
408 {
409 return mCommRank ;
410 }
411
412//------------------------------------------------------------------------------
413
414 inline proc_t
416 {
417 return mCommSize ;
418 }
419
420//------------------------------------------------------------------------------
421
422 inline bool Wrapper::uses_mpi() const
423 {
424 return mUsesMPI ;
425 }
426
427//------------------------------------------------------------------------------
428
429 inline SpMatrix *
431 {
432 return mMatrix ;
433 }
434
435//------------------------------------------------------------------------------
436 }
437}
438
439#endif //BELFEM_CL_SOLVERWRAPPER_HPP
CommunicationObject()
Definition cl_Communicator.cpp:375
Sparse matrix in CSR or CSC format.
Definition cl_SpMatrix.hpp:52
virtual void initialize()
Definition cl_SolverWrapper.cpp:61
virtual void freeze_factorization(const SpMatrix &aMatrix)
arm the frozen state: subsequent solves reuse the factorization that the LAST SUCCESSFUL solve built,...
Definition cl_SolverWrapper.cpp:251
const string & label() const
Definition cl_SolverWrapper.cpp:97
virtual bool supports_factorization_reuse() const
true if this wrapper can solve against an EXISTING factorization rather than rebuilding it.
Definition cl_SolverWrapper.cpp:240
bool failed() const
True if a soft failure was recorded and not cleared since.
Definition cl_SolverWrapper.hpp:111
void mat2vec(const Matrix< real > &aM, Vector< real > &aV)
Flattens in column-major order: column j occupies entries j * n_rows through j * n_rows + n_rows - 1.
Definition cl_SolverWrapper.cpp:127
Wrapper(const string &aLabel, const bool aUsesMPI)
Definition cl_SolverWrapper.cpp:44
virtual void unfreeze_factorization()
drop the frozen state and return to ordinary re-factorizing solves.
Definition cl_SolverWrapper.cpp:266
virtual real get_omega2() const
the SECOND half of that backward error on its own, if supported.
Definition cl_SolverWrapper.cpp:228
void set_soft_fail(const bool aFlag)
arm/disarm the soft-fail contract ( see the member note )
Definition cl_SolverWrapper.hpp:100
void hatch_turtle()
print a warning ( the turtle ) when the MPI ranks sharing a node ask for more OpenMP threads than the...
Definition cl_SolverWrapper.cpp:391
void vec2mat(const Vector< real > &aV, Matrix< real > &aM)
Definition cl_SolverWrapper.cpp:149
void clear_failure()
clear a recorded soft failure before the next solve
Definition cl_SolverWrapper.hpp:120
virtual real get_forward_error() const
estimated FORWARD error of the last solve, || dx || / || x ||, if supported by the solver and computa...
Definition cl_SolverWrapper.cpp:204
virtual real get_backward_error() const
componentwise BACKWARD error of the last solve, if supported by the solver and computation was reques...
Definition cl_SolverWrapper.cpp:216
bool soft_fail() const
subclass hooks for the soft-fail contract
Definition cl_SolverWrapper.hpp:64
SpMatrix * mMatrix
Definition cl_SolverWrapper.hpp:77
bool uses_mpi() const
Definition cl_SolverWrapper.hpp:422
virtual real get_determinant() const
The determinant of the last factorization.
Definition cl_SolverWrapper.cpp:168
virtual real get_cond1() const
The first of the two condition-number estimates, dimensionless.
Definition cl_SolverWrapper.cpp:180
void free() override
Definition cl_SolverWrapper.cpp:86
virtual void solve(SpMatrix &aMatrix, Vector< real > &aLHS, Vector< real > &aRHS)
Contract for implementers, both overloads: the MPI backends' overrides are collective and must not ta...
Definition cl_SolverWrapper.cpp:105
proc_t comm_size() const
returns the communication size of this proc
Definition cl_SolverWrapper.hpp:415
proc_t rank() const
returns the communication rank of this proc
Definition cl_SolverWrapper.hpp:407
virtual bool factorization_is_frozen() const
true while the frozen scope is armed
Definition cl_SolverWrapper.cpp:276
bool is_initialized() const
tells if the initialitzation routine has already been called
Definition cl_SolverWrapper.hpp:399
void flag_failure()
Definition cl_SolverWrapper.hpp:70
virtual real get_cond2() const
The second condition-number estimate, dimensionless.
Definition cl_SolverWrapper.cpp:192
SpMatrix * matrix()
Borrowed pointer to the caller's matrix; never deleted here.
Definition cl_SolverWrapper.hpp:430
Definition cl_SolverMUMPS.cpp:26
USER GUIDES:
Definition cl_Capacitor.cpp:16
int proc_t
Definition commtypes.hpp:29
SymmetryMode
Definition en_SolverEnums.hpp:36
@ Unsymmetric
Definition en_SolverEnums.hpp:37
double real
Definition typedefs.hpp:36
int32_t int_t
Definition typedefs.hpp:51
proc_t comm_size()
Definition commtools.cpp:22