28 template<
class T = real_t>
36 typedef typename Base::LinOpPtr LinOpPtr;
38 typedef memory::shared_ptr<gsGradientMethod> Ptr;
39 typedef memory::unique_ptr<gsGradientMethod> uPtr;
48 template<
typename OperatorType >
50 const LinOpPtr& precond = LinOpPtr())
51 :
Base(mat, precond), m_adapt_step_size(true), m_step_size(0) {}
58 template<
typename OperatorType >
60 const LinOpPtr& precond,
62 :
Base(mat, precond), m_adapt_step_size(false), m_step_size(step_size) {}
71 template<
typename OperatorType >
72 static uPtr
make(
const OperatorType& mat,
73 const LinOpPtr& precond = LinOpPtr())
81 template<
typename OperatorType >
82 static uPtr
make(
const OperatorType& mat,
83 const LinOpPtr& precond,
98 void setStepSize(T step_size) { m_adapt_step_size =
false; m_step_size = (gsOptionList::Real)step_size; }
104 opt.
addSwitch(
"AdaptiveStepSize",
"Adaptive step sizes (to minimize residual)",
true );
105 opt.
addReal (
"StepSize",
"Step size (requires AdaptiveStepSize to be false)" , 0 );
113 m_adapt_step_size = opt.
askSwitch(
"AdaptiveStepSize", m_adapt_step_size);
114 m_step_size = opt.
askReal (
"StepSize", m_step_size );
115 if (m_adapt_step_size) m_step_size = 0;
120 bool step( VectorType& x );
123 std::ostream &
print(std::ostream &os)
const
125 os <<
"gsGradientMethod\n";
141 bool m_adapt_step_size;
142 gsOptionList::Real m_step_size;
148 #ifndef GISMO_BUILD_LIB
149 #include GISMO_HPP_HEADER(gsGradientMethod.hpp)
const LinOpPtr m_mat
The matrix/operator to be solved for.
Definition: gsIterativeSolver.h:252
T stepSize() const
Returns the chosen step size.
Definition: gsGradientMethod.h:91
virtual gsIterativeSolver & setOptions(const gsOptionList &opt)
Set the options based on a gsOptionList.
Definition: gsIterativeSolver.h:102
bool adaptiveStepSize() const
Returns true iff adaptive step sizes are activated.
Definition: gsGradientMethod.h:88
gsGradientMethod & setOptions(const gsOptionList &opt)
Set the options based on a gsOptionList.
Definition: gsGradientMethod.h:110
gsOptionList::Real m_tol
The tolerance for m_error to be reached.
Definition: gsIterativeSolver.h:255
bool step(VectorType &x)
Perform one step, requires initIteration.
Definition: gsGradientMethod.hpp:33
static uPtr make(const OperatorType &mat, const LinOpPtr &precond, T step_size)
Constructor using a matrix (operator) and optionally a preconditionner.
Definition: gsGradientMethod.h:82
T m_rhs_norm
The norm of the right-hand-side.
Definition: gsIterativeSolver.h:257
void setStepSize(T step_size)
Set the step size.
Definition: gsGradientMethod.h:98
static uPtr make(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Constructor using a matrix (operator) and optionally a preconditionner.
Definition: gsGradientMethod.h:72
static gsOptionList defaultOptions()
Returns a list of default options.
Definition: gsIterativeSolver.h:92
index_t m_max_iters
The upper bound for the number of iterations.
Definition: gsIterativeSolver.h:254
The gradient method.
Definition: gsGradientMethod.h:29
gsGradientMethod(const OperatorType &mat, const LinOpPtr &precond, T step_size)
Constructor using a matrix (operator) and optionally a preconditionner.
Definition: gsGradientMethod.h:59
T m_error
The relative error as absolute_error/m_rhs_norm.
Definition: gsIterativeSolver.h:258
Real askReal(const std::string &label, const Real &value=0) const
Reads value for option label from options.
Definition: gsOptionList.cpp:139
Abstract class for iterative solvers.
bool initIteration(const VectorType &rhs, VectorType &x)
Init the iteration.
Definition: gsGradientMethod.hpp:18
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
gsGradientMethod(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Constructor using a matrix (operator) and optionally a preconditionner.
Definition: gsGradientMethod.h:49
void setAdaptiveStepSize()
Activate adaptive step size. Then in each step, the step size is chosen such that the norm of the res...
Definition: gsGradientMethod.h:95
bool askSwitch(const std::string &label, const bool &value=false) const
Reads value for option label from options.
Definition: gsOptionList.cpp:128
Abstract class for iterative solvers.
Definition: gsIterativeSolver.h:26
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
void addSwitch(const std::string &label, const std::string &desc, const bool &value)
Adds a option named label, with description desc and value value.
Definition: gsOptionList.cpp:235
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsGradientMethod.h:123
index_t m_num_iter
The number of iterations performed.
Definition: gsIterativeSolver.h:256
static gsOptionList defaultOptions()
Returns a list of default options.
Definition: gsGradientMethod.h:101
LinOpPtr m_precond
The preconditioner.
Definition: gsIterativeSolver.h:253