24 void gaussSeidelSweep(
const gsSparseMatrix<T> & A, gsMatrix<T>& x,
const gsMatrix<T>& f);
26 void reverseGaussSeidelSweep(
const gsSparseMatrix<T> & A, gsMatrix<T>& x,
const gsMatrix<T>& f);
32 template <
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;
132 template <
class Derived>
138 template <
class Derived>
145 template <
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;
249 template <
class Derived>
255 template <
class Derived>
277 template <
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)
312 if ( ordering == gsGaussSeidel::forward )
313 internal::gaussSeidelSweep<T>(
m_expr,x,rhs);
314 if ( ordering == gsGaussSeidel::reverse )
315 internal::reverseGaussSeidelSweep<T>(
m_expr,x,rhs);
316 if ( ordering == gsGaussSeidel::symmetric )
318 internal::gaussSeidelSweep<T>(
m_expr,x,rhs);
319 internal::reverseGaussSeidelSweep<T>(
m_expr,x,rhs);
325 if ( ordering == gsGaussSeidel::forward )
326 internal::reverseGaussSeidelSweep<T>(
m_expr,x,rhs);
327 if ( ordering == gsGaussSeidel::reverse )
328 internal::gaussSeidelSweep<T>(
m_expr,x,rhs);
329 if ( ordering == gsGaussSeidel::symmetric )
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." );
357 template <
class Derived>
363 template <
class Derived>
369 template <
class Derived>
375 template <
class Derived>
381 template <
class Derived>
387 template <
class Derived>
395 template <
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;
476 template <
class Derived>
482 template <
class Derived>
489 #ifndef GISMO_BUILD_LIB
490 #include GISMO_HPP_HEADER(gsSimplePreconditioners.hpp)
NestedMatrix matrix() const
Returns the matrix.
Definition: gsSimplePreconditioners.h:229
memory::unique_ptr< gsJacobiOp > uPtr
Unique pointer for gsJacobiOp.
Definition: gsSimplePreconditioners.h:159
unique_ptr< T > make_unique(T *x)
Definition: gsMemory.h:198
index_t cols() const
Returns the number of columns of the operator.
Definition: gsSimplePreconditioners.h:337
virtual void setOptions(const gsOptionList &opt)
Set options based on a gsOptionList object.
Definition: gsPreconditioner.h:111
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
ordering
Specify the ordering of gsGaussSeidelOp preconditioner.
Definition: gsSimplePreconditioners.h:264
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
NestedMatrix matrix() const
Returns the matrix.
Definition: gsSimplePreconditioners.h:340
static gsOptionList defaultOptions()
Get the default options as gsOptionList object.
Definition: gsSimplePreconditioners.h:214
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
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
apply the operator on the input vector and store the result in x
Definition: gsSimplePreconditioners.h:75
gsJacobiOp(const MatrixPtr &mat, T tau=1)
Constructor with shared pointer to matrix.
Definition: gsSimplePreconditioners.h:169
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
apply the operator on the input vector and store the result in x
Definition: gsSimplePreconditioners.h:443
memory::shared_ptr< gsJacobiOp > Ptr
Shared pointer for gsJacobiOp.
Definition: gsSimplePreconditioners.h:156
index_t rows() const
Returns the number of rows of the operator.
Definition: gsSimplePreconditioners.h:204
Richardson preconditioner.
Definition: gsSimplePreconditioners.h:33
gsEigen::IncompleteLUT< T > m_ilu
The decomposition itself.
Definition: gsSimplePreconditioners.h:470
MatrixType::Scalar T
Scalar type.
Definition: gsSimplePreconditioners.h:40
gsIncompleteLUOp(const MatrixType &mat, index_t fillfactor=1)
Constructor with given matrix.
Definition: gsSimplePreconditioners.h:415
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
gsPreconditionerOp< T > Base
Base class.
Definition: gsSimplePreconditioners.h:162
const MatrixPtr m_mat
Shared pointer to matrix (if needed)
Definition: gsSimplePreconditioners.h:351
Jacobi preconditioner.
Definition: gsSimplePreconditioners.h:146
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
NestedMatrix matrix() const
Returns the matrix.
Definition: gsSimplePreconditioners.h:457
gsGaussSeidelOp(const MatrixPtr &mat)
Constructor with shared pointer to matrix.
Definition: gsSimplePreconditioners.h:301
NestedMatrix m_expr
Nested Eigen expression.
Definition: gsSimplePreconditioners.h:352
index_t cols() const
Returns the number of columns of the operator.
Definition: gsSimplePreconditioners.h:454
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
Simple abstract class for (discrete) linear preconditioners.
#define index_t
Definition: gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
Gauss-Seidel preconditioner.
Definition: gsSimplePreconditioners.h:278
void getDamping()
Get damping parameter.
Definition: gsSimplePreconditioners.h:211
index_t cols() const
Returns the number of columns of the operator.
Definition: gsSimplePreconditioners.h:88
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
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
gsRichardsonOp(const MatrixType &mat, T tau=1)
Constructor with given matrix.
Definition: gsSimplePreconditioners.h:52
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
static gsOptionList defaultOptions()
Get the default options as gsOptionList object.
Definition: gsSimplePreconditioners.h:97
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
gsLinearOperator< T >::Ptr underlyingOp() const
Return the underlying operator .
Definition: gsSimplePreconditioners.h:237
memory::unique_ptr< gsIncompleteLUOp > uPtr
Unique pointer for gsIncompleteLUOp.
Definition: gsSimplePreconditioners.h:409
MatrixPtr matrixPtr() const
Returns a shared pinter to the matrix.
Definition: gsSimplePreconditioners.h:460
memory::shared_ptr< gsIncompleteLUOp > Ptr
Shared pointer for gsIncompleteLUOp.
Definition: gsSimplePreconditioners.h:406
gsGaussSeidelOp(const MatrixType &mat)
Constructor with given matrix.
Definition: gsSimplePreconditioners.h:297
memory::unique_ptr< gsGaussSeidelOp > uPtr
Unique pointer for gsGaussSeidelOp.
Definition: gsSimplePreconditioners.h:291
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
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
MatrixType::Scalar T
Scalar type.
Definition: gsSimplePreconditioners.h:285
memory::shared_ptr< gsRichardsonOp > Ptr
Shared pointer for gsRichardsonOp.
Definition: gsSimplePreconditioners.h:43
gsIncompleteLUOp(const MatrixPtr &mat, index_t fillfactor=1)
Constructor with shared pointer to matrix.
Definition: gsSimplePreconditioners.h:423
memory::shared_ptr< gsLinearOperator > Ptr
Shared pointer for gsLinearOperator.
Definition: gsLinearOperator.h:33
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
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
MatrixType::Scalar T
Scalar type.
Definition: gsSimplePreconditioners.h:403
MatrixPtr matrixPtr() const
Returns a shared pinter to the matrix.
Definition: gsSimplePreconditioners.h:343
const MatrixPtr m_mat
Shared pointer to matrix (if needed)
Definition: gsSimplePreconditioners.h:123
void getDamping()
Get damping parameter.
Definition: gsSimplePreconditioners.h:94
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
apply the operator on the input vector and store the result in x
Definition: gsSimplePreconditioners.h:190
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
memory::shared_ptr< gsGaussSeidelOp > Ptr
Shared pointer for gsGaussSeidelOp.
Definition: gsSimplePreconditioners.h:288
gsPreconditionerOp< T > Base
Base class.
Definition: gsSimplePreconditioners.h:294
Simple abstract class for perconditioners.
Definition: gsPreconditioner.h:42
Real askReal(const std::string &label, const Real &value=0) const
Reads value for option label from options.
Definition: gsOptionList.cpp:139
gsLinearOperator< T >::Ptr underlyingOp() const
Return the underlying operator .
Definition: gsSimplePreconditioners.h:120
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
NestedMatrix m_expr
Nested Eigen expression.
Definition: gsSimplePreconditioners.h:124
void setDamping(const T tau)
Set damping parameter.
Definition: gsSimplePreconditioners.h:91
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
void setDamping(const T tau)
Set damping parameter.
Definition: gsSimplePreconditioners.h:208
MatrixPtr matrixPtr() const
Returns a shared pinter to the matrix.
Definition: gsSimplePreconditioners.h:115
gsPreconditionerOp< T > Base
Base class.
Definition: gsSimplePreconditioners.h:412
const MatrixPtr m_mat
Shared pointer to matrix (if needed)
Definition: gsSimplePreconditioners.h:468
NestedMatrix m_expr
Nested Eigen expression.
Definition: gsSimplePreconditioners.h:241
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
gsLinearOperator< T >::Ptr underlyingOp() const
Return the underlying operator .
Definition: gsSimplePreconditioners.h:348
This is the main header file that collects wrappers of Eigen for linear algebra.
virtual void setOptions(const gsOptionList &opt)
Set options based on a gsOptionList object.
Definition: gsSimplePreconditioners.h:105
Incomplete LU with thresholding preconditioner.
Definition: gsSimplePreconditioners.h:396
index_t cols() const
Returns the number of columns of the operator.
Definition: gsSimplePreconditioners.h:205
gsPreconditionerOp< T > Base
Base class.
Definition: gsSimplePreconditioners.h:49
NestedMatrix m_expr
Nested Eigen expression.
Definition: gsSimplePreconditioners.h:469
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
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
gsRichardsonOp(const MatrixPtr &mat, T tau=1)
Constructor with shared pointer to matrix.
Definition: gsSimplePreconditioners.h:56
index_t rows() const
Returns the number of rows of the operator.
Definition: gsSimplePreconditioners.h:336
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
memory::unique_ptr< gsRichardsonOp > uPtr
Unique pointer for gsRichardsonOp.
Definition: gsSimplePreconditioners.h:46
static gsOptionList defaultOptions()
Get the default options as gsOptionList object.
Definition: gsPreconditioner.h:103
const MatrixPtr m_mat
Shared pointer to matrix (if needed)
Definition: gsSimplePreconditioners.h:240
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
MatrixPtr matrixPtr() const
Returns a shared pinter to the matrix.
Definition: gsSimplePreconditioners.h:232
NestedMatrix matrix() const
Returns the matrix.
Definition: gsSimplePreconditioners.h:112
index_t rows() const
Returns the number of rows of the operator.
Definition: gsSimplePreconditioners.h:87
MatrixType::Scalar T
Scalar type.
Definition: gsSimplePreconditioners.h:153