3 #ifndef DUNE_ISTL_PRECONDITIONERS_HH
4 #define DUNE_ISTL_PRECONDITIONERS_HH
13 #include <dune/common/simd/simd.hh>
14 #include <dune/common/parametertree.hh>
70 template<
class O,
int c = -1>
72 public Preconditioner<typename O::domain_type, typename O::range_type>
91 : inverse_operator_(inverse_operator)
94 DUNE_THROW(InvalidStateException,
"User-supplied solver category does not match that of the given inverse operator");
104 inverse_operator_.apply(v, copy, res);
136 template<
class M,
class X,
class Y,
int l=1>
158 : _A_(A), _n(n), _w(w)
177 :
SeqSSOR(A->getmat(), configuration)
193 SeqSSOR (
const M& A,
const ParameterTree& configuration)
202 virtual void pre ([[maybe_unused]] X& x, [[maybe_unused]] Y& b)
210 virtual void apply (X& v,
const Y& d)
212 for (
int i=0; i<_n; i++) {
223 virtual void post ([[maybe_unused]] X& x)
254 template<
class M,
class X,
class Y,
int l=1>
276 : _A_(A), _n(n), _w(w)
295 :
SeqSOR(A->getmat(), configuration)
311 SeqSOR (
const M& A,
const ParameterTree& configuration)
320 virtual void pre ([[maybe_unused]] X& x, [[maybe_unused]] Y& b)
328 virtual void apply (X& v,
const Y& d)
330 this->
template apply<true>(v,d);
341 template<
bool forward>
345 for (
int i=0; i<_n; i++) {
349 for (
int i=0; i<_n; i++) {
359 virtual void post ([[maybe_unused]] X& x)
389 template<
class M,
class X,
class Y,
int l=1>
403 template<
class M,
class X,
class Y,
int l=1>
425 : _A_(A), _n(n), _w(w)
444 :
SeqJac(A->getmat(), configuration)
460 SeqJac (
const M& A,
const ParameterTree& configuration)
469 virtual void pre ([[maybe_unused]] X& x, [[maybe_unused]] Y& b)
477 virtual void apply (X& v,
const Y& d)
479 for (
int i=0; i<_n; i++) {
489 virtual void post ([[maybe_unused]] X& x)
504 scalar_field_type _w;
521 template<
class M,
class X,
class Y,
int l=1>
550 :
SeqILU( A, 0, w, resort )
569 :
SeqILU(A->getmat(), configuration)
586 SeqILU(
const M& A,
const ParameterTree& config)
589 config.
get(
"resort", false))
606 wNotIdentity_([w]{
using std::abs;
return abs(w -
scalar_field_type(1)) > 1e-15;}() )
611 ILU_.reset(
new matrix_type( A ) );
618 ILU_.reset(
new matrix_type( A.
N(), A.
M(), matrix_type::row_wise) );
636 virtual void pre ([[maybe_unused]] X& x, [[maybe_unused]] Y& b)
644 virtual void apply (X& v,
const Y& d)
666 virtual void post ([[maybe_unused]] X& x)
677 std::unique_ptr< matrix_type >
ILU_;
682 std::vector< block_type, typename matrix_type::allocator_type >
inv_;
700 template<
class X,
class Y>
741 virtual void pre ([[maybe_unused]] X& x, [[maybe_unused]] Y& b)
749 virtual void apply (X& v,
const Y& d)
760 virtual void post ([[maybe_unused]] X& x)
774 using D =
typename Dune::TypeListElement<1, decltype(tl)>::type;
775 using R =
typename Dune::TypeListElement<2, decltype(tl)>::type;
776 return std::make_shared<Richardson<D,R>>(config);
790 template<
class M,
class X,
class Y >
822 :
SeqILDL(A->getmat(), configuration)
850 : decomposition_( A.N(), A.M(),
matrix_type::random ),
854 for(
auto i = A.begin(), iend = A.end(); i != iend; ++i )
856 const auto &A_i = *i;
857 const auto ij = A_i.find( i.index() );
858 if( ij != A_i.end() )
859 decomposition_.setrowsize( i.index(), ij.offset()+1 );
861 DUNE_THROW(
ISTLError,
"diagonal entry missing" );
863 decomposition_.endrowsizes();
866 for(
auto i = A.begin(), iend = A.end(); i != iend; ++i )
868 const auto &A_i = *i;
869 for(
auto ij = A_i.begin(); ij.index() < i.index() ; ++ij )
870 decomposition_.addindex( i.index(), ij.index() );
871 decomposition_.addindex( i.index(), i.index() );
873 decomposition_.endindices();
877 for(
auto row = decomposition_.begin(), rowend = decomposition_.end(); row != rowend; ++row, ++i )
879 auto ij = i->begin();
880 for(
auto col = row->begin(), colend = row->end();
col != colend; ++
col, ++ij )
889 void pre ([[maybe_unused]] X &x, [[maybe_unused]] Y &b)
override
893 void apply ( X &v,
const Y &d )
override
900 void post ([[maybe_unused]] X &x)
override
Simple iterative methods like Jacobi, Gauss-Seidel, SOR, SSOR, etc. in a generic way.
Incomplete LDL decomposition.
The incomplete LU factorization kernels.
Some handy generic functions for ISTL matrices.
Define general, extensible interface for inverse operators.
Col col
Definition: matrixmatrix.hh:349
void bsorb(const M &A, X &x, const Y &b, const K &w)
SSOR step.
Definition: gsetc.hh:644
void dbjac(const M &A, X &x, const Y &b, const K &w)
Jacobi step.
Definition: gsetc.hh:656
void bsorf(const M &A, X &x, const Y &b, const K &w)
SOR step.
Definition: gsetc.hh:632
Definition: allocator.hh:9
void bildl_decompose(Matrix &A)
compute ILDL decomposition of a symmetric matrix A
Definition: ildl.hh:86
PropertyMapTypeSelector< Amg::VertexVisitedTag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > >::Type get([[maybe_unused]] const Amg::VertexVisitedTag &tag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > &graph)
Definition: dependency.hh:291
DUNE_REGISTER_PRECONDITIONER("amg", AMGCreator())
void bildl_backsolve(const Matrix &A, X &v, const Y &d, bool isLowerTriangular=false)
Definition: ildl.hh:147
void convertToCRS(const M &A, CRS &lower, CRS &upper, InvVector &inv)
convert ILU decomposition into CRS format for lower and upper triangular and inverse.
Definition: ilu.hh:306
void blockILUBacksolve(const M &A, X &v, const Y &d)
LU backsolve with stored inverse.
Definition: ilu.hh:93
void blockILU0Decomposition(M &A)
compute ILU decomposition of A. A is overwritten by its decomposition
Definition: ilu.hh:32
void blockILUDecomposition(const M &A, int n, M &ILU)
Definition: ilu.hh:166
compile-time parameter for block recursion depth
Definition: gsetc.hh:43
derive error class from the base class in common
Definition: istlexception.hh:17
size_type M() const
Return the number of columns.
Definition: matrix.hh:698
size_type N() const
Return the number of rows.
Definition: matrix.hh:693
static void check([[maybe_unused]] const Matrix &mat)
Check whether the a matrix has diagonal values on blocklevel recursion levels.
Definition: matrixutils.hh:51
A linear operator exporting itself in matrix form.
Definition: operators.hh:107
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:30
Turns an InverseOperator into a Preconditioner.
Definition: preconditioners.hh:73
O::range_type range_type
The range type of the preconditioner.
Definition: preconditioners.hh:78
O::domain_type domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:76
virtual void post(domain_type &)
Clean up.
Definition: preconditioners.hh:107
range_type::field_type field_type
The field type of the preconditioner.
Definition: preconditioners.hh:80
Simd::Scalar< field_type > scalar_field_type
scalar type underlying the field_type
Definition: preconditioners.hh:82
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: preconditioners.hh:111
virtual void pre(domain_type &, range_type &)
Prepare the preconditioner.
Definition: preconditioners.hh:97
InverseOperator2Preconditioner(InverseOperator &inverse_operator)
Construct the preconditioner from the solver.
Definition: preconditioners.hh:90
O InverseOperator
type of the wrapped inverse operator
Definition: preconditioners.hh:84
virtual void apply(domain_type &v, const range_type &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: preconditioners.hh:100
Sequential SSOR preconditioner.
Definition: preconditioners.hh:137
SeqSSOR(const std::shared_ptr< const AssembledLinearOperator< M, X, Y >> &A, const ParameterTree &configuration)
Constructor.
Definition: preconditioners.hh:176
SeqSSOR(const M &A, const ParameterTree &configuration)
Constructor.
Definition: preconditioners.hh:193
virtual void pre([[maybe_unused]] X &x, [[maybe_unused]] Y &b)
Prepare the preconditioner.
Definition: preconditioners.hh:202
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: preconditioners.hh:227
X::field_type field_type
The field type of the preconditioner.
Definition: preconditioners.hh:146
Simd::Scalar< field_type > scalar_field_type
scalar type underlying the field_type
Definition: preconditioners.hh:148
SeqSSOR(const M &A, int n, scalar_field_type w)
Constructor.
Definition: preconditioners.hh:157
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:142
M matrix_type
The matrix type the preconditioner is for.
Definition: preconditioners.hh:140
virtual void post([[maybe_unused]] X &x)
Clean up.
Definition: preconditioners.hh:223
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: preconditioners.hh:210
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:144
Sequential SOR preconditioner.
Definition: preconditioners.hh:255
M matrix_type
The matrix type the preconditioner is for.
Definition: preconditioners.hh:258
void apply(X &v, const Y &d)
Apply the preconditioner in a special direction.
Definition: preconditioners.hh:342
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:260
SeqSOR(const M &A, int n, scalar_field_type w)
Constructor.
Definition: preconditioners.hh:275
Simd::Scalar< field_type > scalar_field_type
scalar type underlying the field_type
Definition: preconditioners.hh:266
SeqSOR(const std::shared_ptr< const AssembledLinearOperator< M, X, Y >> &A, const ParameterTree &configuration)
Constructor.
Definition: preconditioners.hh:294
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: preconditioners.hh:363
virtual void pre([[maybe_unused]] X &x, [[maybe_unused]] Y &b)
Prepare the preconditioner.
Definition: preconditioners.hh:320
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: preconditioners.hh:328
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:262
SeqSOR(const M &A, const ParameterTree &configuration)
Constructor.
Definition: preconditioners.hh:311
X::field_type field_type
The field type of the preconditioner.
Definition: preconditioners.hh:264
virtual void post([[maybe_unused]] X &x)
Clean up.
Definition: preconditioners.hh:359
The sequential jacobian preconditioner.
Definition: preconditioners.hh:404
virtual void post([[maybe_unused]] X &x)
Clean up.
Definition: preconditioners.hh:489
SeqJac(const M &A, const ParameterTree &configuration)
Constructor.
Definition: preconditioners.hh:460
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: preconditioners.hh:477
M matrix_type
The matrix type the preconditioner is for.
Definition: preconditioners.hh:407
Simd::Scalar< field_type > scalar_field_type
scalar type underlying the field_type
Definition: preconditioners.hh:415
SeqJac(const std::shared_ptr< const AssembledLinearOperator< M, X, Y >> &A, const ParameterTree &configuration)
Constructor.
Definition: preconditioners.hh:443
X::field_type field_type
The field type of the preconditioner.
Definition: preconditioners.hh:413
SeqJac(const M &A, int n, scalar_field_type w)
Constructor.
Definition: preconditioners.hh:424
virtual void pre([[maybe_unused]] X &x, [[maybe_unused]] Y &b)
Prepare the preconditioner.
Definition: preconditioners.hh:469
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:409
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: preconditioners.hh:493
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:411
Sequential ILU preconditioner.
Definition: preconditioners.hh:522
matrix_type ::block_type block_type
block type of matrix
Definition: preconditioners.hh:527
virtual void apply(X &v, const Y &d)
Apply the preconditioner.
Definition: preconditioners.hh:644
ILU::CRS< block_type, typename M::allocator_type > CRS
type of ILU storage
Definition: preconditioners.hh:540
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:531
const scalar_field_type w_
The relaxation factor to use.
Definition: preconditioners.hh:685
CRS lower_
The ILU(n) decomposition of the matrix. As storage a CRS structure is used.
Definition: preconditioners.hh:680
const bool wNotIdentity_
true if w != 1.0
Definition: preconditioners.hh:687
SeqILU(const M &A, const ParameterTree &config)
Constructor.
Definition: preconditioners.hh:586
virtual void post([[maybe_unused]] X &x)
Clean up.
Definition: preconditioners.hh:666
SeqILU(const M &A, int n, scalar_field_type w, const bool resort=false)
Constructor.
Definition: preconditioners.hh:600
std::remove_const< M >::type matrix_type
The matrix type the preconditioner is for.
Definition: preconditioners.hh:525
SeqILU(const M &A, scalar_field_type w, const bool resort=false)
Constructor.
Definition: preconditioners.hh:549
virtual void pre([[maybe_unused]] X &x, [[maybe_unused]] Y &b)
Prepare the preconditioner.
Definition: preconditioners.hh:636
X::field_type field_type
The field type of the preconditioner.
Definition: preconditioners.hh:534
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: preconditioners.hh:670
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:529
std::vector< block_type, typename matrix_type::allocator_type > inv_
Definition: preconditioners.hh:682
Simd::Scalar< field_type > scalar_field_type
scalar type underlying the field_type
Definition: preconditioners.hh:537
SeqILU(const std::shared_ptr< const AssembledLinearOperator< M, X, Y >> &A, const ParameterTree &configuration)
Constructor.
Definition: preconditioners.hh:568
std::unique_ptr< matrix_type > ILU_
The ILU(n) decomposition of the matrix. As storage a BCRSMatrix is used.
Definition: preconditioners.hh:677
CRS upper_
Definition: preconditioners.hh:681
Richardson preconditioner.
Definition: preconditioners.hh:701
virtual void post([[maybe_unused]] X &x)
Clean up.
Definition: preconditioners.hh:760
X::field_type field_type
The field type of the preconditioner.
Definition: preconditioners.hh:708
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: preconditioners.hh:764
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:706
Richardson(scalar_field_type w=1.0)
Constructor.
Definition: preconditioners.hh:717
Simd::Scalar< field_type > scalar_field_type
scalar type underlying the field_type
Definition: preconditioners.hh:710
Richardson(const ParameterTree &configuration)
Constructor.
Definition: preconditioners.hh:732
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:704
virtual void pre([[maybe_unused]] X &x, [[maybe_unused]] Y &b)
Prepare the preconditioner.
Definition: preconditioners.hh:741
virtual void apply(X &v, const Y &d)
Apply the precondioner.
Definition: preconditioners.hh:749
sequential ILDL preconditioner
Definition: preconditioners.hh:793
SeqILDL(const matrix_type &A, const ParameterTree &config)
Constructor.
Definition: preconditioners.hh:837
void pre([[maybe_unused]] X &x, [[maybe_unused]] Y &b) override
Prepare the preconditioner.
Definition: preconditioners.hh:889
SeqILDL(const matrix_type &A, scalar_field_type relax=scalar_field_type(1))
constructor
Definition: preconditioners.hh:849
void post([[maybe_unused]] X &x) override
Clean up.
Definition: preconditioners.hh:900
X domain_type
domain type of the preconditioner
Definition: preconditioners.hh:801
Y range_type
range type of the preconditioner
Definition: preconditioners.hh:803
std::remove_const_t< M > matrix_type
type of matrix the preconditioner is for
Definition: preconditioners.hh:799
void apply(X &v, const Y &d) override
Apply one step of the preconditioner to the system A(v)=d.
Definition: preconditioners.hh:893
SeqILDL(const std::shared_ptr< const AssembledLinearOperator< M, X, Y >> &A, const ParameterTree &configuration)
Constructor.
Definition: preconditioners.hh:821
Simd::Scalar< field_type > scalar_field_type
scalar type underlying the field_type
Definition: preconditioners.hh:807
X::field_type field_type
field type of the preconditioner
Definition: preconditioners.hh:805
SolverCategory::Category category() const override
Category of the preconditioner (see SolverCategory::Category)
Definition: preconditioners.hh:904
Statistics about the application of an inverse operator.
Definition: solver.hh:46
Abstract base class for all solvers.
Definition: solver.hh:97
Category
Definition: solvercategory.hh:21
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:23
static Category category(const OP &op, decltype(op.category()) *=nullptr)
Helperfunction to extract the solver category either from an enum, or from the newly introduced virtu...
Definition: solvercategory.hh:32