FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
superlu.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
10#include <kernel/solver/adp_solver_base.hpp>
11
12#if defined(FEAT_HAVE_SUPERLU_DIST) || defined(DOXYGEN)
13
14namespace FEAT
15{
16 namespace Solver
17 {
19
24 namespace SuperLU_Aux
25 {
54 void* create_core(const void* comm, Index num_global_dofs, Index dof_offset,
55 Index num_owned_dofs, const unsigned int* row_ptr, const unsigned int* col_idx);
56 void* create_core(const void* comm, Index num_global_dofs, Index dof_offset,
57 Index num_owned_dofs, const unsigned long* row_ptr, const unsigned long* col_idx);
58 void* create_core(const void* comm, Index num_global_dofs, Index dof_offset,
59 Index num_owned_dofs, const unsigned long long* row_ptr, const unsigned long long* col_idx);
60
62 void destroy_core(void* core);
63
65 int init_numeric(void* core, const double* vals);
66
74 int solve(void* core, double* x);
75 } // namespace SuperLU_Aux
77
91 template<typename Matrix_, typename Filter_>
92 class SuperLU :
93 public ADPSolverBase<Matrix_, Filter_>
94 {
95 public:
99 typedef typename Matrix_::VectorTypeL VectorType;
100
101 protected:
103 void* _core;
104
105 public:
109 explicit SuperLU(const Matrix_& matrix, const Filter_& filter) :
110 BaseClass(matrix, filter),
111 _core(nullptr)
112 {
113 }
114
115 virtual String name() const override
116 {
117 return "SuperLU";
118 }
119
120 virtual void init_symbolic() override
121 {
123 XASSERT(this->_core == nullptr);
124
125 // create our core wrapper object
126 this->_core = SuperLU_Aux::create_core(
127#ifdef FEAT_HAVE_MPI
128 &this->_get_comm()->mpi_comm(),
129#else
130 nullptr, // no communicator for non-MPI builds
131#endif
132 this->_get_num_global_dofs(),
134 this->_get_num_owned_dofs(),
135 this->_get_mat_row_ptr(),
136 this->_get_mat_col_idx());
137 }
138
139 virtual void done_symbolic() override
140 {
141 XASSERT(this->_core != nullptr);
142
143 SuperLU_Aux::destroy_core(this->_core);
144 this->_core = nullptr;
145
147 }
148
149 virtual void init_numeric() override
150 {
151 XASSERT(this->_core != nullptr);
153
154 // set the new matrix values
155 const int info = SuperLU_Aux::init_numeric(this->_core, this->_get_mat_vals());
156
157 // info = 0 means success
158 // info < 0 means illegal argument; this should never happen
159 XASSERTM(info >= 0, "SuperLU: illegal argument in init_numeric()");
160 if(0 < info)
161 {
162 // 0 < info < N: zero pivot = singular matrix
163 if(info <= int(this->_get_num_global_dofs()))
164 throw SingularMatrixException("SuperLU: singular matrix");
165 else // info > N: out of memory
166 throw SolverException("SuperLU: out of memory");
167 }
168 }
169
170 virtual Status apply(VectorType& vec_cor, const VectorType& vec_def) override
171 {
172 // upload defect vector into internal correction vector
173 this->_upload_vec_cor(vec_def);
174
175 // solve
176 int info = SuperLU_Aux::solve(this->_core, this->_get_vec_cor_vals(vec_cor));
177
178 // info != 0 means something went wrong, but this should never happen here...
179 XASSERTM(info == 0, "SuperLU: solve returned non-zero info value");
180
181 // download solution into correction vector
182 this->_download_vec_cor(vec_cor);
183
184 // okay
185 return Status::success;
186 }
187 }; // class SuperLU
188
201 template<typename Matrix_, typename Filter_>
202 std::shared_ptr<SuperLU<Matrix_, Filter_>> new_superlu(const Matrix_& matrix, const Filter_& filter)
203 {
204#ifdef FEAT_HAVE_MPI
205 return std::make_shared<SuperLU<Matrix_, Filter_>>(matrix, filter);
206#else
207 XABORT("new_superlu: SuperLU solver is only available in MPI builds")
208#endif
209 }
210 } // namespace Solver
211} // namespace FEAT
212
213#endif // defined(FEAT_HAVE_SUPERLU_DIST) || defined(DOXYGEN)
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Base-Class for Solvers based on Algebraic-DOF-Partitioning.
const Dist::Comm * _get_comm() const
const DataType * _get_mat_vals() const
const IndexType * _get_mat_col_idx() const
DataType * _get_vec_cor_vals(VectorType &vec_cor)
Index _get_num_owned_dofs() const
Index _get_global_dof_offset() const
void _download_vec_cor(VectorType &vec_cor)
const IndexType * _get_mat_row_ptr() const
Index _get_num_global_dofs() const
void _upload_vec_cor(const VectorType &vec_cor)
Singular Matrix exception.
Definition: base.hpp:159
virtual void init_symbolic()
Symbolic initialization method.
Definition: base.hpp:227
virtual void init_numeric()
Numeric initialization method.
Definition: base.hpp:237
virtual void done_symbolic()
Symbolic finalization method.
Definition: base.hpp:255
Base-class for solver generated exceptions.
Definition: base.hpp:127
(distributed) SuperLU direct sparse solver
Definition: superlu.hpp:94
virtual void done_symbolic() override
Symbolic finalization method.
Definition: superlu.hpp:139
virtual String name() const override
Returns a descriptive string.
Definition: superlu.hpp:115
Matrix_::VectorTypeL VectorType
our vector type
Definition: superlu.hpp:99
virtual void init_symbolic() override
Symbolic initialization method.
Definition: superlu.hpp:120
SuperLU(const Matrix_ &matrix, const Filter_ &filter)
Constructor.
Definition: superlu.hpp:109
ADPSolverBase< Matrix_, Filter_ > BaseClass
our base class
Definition: superlu.hpp:97
virtual void init_numeric() override
Numeric initialization method.
Definition: superlu.hpp:149
void * _core
a pointer to our opaque SuperLU core object
Definition: superlu.hpp:103
String class implementation.
Definition: string.hpp:46
Status
Solver status return codes enumeration.
Definition: base.hpp:47
@ success
solving successful (convergence criterion fulfilled)
std::shared_ptr< SuperLU< Matrix_, Filter_ > > new_superlu(const Matrix_ &matrix, const Filter_ &filter)
Creates a new SuperLU solver object.
Definition: superlu.hpp:202
Status solve(SolverBase< Vector_ > &solver, Vector_ &vec_sol, const Vector_ &vec_rhs, const Matrix_ &matrix, const Filter_ &filter)
Solve linear system with initial solution guess.
Definition: base.hpp:347
FEAT namespace.
Definition: adjactor.hpp:12