|
using | ConstVectorViewType = typename Traits< Matrix >::ConstVectorViewType |
| Type for constant vector view.
|
|
using | DeviceType = typename Matrix::DeviceType |
| Device where the solver will run on and auxillary data will alloacted on.
|
|
using | IndexType = typename Matrix::IndexType |
| Type for indexing.
|
|
using | MatrixPointer = std::shared_ptr< std::add_const_t< MatrixType > > |
| Type of shared pointer to the matrix.
|
|
using | MatrixType = Matrix |
| Type of the matrix representing the linear system.
|
|
using | RealType = typename Matrix::RealType |
| Floating point type used for computations.
|
|
using | VectorViewType = typename Traits< Matrix >::VectorViewType |
| Type for vector view.
|
|
template<typename Matrix>
class TNL::Solvers::Linear::Preconditioners::Preconditioner< Matrix >
Base class for preconditioners of of iterative solvers of linear systems.
- Template Parameters
-
Matrix | is type of matrix describing the linear system. |
The following example shows how to setup an iterative solver of linear systems with preconditioning:
3#include <TNL/Matrices/SparseMatrix.h>
4#include <TNL/Devices/Host.h>
5#include <TNL/Devices/Cuda.h>
6#include <TNL/Solvers/Linear/TFQMR.h>
7#include <TNL/Solvers/Linear/Preconditioners/Diagonal.h>
9template<
typename Device >
11iterativeLinearSolverExample()
26 matrix_ptr->setDimensions( size, size );
27 matrix_ptr->setRowCapacities( Vector( { 2, 3, 3, 3, 2 } ) );
31 const int rowIdx = row.getRowIndex();
33 row.setElement( 0, rowIdx, 2.5 );
34 row.setElement( 1, rowIdx + 1, -1 );
36 else if( rowIdx == size - 1 ) {
37 row.setElement( 0, rowIdx - 1, -1.0 );
38 row.setElement( 1, rowIdx, 2.5 );
41 row.setElement( 0, rowIdx - 1, -1.0 );
42 row.setElement( 1, rowIdx, 2.5 );
43 row.setElement( 2, rowIdx + 1, -1.0 );
50 matrix_ptr->forAllRows( f );
56 Vector x( size, 1.0 );
58 matrix_ptr->vectorProduct( x, b );
68 preconditioner_ptr->update( matrix_ptr );
70 solver.setMatrix( matrix_ptr );
71 solver.setPreconditioner( preconditioner_ptr );
72 solver.setConvergenceResidue( 1.0e-6 );
78main(
int argc,
char* argv[] )
81 iterativeLinearSolverExample< TNL::Devices::Sequential >();
85 iterativeLinearSolverExample< TNL::Devices::Cuda >();
#define __cuda_callable__
Definition Macros.h:49
Vector extends Array with algebraic operations.
Definition Vector.h:36
Implementation of sparse matrix, i.e. matrix storing only non-zero elements.
Definition SparseMatrix.h:57
Diagonal (Jacobi) preconditioner for iterative solvers of linear systems.
Definition Diagonal.h:21
Matrix MatrixType
Type of the matrix representing the linear system.
Definition Preconditioner.h:62
Iterative solver of linear systems based on the Transpose-free quasi-minimal residual (TFQMR) method.
Definition TFQMR.h:21
The result looks as follows:
Solving linear system on host:
Row: 0 -> 0:2.5 1:-1
Row: 1 -> 0:-1 1:2.5 2:-1
Row: 2 -> 1:-1 2:2.5 3:-1
Row: 3 -> 2:-1 3:2.5 4:-1
Row: 4 -> 3:-1 4:2.5
Vector b = [ 1.5, 0.5, 0.5, 0.5, 1.5 ]
Vector x = [ 1, 1, 1, 1, 1 ]
Solving linear system on CUDA device:
Row: 0 -> 0:2.5 1:-1
Row: 1 -> 0:-1 1:2.5 2:-1
Row: 2 -> 1:-1 2:2.5 3:-1
Row: 3 -> 2:-1 3:2.5 4:-1
Row: 4 -> 3:-1 4:2.5
Vector b = [ 1.5, 0.5, 0.5, 0.5, 1.5 ]
Vector x = [ 1, 1, 1, 1, 1 ]