STK++ 0.9.13
|
In most cases, preconditioning is necessary to ensure fast convergence of the conjugate gradient method. More...
#include <STK_CG.h>
Public Types | |
typedef ColVector::Type | Type |
Public Member Functions | |
r_ () | |
iter_ (0) | |
eps_ (eps) | |
p_mult_ p_cond_ | p_init_ (p_init) |
PCG (PCG const &pcg) | |
Copy constructor. | |
~PCG () | |
destructor | |
PCG * | clone () const |
clone pattern | |
ColVector const & | x () const |
Real const & | x (int const &i) const |
ColVector const & | r () const |
void | setEps (Type const &eps) |
Set the tolerance. | |
void | setB (ColVector const &b) |
Set the constant vector. | |
void | setInitFunctor (InitFunctor const &init) |
Set functor computing x at initialization. | |
void | setMultFunctor (MultFunctor const &mult) |
Set functor computing Ax. | |
void | setCondFunctor (CondFunctor const &cond) |
Set functor computing the value ![]() | |
int | run () |
run the conjugate gradient | |
String const & | error () const |
get the last error message. | |
Public Attributes | |
: x_() | |
Constructor. | |
p_mult_ | mult |
p_mult_ p_cond_ | cond |
p_mult_ p_cond_ p_b_ | b {} |
Protected Member Functions | |
int | pcg () |
preconditioned Gradient implementation | |
Protected Attributes | |
String | msg_error_ |
String with the last error message. | |
Private Attributes | |
ColVector | x_ |
solution of the system | |
ColVector | r_ |
residuals of the system | |
int | iter_ |
number of iterations | |
Type | eps_ |
tolerance | |
MultFunctor const * | p_mult_ |
pointer on the functor performing Ax | |
CondFunctor const * | p_cond_ |
pointer on the functor performing ![]() | |
InitFunctor const * | p_init_ |
pointer on the functor initializing x | |
ColVector const * | p_b_ |
constant pointer on the second member of the system | |
In most cases, preconditioning is necessary to ensure fast convergence of the conjugate gradient method.
The preconditioned conjugate gradient method takes the following form:
The result is
The above formulation is equivalent to applying the conjugate gradient method without preconditioning to the system
The preconditioner matrix M has to be symmetric positive-definite and fixed, i.e., cannot change from iteration to iteration. If any of these assumptions on the preconditioner is violated, the behavior of the preconditioned conjugate gradient method may become unpredictable.
MultFunctor | A functor computing the result of Ax. |
CondFunctor | A functor computing the value ![]() |
InitFunctor | A functor computing the initial value x. |
ColVector | The type of the containers for the vectors. |
typedef ColVector::Type STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::Type |
|
inline |
Copy constructor.
The constructor to copy.
pcg | the preconditioned conjugate gradient to copy |
Definition at line 285 of file STK_CG.h.
|
inline |
|
inline |
STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::eps_ | ( | eps | ) |
|
inline |
get the last error message.
Definition at line 319 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::msg_error_.
STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::iter_ | ( | 0 | ) |
p_mult_ p_cond_ STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::p_init_ | ( | p_init | ) |
|
inlineprotected |
preconditioned Gradient implementation
Definition at line 325 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::eps_, STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::iter_, STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::p_b_, STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::p_init_, STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::p_mult_, STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::r_, and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::x_.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::run().
|
inline |
Definition at line 303 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::r_.
STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::r_ | ( | ) |
|
inline |
run the conjugate gradient
Definition at line 315 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::pcg().
|
inline |
Set the constant vector.
Definition at line 307 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::b, and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::p_b_.
|
inline |
Set functor computing the value
Definition at line 313 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::cond, and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::p_cond_.
|
inline |
Set the tolerance.
Definition at line 305 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::eps_.
|
inline |
Set functor computing x at initialization.
Definition at line 309 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::p_init_.
|
inline |
Set functor computing Ax.
Definition at line 311 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::mult, and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::p_mult_.
|
inline |
Definition at line 299 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::x_.
|
inline |
Definition at line 301 of file STK_CG.h.
References STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::x_.
STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::__pad0__ |
p_mult_ p_cond_ p_b_ STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::b {} |
Definition at line 280 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::setB().
p_mult_ p_cond_ STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::cond |
Definition at line 278 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::setCondFunctor().
|
private |
tolerance
Definition at line 382 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::pcg(), and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::setEps().
|
private |
number of iterations
Definition at line 380 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::pcg().
|
protected |
String with the last error message.
Definition at line 323 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::error().
p_mult_ STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::mult |
Definition at line 277 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::setMultFunctor().
|
private |
constant pointer on the second member of the system
Definition at line 390 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::pcg(), and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::setB().
|
private |
pointer on the functor performing
Definition at line 386 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::setCondFunctor().
|
private |
pointer on the functor initializing x
Definition at line 388 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::pcg(), and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::setInitFunctor().
|
private |
pointer on the functor performing Ax
Definition at line 384 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::pcg(), and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::setMultFunctor().
|
private |
residuals of the system
Definition at line 378 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::pcg(), and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::r().
|
private |
solution of the system
Definition at line 376 of file STK_CG.h.
Referenced by STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::pcg(), STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::x(), and STK::PCG< MultFunctor, CondFunctor, ColVector, InitFunctor >::x().