24void gaussSeidelSweep(
const gsSparseMatrix<T> & A, gsMatrix<T>& x,
const gsMatrix<T>& f);
26void reverseGaussSeidelSweep(
const gsSparseMatrix<T> & A, gsMatrix<T>& x,
const gsMatrix<T>& f);
32template <
typename MatrixType>
35 typedef memory::shared_ptr<MatrixType> MatrixPtr;
36 typedef typename MatrixType::Nested NestedMatrix;
40 typedef typename MatrixType::Scalar
T;
43 typedef memory::shared_ptr< gsRichardsonOp >
Ptr;
46 typedef memory::unique_ptr< gsRichardsonOp >
uPtr;
59 static uPtr make(
const MatrixType& mat,
T tau = 1)
62 static uPtr make(
const MatrixPtr& mat,
T tau = 1)
68 "Dimensions do not match.");
70 x += m_tau * ( rhs -
m_expr * x );
78 "Dimensions do not match.");
81 x.noalias() = m_tau * input;
83 for (
index_t k = 1; k < m_num_of_sweeps; ++k)
84 x += m_tau * ( input -
m_expr * x );
100 opt.
addReal(
"Damping",
"Damping parameter of the Richardson iteration", 1 );
108 m_tau = opt.
askReal(
"Damping", m_tau );
116 GISMO_ENSURE(
m_mat,
"A shared pointer is only available if it was provided to gsRichardsonOp." );
126 using Base::m_num_of_sweeps;
132template <
class Derived>
138template <
class Derived>
145template <
typename MatrixType>
148 typedef memory::shared_ptr<MatrixType> MatrixPtr;
149 typedef typename MatrixType::Nested NestedMatrix;
153 typedef typename MatrixType::Scalar
T;
156 typedef memory::shared_ptr< gsJacobiOp >
Ptr;
159 typedef memory::unique_ptr< gsJacobiOp >
uPtr;
172 static uPtr make(
const MatrixType& mat,
T tau = 1)
175 static uPtr make(
const MatrixPtr& mat,
T tau = 1)
181 "Dimensions do not match.");
183 GISMO_ASSERT( rhs.cols() == 1,
"This operator is only implemented for a single right-hand side." );
185 x.array() += m_tau * ( rhs -
m_expr * x ).array() /
m_expr.diagonal().array();
193 "Dimensions do not match.");
195 GISMO_ASSERT( input.cols() == 1,
"This operator is only implemented for a single right-hand side." );
198 x.array() = m_tau * input.array() /
m_expr.diagonal().array();
200 for (
index_t k = 1; k < m_num_of_sweeps; ++k)
201 x.array() += m_tau * ( input -
m_expr * x ).array() /
m_expr.diagonal().array();
217 opt.
addReal(
"Damping",
"Damping parameter of the Jacobi iteration", 1 );
225 m_tau = opt.
askReal(
"Damping", m_tau );
233 GISMO_ENSURE(
m_mat,
"A shared pointer is only available if it was provided to gsJacobiOp." );
242 using Base::m_num_of_sweeps;
249template <
class Derived>
255template <
class Derived>
277template <
typename MatrixType, gsGaussSe
idel::ordering ordering = gsGaussSe
idel::forward>
280 typedef memory::shared_ptr<MatrixType> MatrixPtr;
281 typedef typename MatrixType::Nested NestedMatrix;
285 typedef typename MatrixType::Scalar
T;
288 typedef memory::shared_ptr< gsGaussSeidelOp >
Ptr;
291 typedef memory::unique_ptr< gsGaussSeidelOp >
uPtr;
304 static uPtr make(
const MatrixType& mat)
307 static uPtr make(
const MatrixPtr& mat)
313 internal::gaussSeidelSweep<T>(
m_expr,x,rhs);
315 internal::reverseGaussSeidelSweep<T>(
m_expr,x,rhs);
318 internal::gaussSeidelSweep<T>(
m_expr,x,rhs);
319 internal::reverseGaussSeidelSweep<T>(
m_expr,x,rhs);
326 internal::reverseGaussSeidelSweep<T>(
m_expr,x,rhs);
328 internal::gaussSeidelSweep<T>(
m_expr,x,rhs);
331 internal::gaussSeidelSweep<T>(
m_expr,x,rhs);
332 internal::reverseGaussSeidelSweep<T>(
m_expr,x,rhs);
344 GISMO_ENSURE(
m_mat,
"A shared pointer is only available if it was provided to gsGaussSeidelOp." );
357template <
class Derived>
363template <
class Derived>
369template <
class Derived>
375template <
class Derived>
381template <
class Derived>
387template <
class Derived>
395template <
typename MatrixType>
398 typedef memory::shared_ptr<MatrixType> MatrixPtr;
399 typedef typename MatrixType::Nested NestedMatrix;
403 typedef typename MatrixType::Scalar
T;
406 typedef memory::shared_ptr< gsIncompleteLUOp >
Ptr;
409 typedef memory::unique_ptr< gsIncompleteLUOp >
uPtr;
418 m_ilu.setFillfactor(fillfactor);
426 m_ilu.setFillfactor(fillfactor);
430 static uPtr make(
const MatrixType& mat,
index_t fillfactor = 1)
433 static uPtr make(
const MatrixPtr& mat,
index_t fillfactor = 1)
446 x =
m_ilu.solve( input ).eval();
448 for (
index_t k = 1; k < Base::m_num_of_sweeps; ++k)
461 GISMO_ENSURE(
m_mat,
"A shared pointer is only available if it was provided to gsIncompleteLUOp." );
471 using Base::m_num_of_sweeps;
476template <
class Derived>
482template <
class Derived>
489#ifndef GISMO_BUILD_LIB
490#include GISMO_HPP_HEADER(gsSimplePreconditioners.hpp)
Gauss-Seidel preconditioner.
Definition gsSimplePreconditioners.h:279
index_t rows() const
Returns the number of rows of the operator.
Definition gsSimplePreconditioners.h:336
gsGaussSeidelOp< Derived >::uPtr makeGaussSeidelOp(const memory::shared_ptr< Derived > &mat)
Returns a smart pointer to a Jacobi operator referring on mat.
Definition gsSimplePreconditioners.h:364
gsLinearOperator< T >::Ptr underlyingOp() const
Return the underlying operator .
Definition gsSimplePreconditioners.h:348
gsGaussSeidelOp< Derived >::uPtr makeGaussSeidelOp(const gsEigen::EigenBase< Derived > &mat)
Returns a smart pointer to a Gauss-Seidel operator referring on mat.
Definition gsSimplePreconditioners.h:358
const MatrixPtr m_mat
Shared pointer to matrix (if needed)
Definition gsSimplePreconditioners.h:351
gsGaussSeidelOp< Derived, gsGaussSeidel::reverse >::uPtr makeReverseGaussSeidelOp(const memory::shared_ptr< Derived > &mat)
Returns a smart pointer to a reverse Gauss-Seidel operator referring on mat.
Definition gsSimplePreconditioners.h:376
gsGaussSeidelOp(const MatrixPtr &mat)
Constructor with shared pointer to matrix.
Definition gsSimplePreconditioners.h:301
NestedMatrix m_expr
Nested Eigen expression.
Definition gsSimplePreconditioners.h:352
gsGaussSeidelOp< Derived, gsGaussSeidel::symmetric >::uPtr makeSymmetricGaussSeidelOp(const memory::shared_ptr< Derived > &mat)
Returns a smart pointer to a symmetric Gauss-Seidel operator referring on mat.
Definition gsSimplePreconditioners.h:388
MatrixPtr matrixPtr() const
Returns a shared pinter to the matrix.
Definition gsSimplePreconditioners.h:343
memory::shared_ptr< gsGaussSeidelOp > Ptr
Shared pointer for gsGaussSeidelOp.
Definition gsSimplePreconditioners.h:288
NestedMatrix matrix() const
Returns the matrix.
Definition gsSimplePreconditioners.h:340
MatrixType::Scalar T
Scalar type.
Definition gsSimplePreconditioners.h:285
void step(const gsMatrix< T > &rhs, gsMatrix< T > &x) const
Apply the method for given right hand side and current iterate.
Definition gsSimplePreconditioners.h:310
index_t cols() const
Returns the number of columns of the operator.
Definition gsSimplePreconditioners.h:337
gsGaussSeidelOp(const MatrixType &mat)
Constructor with given matrix.
Definition gsSimplePreconditioners.h:297
gsGaussSeidelOp< Derived, gsGaussSeidel::symmetric >::uPtr makeSymmetricGaussSeidelOp(const gsEigen::EigenBase< Derived > &mat)
Returns a smart pointer to a symmetric Gauss-Seidel operator referring on mat.
Definition gsSimplePreconditioners.h:382
memory::unique_ptr< gsGaussSeidelOp > uPtr
Unique pointer for gsGaussSeidelOp.
Definition gsSimplePreconditioners.h:291
gsPreconditionerOp< T > Base
Base class.
Definition gsSimplePreconditioners.h:294
void stepT(const gsMatrix< T > &rhs, gsMatrix< T > &x) const
Apply the transposed variant of the method for given right hand side and current iterate.
Definition gsSimplePreconditioners.h:323
gsGaussSeidelOp< Derived, gsGaussSeidel::reverse >::uPtr makeReverseGaussSeidelOp(const gsEigen::EigenBase< Derived > &mat)
Returns a smart pointer to a reverse Gauss-Seidel operator referring on mat.
Definition gsSimplePreconditioners.h:370
Incomplete LU with thresholding preconditioner.
Definition gsSimplePreconditioners.h:397
index_t rows() const
Returns the number of rows of the operator.
Definition gsSimplePreconditioners.h:453
gsLinearOperator< T >::Ptr underlyingOp() const
Return the underlying operator .
Definition gsSimplePreconditioners.h:465
const MatrixPtr m_mat
Shared pointer to matrix (if needed)
Definition gsSimplePreconditioners.h:468
gsIncompleteLUOp< Derived >::uPtr makeIncompleteLUOp(const gsEigen::EigenBase< Derived > &mat)
Returns a smart pointer to a Gauss-Seidel operator referring on mat.
Definition gsSimplePreconditioners.h:477
memory::unique_ptr< gsIncompleteLUOp > uPtr
Unique pointer for gsIncompleteLUOp.
Definition gsSimplePreconditioners.h:409
memory::shared_ptr< gsIncompleteLUOp > Ptr
Shared pointer for gsIncompleteLUOp.
Definition gsSimplePreconditioners.h:406
NestedMatrix m_expr
Nested Eigen expression.
Definition gsSimplePreconditioners.h:469
MatrixPtr matrixPtr() const
Returns a shared pinter to the matrix.
Definition gsSimplePreconditioners.h:460
gsIncompleteLUOp(const MatrixType &mat, index_t fillfactor=1)
Constructor with given matrix.
Definition gsSimplePreconditioners.h:415
NestedMatrix matrix() const
Returns the matrix.
Definition gsSimplePreconditioners.h:457
MatrixType::Scalar T
Scalar type.
Definition gsSimplePreconditioners.h:403
void step(const gsMatrix< T > &rhs, gsMatrix< T > &x) const
Apply the method for given right hand side and current iterate.
Definition gsSimplePreconditioners.h:436
index_t cols() const
Returns the number of columns of the operator.
Definition gsSimplePreconditioners.h:454
gsIncompleteLUOp(const MatrixPtr &mat, index_t fillfactor=1)
Constructor with shared pointer to matrix.
Definition gsSimplePreconditioners.h:423
gsIncompleteLUOp< Derived >::uPtr makeIncompleteLUOp(const memory::shared_ptr< Derived > &mat)
Returns a smart pointer to a Jacobi operator referring on mat.
Definition gsSimplePreconditioners.h:483
gsPreconditionerOp< T > Base
Base class.
Definition gsSimplePreconditioners.h:412
gsEigen::IncompleteLUT< T > m_ilu
The decomposition itself.
Definition gsSimplePreconditioners.h:470
Jacobi preconditioner.
Definition gsSimplePreconditioners.h:147
index_t rows() const
Returns the number of rows of the operator.
Definition gsSimplePreconditioners.h:204
gsLinearOperator< T >::Ptr underlyingOp() const
Return the underlying operator .
Definition gsSimplePreconditioners.h:237
const MatrixPtr m_mat
Shared pointer to matrix (if needed)
Definition gsSimplePreconditioners.h:240
memory::shared_ptr< gsJacobiOp > Ptr
Shared pointer for gsJacobiOp.
Definition gsSimplePreconditioners.h:156
gsJacobiOp(const MatrixPtr &mat, T tau=1)
Constructor with shared pointer to matrix.
Definition gsSimplePreconditioners.h:169
void setDamping(const T tau)
Set damping parameter.
Definition gsSimplePreconditioners.h:208
NestedMatrix m_expr
Nested Eigen expression.
Definition gsSimplePreconditioners.h:241
MatrixPtr matrixPtr() const
Returns a shared pinter to the matrix.
Definition gsSimplePreconditioners.h:232
void getDamping()
Get damping parameter.
Definition gsSimplePreconditioners.h:211
memory::unique_ptr< gsJacobiOp > uPtr
Unique pointer for gsJacobiOp.
Definition gsSimplePreconditioners.h:159
NestedMatrix matrix() const
Returns the matrix.
Definition gsSimplePreconditioners.h:229
gsJacobiOp< Derived >::uPtr makeJacobiOp(const gsEigen::EigenBase< Derived > &mat, typename Derived::Scalar tau=1)
Returns a smart pointer to a Jacobi operator referring on mat.
Definition gsSimplePreconditioners.h:250
MatrixType::Scalar T
Scalar type.
Definition gsSimplePreconditioners.h:153
void step(const gsMatrix< T > &rhs, gsMatrix< T > &x) const
Apply the method for given right hand side and current iterate.
Definition gsSimplePreconditioners.h:178
virtual void setOptions(const gsOptionList &opt)
Set options based on a gsOptionList object.
Definition gsSimplePreconditioners.h:222
gsJacobiOp(const MatrixType &mat, T tau=1)
Constructor with given matrix.
Definition gsSimplePreconditioners.h:165
index_t cols() const
Returns the number of columns of the operator.
Definition gsSimplePreconditioners.h:205
static gsOptionList defaultOptions()
Get the default options as gsOptionList object.
Definition gsSimplePreconditioners.h:214
gsJacobiOp< Derived >::uPtr makeJacobiOp(const memory::shared_ptr< Derived > &mat, typename Derived::Scalar tau=1)
Returns a smart pointer to a Jacobi operator referring on mat.
Definition gsSimplePreconditioners.h:256
gsPreconditionerOp< T > Base
Base class.
Definition gsSimplePreconditioners.h:162
memory::shared_ptr< gsLinearOperator > Ptr
Shared pointer for gsLinearOperator.
Definition gsLinearOperator.h:33
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
Real askReal(const std::string &label, const Real &value=0) const
Reads value for option label from options.
Definition gsOptionList.cpp:139
void addReal(const std::string &label, const std::string &desc, const Real &value)
Adds a option named label, with description desc and value value.
Definition gsOptionList.cpp:211
Simple abstract class for perconditioners.
Definition gsPreconditioner.h:43
virtual void setOptions(const gsOptionList &opt)
Set options based on a gsOptionList object.
Definition gsPreconditioner.h:111
static gsOptionList defaultOptions()
Get the default options as gsOptionList object.
Definition gsPreconditioner.h:103
Richardson preconditioner.
Definition gsSimplePreconditioners.h:34
index_t rows() const
Returns the number of rows of the operator.
Definition gsSimplePreconditioners.h:87
gsRichardsonOp(const MatrixPtr &mat, T tau=1)
Constructor with shared pointer to matrix.
Definition gsSimplePreconditioners.h:56
gsLinearOperator< T >::Ptr underlyingOp() const
Return the underlying operator .
Definition gsSimplePreconditioners.h:120
gsRichardsonOp(const MatrixType &mat, T tau=1)
Constructor with given matrix.
Definition gsSimplePreconditioners.h:52
const MatrixPtr m_mat
Shared pointer to matrix (if needed)
Definition gsSimplePreconditioners.h:123
gsRichardsonOp< Derived >::uPtr makeRichardsonOp(const memory::shared_ptr< Derived > &mat, typename Derived::Scalar tau=1)
Returns a smart pointer to a Richardson operator referring on mat.
Definition gsSimplePreconditioners.h:139
memory::shared_ptr< gsRichardsonOp > Ptr
Shared pointer for gsRichardsonOp.
Definition gsSimplePreconditioners.h:43
gsRichardsonOp< Derived >::uPtr makeRichardsonOp(const gsEigen::EigenBase< Derived > &mat, typename Derived::Scalar tau=1)
Returns a smart pointer to a Richardson operator referring on mat.
Definition gsSimplePreconditioners.h:133
memory::unique_ptr< gsRichardsonOp > uPtr
Unique pointer for gsRichardsonOp.
Definition gsSimplePreconditioners.h:46
void setDamping(const T tau)
Set damping parameter.
Definition gsSimplePreconditioners.h:91
NestedMatrix m_expr
Nested Eigen expression.
Definition gsSimplePreconditioners.h:124
MatrixPtr matrixPtr() const
Returns a shared pinter to the matrix.
Definition gsSimplePreconditioners.h:115
void getDamping()
Get damping parameter.
Definition gsSimplePreconditioners.h:94
NestedMatrix matrix() const
Returns the matrix.
Definition gsSimplePreconditioners.h:112
MatrixType::Scalar T
Scalar type.
Definition gsSimplePreconditioners.h:40
void step(const gsMatrix< T > &rhs, gsMatrix< T > &x) const
Apply the method for given right hand side and current iterate.
Definition gsSimplePreconditioners.h:65
virtual void setOptions(const gsOptionList &opt)
Set options based on a gsOptionList object.
Definition gsSimplePreconditioners.h:105
index_t cols() const
Returns the number of columns of the operator.
Definition gsSimplePreconditioners.h:88
static gsOptionList defaultOptions()
Get the default options as gsOptionList object.
Definition gsSimplePreconditioners.h:97
gsPreconditionerOp< T > Base
Base class.
Definition gsSimplePreconditioners.h:49
ordering
Specify the ordering of gsGaussSeidelOp preconditioner.
Definition gsSimplePreconditioners.h:265
@ symmetric
one total step is = one forward + one backward
Definition gsSimplePreconditioners.h:268
@ reverse
reverse ordering
Definition gsSimplePreconditioners.h:267
@ forward
standard forward ordering
Definition gsSimplePreconditioners.h:266
#define index_t
Definition gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition gsDebug.h:102
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
This is the main header file that collects wrappers of Eigen for linear algebra.
Simple abstract class for (discrete) linear preconditioners.
unique_ptr< T > make_unique(T *x)
Definition gsMemory.h:198
The G+Smo namespace, containing all definitions for the library.