G+Smo  23.12.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsGradientMethod< T > Class Template Reference

Detailed Description

template<class T = real_t>
class gismo::gsGradientMethod< T >

The gradient method.

Iterates x^{new} = x - damping * precond * ( mat * x - rhs ),

where by default damping = 1 and precond = identity.

+ Inheritance diagram for gsGradientMethod< T >:
+ Collaboration diagram for gsGradientMethod< T >:

Public Member Functions

bool adaptiveStepSize () const
 Returns true iff adaptive step sizes are activated.
 
virtual std::string detail () const
 Prints the object as a string with extended details.
 
error () const
 The relative residual error of the current iterate. More...
 
virtual void finalizeIteration (VectorType &)
 Some post-processing might be required.
 
template<typename OperatorType >
 gsGradientMethod (const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
 Constructor using a matrix (operator) and optionally a preconditionner. More...
 
template<typename OperatorType >
 gsGradientMethod (const OperatorType &mat, const LinOpPtr &precond, T step_size)
 Constructor using a matrix (operator) and optionally a preconditionner. More...
 
bool initIteration (const VectorType &rhs, VectorType &x)
 Init the iteration.
 
index_t iterations () const
 The number of iterations needed to reach the error criteria.
 
LinOpPtr preconditioner () const
 Get the preconditioner.
 
std::ostream & print (std::ostream &os) const
 Prints the object as a string.
 
void setAdaptiveStepSize ()
 Activate adaptive step size. Then in each step, the step size is chosen such that the norm of the residual is minimized.
 
void setMaxIterations (index_t max_iters)
 Set the maximum number of iterations (default: 1000)
 
gsGradientMethodsetOptions (const gsOptionList &opt)
 Set the options based on a gsOptionList.
 
void setPreconditioner (const LinOpPtr &precond)
 Set the preconditionner.
 
void setStepSize (T step_size)
 Set the step size.
 
void setTolerance (T tol)
 Set the tolerance for the error criteria on the relative residual error (default: 1e-10)
 
index_t size () const
 Returns the size of the linear system.
 
void solve (const VectorType &rhs, VectorType &x)
 Solves the linear system and stores the solution in x. More...
 
void solveDetailed (const VectorType &rhs, VectorType &x, VectorType &error_history)
 Solves the linear system and stores the solution in x and records the error histroy. More...
 
bool step (VectorType &x)
 Perform one step, requires initIteration.
 
stepSize () const
 Returns the chosen step size.
 
tolerance () const
 The chosen tolerance for the error criteria on the relative residual error.
 
LinOpPtr underlying () const
 Get the underlying matrix/operator to be solved for.
 

Static Public Member Functions

static gsOptionList defaultOptions ()
 Returns a list of default options.
 
template<typename OperatorType >
static uPtr make (const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
 Constructor using a matrix (operator) and optionally a preconditionner. More...
 
template<typename OperatorType >
static uPtr make (const OperatorType &mat, const LinOpPtr &precond, T step_size)
 Constructor using a matrix (operator) and optionally a preconditionner. More...
 

Protected Attributes

m_error
 The relative error as absolute_error/m_rhs_norm.
 
const LinOpPtr m_mat
 The matrix/operator to be solved for.
 
index_t m_max_iters
 The upper bound for the number of iterations.
 
index_t m_num_iter
 The number of iterations performed.
 
LinOpPtr m_precond
 The preconditioner.
 
m_rhs_norm
 The norm of the right-hand-side.
 
gsOptionList::Real m_tol
 The tolerance for m_error to be reached.
 

Related Functions

(Note that these are not member functions.)

template<class T >
std::ostream & operator<< (std::ostream &os, const gsIterativeSolver< T > &b)
 Print (as string) operator for iterative solvers. More...
 

Constructor & Destructor Documentation

gsGradientMethod ( const OperatorType &  mat,
const LinOpPtr &  precond = LinOpPtr() 
)
inlineexplicit

Constructor using a matrix (operator) and optionally a preconditionner.

Parameters
matThe operator to be solved for, see gsIterativeSolver for details
precondThe preconditioner, defaulted to the identity

In each step, the step width is chosen such that the residual is minimized (adaptive step sizes)

gsGradientMethod ( const OperatorType &  mat,
const LinOpPtr &  precond,
step_size 
)
inlineexplicit

Constructor using a matrix (operator) and optionally a preconditionner.

Parameters
matThe operator to be solved for, see gsIterativeSolver for details
precondThe preconditioner, defaulted to the identity
step_sizeThe step size

Member Function Documentation

T error ( ) const
inlineinherited

The relative residual error of the current iterate.

This is the Euclidean norm of the residual, devided by the Euclidean norm of the right-hand side.

static uPtr make ( const OperatorType &  mat,
const LinOpPtr &  precond = LinOpPtr() 
)
inlinestatic

Constructor using a matrix (operator) and optionally a preconditionner.

Parameters
matThe operator to be solved for, see gsIterativeSolver for details
precondThe preconditioner, defaulted to the identity

In each step, the step width is chosen such that the residual is minimized (adaptive step sizes)

static uPtr make ( const OperatorType &  mat,
const LinOpPtr &  precond,
step_size 
)
inlinestatic

Constructor using a matrix (operator) and optionally a preconditionner.

Parameters
matThe operator to be solved for, see gsIterativeSolver for details
precondThe preconditioner, defaulted to the identity
step_sizeThe step size
void solve ( const VectorType rhs,
VectorType x 
)
inlineinherited

Solves the linear system and stores the solution in x.

Solves the linear system of equations

Parameters
[in]rhsthe right hand side of the linear system
[in,out]xstarting value; the solution is stored in here
void solveDetailed ( const VectorType rhs,
VectorType x,
VectorType error_history 
)
inlineinherited

Solves the linear system and stores the solution in x and records the error histroy.

Solves the linear system of equations

Parameters
[in]rhsthe right hand side of the linear system
[in,out]xstarting value; the solution is stored in here
[out]error_historythe error history is stored here

Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  os,
const gsIterativeSolver< T > &  b 
)
related

Print (as string) operator for iterative solvers.