FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
adp_solver_base.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
9#include <kernel/solver/base.hpp>
10#include <kernel/global/alg_dof_parti.hpp>
11#include <kernel/global/matrix.hpp>
12#include <kernel/global/filter.hpp>
13#include <kernel/global/vector.hpp>
14#include <kernel/global/pmdcdsc_matrix.hpp>
15
16namespace FEAT
17{
18 namespace Solver
19 {
44 template<typename Matrix_, typename Filter_, typename SolverBase_ = Solver::SolverBase<typename Matrix_::VectorTypeL>>
45#ifndef DOXYGEN
46 class ADPSolverBase;
47#else // DOXYGEN
49 public SolverBase_
50 {
51 protected:
53 explicit ADPSolverBase(const GlobalMatrixType& matrix, const GlobalFilterType& filter);
54
56 const Dist::Comm* _get_comm() const;
57
60
63
66
69
71 const DataType* _get_mat_vals() const;
72
74 const IndexType* _get_mat_row_ptr() const;
75
77 const IndexType* _get_mat_col_idx() const;
78
80 const DataType* _get_vec_def_vals(const VectorType& vec_def);
81
83 DataType* _get_vec_def_vals(VectorType& vec_def);
84
86 DataType* _get_vec_cor_vals(VectorType& vec_cor);
87
89 void _upload_vec_def(const VectorType& vec_def);
90
92 void _upload_vec_cor(const VectorType& vec_cor);
93
96
99 }; // class ADPSolverBase
100#endif // DOXYGEN
101
116 template<typename LocalMatrix_, typename Mirror_, typename GlobalFilter_, typename SolverBase_>
117 class ADPSolverBase<Global::Matrix<LocalMatrix_, Mirror_, Mirror_>, GlobalFilter_, SolverBase_> :
118 //public SolverBase<Global::Vector<typename LocalMatrix_::VectorTypeL, Mirror_>>
119 public SolverBase_
120 {
121 public:
122 typedef LocalMatrix_ LocalMatrixType;
123 typedef typename LocalMatrixType::VectorTypeL LocalVectorType;
124 typedef Mirror_ MirrorType;
125
128 typedef GlobalFilter_ GlobalFilterType;
129
130 //typedef SolverBase<GlobalVectorType> BaseClass;
131 typedef SolverBase_ BaseClass;
132
134
138
139 typedef typename AlgDofPartiType::DataType DataType;
140 typedef typename AlgDofPartiType::IndexType IndexType;
141
142 private:
149
150 protected:
154 const GlobalFilterType& _system_filter;
155
156 explicit ADPSolverBase(const GlobalMatrixType& matrix, const GlobalFilterType& filter) :
157 BaseClass(),
158 _alg_dof_parti(),
159 _adp_matrix(),
160 _adp_vec_def(),
161 _adp_vec_cor(),
162 _system_matrix(matrix),
163 _system_filter(filter)
164 {
165 }
166
167 public:
169 const Dist::Comm* _get_comm() const
170 {
171 return this->_system_matrix.get_comm();
172 }
173
180 virtual void init_symbolic() override
181 {
182 BaseClass::init_symbolic();
183
184 // assemble the algebraic dof partitioning
185 _alg_dof_parti.assemble_by_gate(*this->_system_matrix.get_row_gate());
186
187 // upload the matrix structure
188 _adp_matrix = ADPMatrixType(&this->_alg_dof_parti);
189 _adp_matrix.upload_symbolic(this->_system_matrix);
190
191 // create two vectors
192 _adp_vec_def = ADPVectorType(&this->_alg_dof_parti);
193 _adp_vec_cor = ADPVectorType(&this->_alg_dof_parti);
194
195 // format matrix and vectors
196 _adp_matrix.owned().format();
197 _adp_vec_def.owned().format();
198 _adp_vec_cor.owned().format();
199 }
200
207 virtual void init_numeric() override
208 {
209 BaseClass::init_numeric();
210
211 // upload matrix values
212 _adp_matrix.upload_numeric(this->_system_matrix);
213
214 // filter matrix
215 _adp_matrix.filter_matrix(this->_system_filter);
216 }
217
218 virtual void done_symbolic() override
219 {
220 _adp_vec_cor.clear();
221 _adp_vec_def.clear();
222 _adp_matrix.clear();
223 _alg_dof_parti.clear();
224
225 BaseClass::done_symbolic();
226 }
227
228 protected:
230 {
231 return this->_alg_dof_parti.get_num_owned_dofs();
232 }
233
235 {
236 return this->_alg_dof_parti.get_num_global_dofs();
237 }
238
240 {
241 return this->_alg_dof_parti.get_global_dof_offset();
242 }
243
244 Index _get_mat_num_nze() const
245 {
246 return this->_adp_matrix.owned().used_elements();
247 }
248
249 const DataType* _get_mat_vals() const
250 {
251 return this->_adp_matrix.owned().val();
252 }
253
254 const IndexType* _get_mat_row_ptr() const
255 {
256 return this->_adp_matrix.owned().row_ptr();
257 }
258
259 const IndexType* _get_mat_col_idx() const
260 {
261 return this->_adp_matrix.owned().col_ind();
262 }
263
264 const DataType* _get_vec_def_vals(const VectorType&)
265 {
266 return this->_adp_vec_def.owned().elements();
267 }
268
269 DataType* _get_vec_def_vals(VectorType&)
270 {
271 return this->_adp_vec_def.owned().elements();
272 }
273
274 DataType* _get_vec_cor_vals(VectorType&)
275 {
276 return this->_adp_vec_cor.owned().elements();
277 }
278
279 void _upload_vec_def(const VectorType& vec_def)
280 {
281 this->_adp_vec_def.upload(vec_def);
282 }
283
284 void _upload_vec_cor(const VectorType& vec_cor)
285 {
286 this->_adp_vec_cor.upload(vec_cor);
287 }
288
289 void _download_vec_def(VectorType& vec_def)
290 {
291 this->_adp_vec_def.download(vec_def);
292 }
293
294 void _download_vec_cor(VectorType& vec_cor)
295 {
296 this->_adp_vec_cor.download(vec_cor);
297 }
298 }; // class ADPSolverBase<Global::Matrix<...>, ...>
299
300
315 template<typename MatrixB_, typename MatrixD_, typename GlobalFilter_, typename SolverBase_>
316 class ADPSolverBase<Global::PMDCDSCMatrix<MatrixB_, MatrixD_>, GlobalFilter_, SolverBase_> :
317 //public SolverBase<typename Global::PMDCDSCMatrix<MatrixB_, MatrixD_>::VectorTypeL>
318 public SolverBase_
319 {
320 public:
322 typedef GlobalFilter_ GlobalFilterType;
323
324 typedef typename GlobalMatrixType::LocalMatrixTypeS LocalMatrixTypeS;
325
326 typedef typename GlobalMatrixType::VectorTypeL GlobalVectorType;
327
328 //typedef SolverBase<GlobalVectorType> BaseClass;
329 typedef SolverBase_ BaseClass;
330
331 typedef GlobalVectorType VectorType;
332
333 typedef typename LocalMatrixTypeS::DataType DataType;
334 typedef typename LocalMatrixTypeS::IndexType IndexType;
335
336 private:
339 // the total global DOF count
340 Index _glob_dof_count;
342 LocalMatrixTypeS _matrix_slice;
343
344 protected:
348 const GlobalFilterType& _system_filter;
349
350 explicit ADPSolverBase(const GlobalMatrixType& matrix, const GlobalFilterType& filter) :
351 BaseClass(),
352 _glob_dof_offset(0),
353 _glob_dof_count(0),
354 _system_matrix(matrix),
355 _system_filter(filter)
356 {
357 }
358
359 public:
361 const Dist::Comm* _get_comm() const
362 {
363 return this->_system_matrix.get_comm();
364 }
365
366 virtual void init_symbolic() override
367 {
368 BaseClass::init_symbolic();
369
370 // assemble matrix slice structure
371 _matrix_slice = _system_matrix.asm_adp_symbolic(_glob_dof_offset, _glob_dof_count);
372 }
373
374 virtual void init_numeric() override
375 {
376 BaseClass::init_numeric();
377
378 // upload matrix values
379 _system_matrix.asm_adp_numeric(_matrix_slice);
380
381 // filter matrix
382 this->_system_filter.local().filter_mat(_matrix_slice);
383 }
384
385 virtual void done_symbolic() override
386 {
387 _matrix_slice.clear();
388 BaseClass::done_symbolic();
389 }
390
391 protected:
392
394 {
395 return _glob_dof_count;
396 }
397
399 {
400 return _glob_dof_offset;
401 }
402
404 {
405 return _matrix_slice.rows();
406 }
407
408 Index _get_mat_num_nze() const
409 {
410 return _matrix_slice.used_elements();
411 }
412
413 const DataType* _get_mat_vals() const
414 {
415 return _matrix_slice.val();
416 }
417
418 const IndexType* _get_mat_row_ptr() const
419 {
420 return _matrix_slice.row_ptr();
421 }
422
423 const IndexType* _get_mat_col_idx() const
424 {
425 return _matrix_slice.col_ind();
426 }
427
428 const DataType* _get_vec_def_vals(const VectorType& vec_def)
429 {
430 return vec_def.local().elements();
431 }
432
433 DataType* _get_vec_def_vals(VectorType& vec_def)
434 {
435 return vec_def.local().elements();
436 }
437
438 DataType* _get_vec_cor_vals(VectorType& vec_cor)
439 {
440 return vec_cor.local().elements();
441 }
442
443 void _upload_vec_def(const VectorType&)
444 {
445 // nothing to do here
446 }
447
448 void _upload_vec_cor(const VectorType&)
449 {
450 // nothing to do here
451 }
452
454 {
455 // nothing to do here
456 }
457
459 {
460 // nothing to do here
461 }
462 }; // class ADPSolverBase<Global::PMDCDSCMatrix<...>, ...>
463 } // namespace Solver
464} // namespace FEAT
Communicator class.
Definition: dist.hpp:1349
Algebraic DOF Partitioning implementation class template.
Algebraic DOF Partitioned CSR matrix class template.
void upload_symbolic(const GlobalMatrixType &mat_a)
Initializes this algebraic dof-partitioned matrix from a global matrix.
void upload_numeric(const GlobalMatrixType &mat_a)
Copies the matrix entry values from the input matrix into this algebraic-dof-partitioned matrix.
void filter_matrix(const Global::Filter< LocalFilter_, MirrorType > &filter)
Applies a global unit-filter into this matrix.
void clear()
Resets the whole object.
Algebraic DOF Partitioned Vector class template.
void upload(const GlobalVectorType &global_vector)
Copies the DOF values from a global vector to this algebraic-dof-partitioned vector.
void download(GlobalVectorType &global_vector) const
Copies the DOF values from this algebraic-dof-partitioned vector into a global vector.
void clear()
Resets the whole object.
Global Matrix wrapper class template.
Definition: matrix.hpp:40
const GateRowType * get_row_gate() const
Returns a const pointer to the internal row gate of the matrix.
Definition: matrix.hpp:154
const Dist::Comm * get_comm() const
Returns a const pointer to the internal communicator of the gates of the matrix.
Definition: matrix.hpp:174
Pre-Multiplied Discontinuous Diagonal Schur-Complement Matrix.
Global vector wrapper class template.
Definition: vector.hpp:68
void format(DT_ value=DT_(0))
Reset all elements of the container to a given value or zero if missing.
Definition: container.hpp:851
DT_ * elements()
Get a pointer to the data array.
IT_ * col_ind()
Retrieve column indices array.
DT_ * val()
Retrieve non zero element array.
Index used_elements() const
Retrieve non zero element count.
IT_ * row_ptr()
Retrieve row start index array.
Base-Class for Solvers based on Algebraic-DOF-Partitioning.
const Dist::Comm * _get_comm() const
const DataType * _get_mat_vals() const
Index _get_mat_num_nze() const
const IndexType * _get_mat_col_idx() const
ADPSolverBase(const GlobalMatrixType &matrix, const GlobalFilterType &filter)
constructor
DataType * _get_vec_cor_vals(VectorType &vec_cor)
DataType * _get_vec_def_vals(VectorType &vec_def)
Index _get_num_owned_dofs() const
void _download_vec_def(VectorType &vec_def)
Index _get_global_dof_offset() const
const DataType * _get_vec_def_vals(const VectorType &vec_def)
void _download_vec_cor(VectorType &vec_cor)
const IndexType * _get_mat_row_ptr() const
Index _get_num_global_dofs() const
void _upload_vec_def(const VectorType &vec_def)
void _upload_vec_cor(const VectorType &vec_cor)
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
Vector_ VectorType
The type of vector this solver can be applied to.
Definition: base.hpp:186
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.