BELFEM 0.9.0
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
55 bool mSoftFail = false ;
56 bool mFailed = false ;
57
58 protected:
59
61 bool
62 soft_fail() const
63 {
64 return mSoftFail ;
65 }
66
67 void
69 {
70 mFailed = true ;
71 }
72
73 SpMatrix * mMatrix = nullptr ;
74 Vector< real > * mX = nullptr ;
75 Vector< real > * mY = nullptr ;
76
77//------------------------------------------------------------------------------
78 public:
79//------------------------------------------------------------------------------
80
81 Wrapper( const string & aLabel, const bool aUsesMPI );
82
83//------------------------------------------------------------------------------
84
85 virtual ~Wrapper();
86
87//------------------------------------------------------------------------------
88
93 const string &
94 label() const ;
95
96//------------------------------------------------------------------------------
97
101 void
102 set_soft_fail( const bool aFlag )
103 {
104 mSoftFail = aFlag ;
105 }
106
110 bool
111 failed() const
112 {
113 return mFailed ;
114 }
115
119 void
121 {
122 mFailed = false ;
123 }
124
125//------------------------------------------------------------------------------
126
127 virtual void
128 solve( SpMatrix & aMatrix,
129 Vector <real> & aLHS,
130 Vector <real> & aRHS );
131
132//------------------------------------------------------------------------------
133
134 virtual void
135 solve( SpMatrix & aMatrix,
136 Matrix <real> & aLHS,
137 Matrix <real> & aRHS );
138
139//------------------------------------------------------------------------------
140
144 bool
145 is_initialized() const ;
146
147//------------------------------------------------------------------------------
148
152 proc_t
153 rank() const ;
154
155//------------------------------------------------------------------------------
156
160 proc_t
161 comm_size() const ;
162
163//------------------------------------------------------------------------------
164
165 bool
166 uses_mpi() const ;
167
168//------------------------------------------------------------------------------
169
170 virtual void
172 SpMatrix & aMatrix,
173 // UNSYMMETRIC, and it must stay identical to the MUMPS override's
174 // default: default arguments bind STATICALLY, so a base/derived
175 // mismatch would silently change the mode with the static type
176 // of the pointer the call goes through
177 const SymmetryMode aSymmetryMode = SymmetryMode::Unsymmetric,
178 const int_t aNumRhsColumns = 1 );
179
180//------------------------------------------------------------------------------
181
182 void
183 free() override;
184
185//------------------------------------------------------------------------------
186
191 virtual real
192 get_determinant() const ;
193
194//------------------------------------------------------------------------------
195
200 virtual real
201 get_cond1() const ;
202
203//------------------------------------------------------------------------------
204
209 virtual real
210 get_cond2() const ;
211
212//------------------------------------------------------------------------------
213
224 virtual real
225 get_forward_error() const ;
226
227//------------------------------------------------------------------------------
228
236 virtual real
237 get_backward_error() const ;
238
239//------------------------------------------------------------------------------
240
250 virtual real
251 get_omega2() const ;
252
253//------------------------------------------------------------------------------
254
260 virtual bool
262
263//------------------------------------------------------------------------------
264
300 virtual void
301 freeze_factorization( const SpMatrix & aMatrix );
302
303//------------------------------------------------------------------------------
304
310 virtual void
312
313//------------------------------------------------------------------------------
314
318 virtual bool
320
321//------------------------------------------------------------------------------
322 protected:
323//------------------------------------------------------------------------------
324
325 virtual void
326 initialize();
327
328//------------------------------------------------------------------------------
329
364 void
365 hatch_turtle();
366
367//------------------------------------------------------------------------------
368
369 void
370 mat2vec( const Matrix< real > & aM,
371 Vector< real > & aV );
372
373//------------------------------------------------------------------------------
374
375 void
376 vec2mat( const Vector< real > & aV,
377 Matrix< real > & aM );
378
379
380//------------------------------------------------------------------------------
381
382 SpMatrix *
383 matrix() ;
384
386 x() ;
387
389 y() ;
390
391//------------------------------------------------------------------------------
392 };
393
394//------------------------------------------------------------------------------
395
396 inline bool
398 {
399 return mIsInitialized ;
400 }
401
402//------------------------------------------------------------------------------
403
404 inline proc_t
406 {
407 return mCommRank ;
408 }
409
410//------------------------------------------------------------------------------
411
412 inline proc_t
414 {
415 return mCommSize ;
416 }
417
418//------------------------------------------------------------------------------
419
420 inline bool Wrapper::uses_mpi() const
421 {
422 return mUsesMPI ;
423 }
424
425//------------------------------------------------------------------------------
426
427 inline SpMatrix *
429 {
430 return mMatrix ;
431 }
432
433//------------------------------------------------------------------------------
434
435 inline Vector< real > &
437 {
438 return *mX ;
439 }
440
441//------------------------------------------------------------------------------
442
443 inline Vector< real > &
445 {
446 return *mY ;
447 }
448
449//------------------------------------------------------------------------------
450 }
451}
452
453#endif //BELFEM_CL_SOLVERWRAPPER_HPP
CommunicationObject()
Definition cl_Communicator.cpp:373
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
returns the name of the solver as string
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 the last factorization/solve failed softly
Definition cl_SolverWrapper.hpp:111
void mat2vec(const Matrix< real > &aM, Vector< real > &aV)
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:102
Vector< real > & x()
Definition cl_SolverWrapper.hpp:436
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
Vector< real > & y()
Definition cl_SolverWrapper.hpp:444
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
Vector< real > * mY
Definition cl_SolverWrapper.hpp:75
bool soft_fail() const
subclass hooks for the soft-fail contract
Definition cl_SolverWrapper.hpp:62
SpMatrix * mMatrix
Definition cl_SolverWrapper.hpp:73
bool uses_mpi() const
Definition cl_SolverWrapper.hpp:420
virtual real get_determinant() const
returns the determinant, if supported by the solver and computation was requested
Definition cl_SolverWrapper.cpp:168
virtual real get_cond1() const
returns the conditioning numbner, if supported by the solver and computation was requested
Definition cl_SolverWrapper.cpp:180
void free() override
Definition cl_SolverWrapper.cpp:86
virtual void solve(SpMatrix &aMatrix, Vector< real > &aLHS, Vector< real > &aRHS)
Definition cl_SolverWrapper.cpp:105
proc_t comm_size() const
returns the communication size of this proc
Definition cl_SolverWrapper.hpp:413
proc_t rank() const
returns the communication rank of this proc
Definition cl_SolverWrapper.hpp:405
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:397
Vector< real > * mX
Definition cl_SolverWrapper.hpp:74
void flag_failure()
Definition cl_SolverWrapper.hpp:68
virtual real get_cond2() const
returns the conditioning numbner, if supported by the solver and computation was requested
Definition cl_SolverWrapper.cpp:192
SpMatrix * matrix()
Definition cl_SolverWrapper.hpp:428
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()
Returns the number of processes in the communicator.
Definition commtools.cpp:22