BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_SolverSUPERLU.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, through
4 * 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_SOLVERSUPERLU_HPP
13#define BELFEM_CL_SOLVERSUPERLU_HPP
14
15#ifdef BELFEM_SUPERLU
16// <slu_ddefs.h> declares the global extern "C" BLAS prototypes ( dtrsv_,
17// dgemm_, ... ) with signatures that clash with the matrix backend, which
18// declares the same symbols differently ( e.g. Blaze uses blas_int_t and
19// Fortran char-length arguments ). The wrapper never calls BLAS itself and
20// libsuperlu.a links the real symbols, so SuperLU's unused prototypes are
21// renamed for the duration of this include only. The #undef restores the
22// names immediately so the backend's own declarations are untouched.
23#define dcopy_ belfem_slu_dcopy_
24#define daxpy_ belfem_slu_daxpy_
25#define dgemm_ belfem_slu_dgemm_
26#define dgemv_ belfem_slu_dgemv_
27#define dtrsm_ belfem_slu_dtrsm_
28#define dtrsv_ belfem_slu_dtrsv_
29#include <slu_ddefs.h>
30#undef dcopy_
31#undef daxpy_
32#undef dgemm_
33#undef dgemv_
34#undef dtrsm_
35#undef dtrsv_
36#else
37 typedef void SuperMatrix ;
38 typedef void superlu_options_t ;
39 typedef void GlobalLU_t ;
40#endif
41
42
43#include "cl_SolverWrapper.hpp"
44
45namespace belfem
46{
47 namespace solver
48 {
49//------------------------------------------------------------------------------
50
51 class SUPERLU : public Wrapper
52 {
53
54 superlu_options_t * mOptions = nullptr ;
55
56 SuperMatrix * mA = nullptr;
57
58 // column permuted matrix A * Pc ( SLU_NCP ).
59 // sp_preorder() aliases the value array of mA, so in-place value
60 // updates of the SpMatrix propagate automatically. The SpMatrix
61 // must NOT be reassigned or resized between symbolic() and free(),
62 // as that would reallocate the value array and dangle this alias.
63 SuperMatrix * mAC = nullptr ;
64
65 // factors, owned by SuperLU
66 SuperMatrix * mL = nullptr ; // SLU_SC
67 SuperMatrix * mU = nullptr ; // SLU_NC
68
69 // per-call LU workspace for dgstrf. Must be a valid struct for
70 // every call; under plain SamePattern dgstrf reuses perm_c/etree,
71 // not this workspace ( that is SamePattern_SameRowPerm ).
72 GlobalLU_t * mGlu = nullptr;
73
74 // column permutation ( fill reduction ), length n_cols
75 int * mPermC = nullptr ;
76
77 // row permutation ( pivoting ), length n_rows
78 int * mPermR = nullptr ;
79
80 // column elimination tree, length n_cols
81 int * mEtree = nullptr ;
82
83 bool mHaveSymbolic = false ;
84 bool mHaveNumeric = false ;
85
86//------------------------------------------------------------------------------
87 public:
88//------------------------------------------------------------------------------
89
90 SUPERLU() ;
91
92//------------------------------------------------------------------------------
93
94 ~SUPERLU() override ;
95
96//------------------------------------------------------------------------------
97 void
98 solve( SpMatrix & aMatrix,
99 Vector <real> & aLHS,
100 Vector <real> & aRHS ) override ;
101
102//------------------------------------------------------------------------------
103
104 void
105 solve( SpMatrix & aMatrix,
106 Matrix <real> & aLHS,
107 Matrix <real> & aRHS ) override ;
108
109//------------------------------------------------------------------------------
110
111 void
112 free() override ;
113
114//------------------------------------------------------------------------------
115 protected :
116//------------------------------------------------------------------------------
117
118 void
119 initialize( SpMatrix & aMatrix,
120 const SymmetryMode aSymmetryMode = SymmetryMode::Unsymmetric,
121 const int_t aNumRhsColumns = 1 ) override ;
122
123 void
124 symbolic();
125
126 void
127 numeric();
128
129//------------------------------------------------------------------------------
130
131 // tear down the SuperLU factorization only ( no base-class reset );
132 // shared by the public free() and by symbolic() re-entry
133 void
135
136//------------------------------------------------------------------------------
137
138 void
139 solve( Vector< real > & aLHS,
140 Vector< real > & aRHS ) ;
141
142//------------------------------------------------------------------------------
143
144 void
145 solve( Matrix< real > & aLHS,
146 Matrix< real > & aRHS ) ;
147
148//------------------------------------------------------------------------------
149 };
150 }
151}
152
153#endif //BELFEM_CL_SOLVERSUPERLU_HPP
void SuperMatrix
Definition cl_SolverSUPERLU.hpp:37
void GlobalLU_t
Definition cl_SolverSUPERLU.hpp:39
void superlu_options_t
Definition cl_SolverSUPERLU.hpp:38
Sparse matrix in CSR or CSC format.
Definition cl_SpMatrix.hpp:52
void free_factorization()
Definition cl_SolverSUPERLU.cpp:273
void solve(SpMatrix &aMatrix, Vector< real > &aLHS, Vector< real > &aRHS) override
Definition cl_SolverSUPERLU.cpp:46
void symbolic()
Definition cl_SolverSUPERLU.cpp:110
void free() override
Definition cl_SolverSUPERLU.cpp:261
SUPERLU()
Definition cl_SolverSUPERLU.cpp:28
void initialize(SpMatrix &aMatrix, const SymmetryMode aSymmetryMode=SymmetryMode::Unsymmetric, const int_t aNumRhsColumns=1) override
Definition cl_SolverSUPERLU.cpp:72
void numeric()
Definition cl_SolverSUPERLU.cpp:191
Wrapper(const string &aLabel, const bool aUsesMPI)
Definition cl_SolverWrapper.cpp:44
USER GUIDES:
Definition cl_Capacitor.cpp:16
SymmetryMode
Definition en_SolverEnums.hpp:36
@ Unsymmetric
Definition en_SolverEnums.hpp:37
int32_t int_t
Definition typedefs.hpp:51