28 template<
class T = real_t>
36 typedef typename Base::LinOpPtr LinOpPtr;
38 typedef memory::shared_ptr<gsConjugateGradient> Ptr;
39 typedef memory::unique_ptr<gsConjugateGradient> uPtr;
45 template<
typename OperatorType >
47 const LinOpPtr& precond = LinOpPtr() )
48 :
Base(mat, precond), m_calcEigenvals(false) {}
54 template<
typename OperatorType >
55 static uPtr
make(
const OperatorType& mat,
const LinOpPtr& precond = LinOpPtr() )
62 opt.
addSwitch(
"CalcEigenvalues",
"Additionally to solving the system,"
63 " CG computes the eigenvalues of the Lanczos matrix",
false );
71 m_calcEigenvals = opt.
askSwitch(
"CalcEigenvalues", m_calcEigenvals);
76 bool step( VectorType& x );
89 std::ostream &
print(std::ostream &os)
const
91 os <<
"gsConjugateGradient\n";
110 bool m_calcEigenvals;
112 std::vector<T> m_delta, m_gamma;
117 #ifndef GISMO_BUILD_LIB
118 #include GISMO_HPP_HEADER(gsConjugateGradient.hpp)
const LinOpPtr m_mat
The matrix/operator to be solved for.
Definition: gsIterativeSolver.h:252
virtual gsIterativeSolver & setOptions(const gsOptionList &opt)
Set the options based on a gsOptionList.
Definition: gsIterativeSolver.h:102
bool step(VectorType &x)
Perform one step, requires initIteration.
Definition: gsConjugateGradient.hpp:55
gsOptionList::Real m_tol
The tolerance for m_error to be reached.
Definition: gsIterativeSolver.h:255
The conjugate gradient method.
Definition: gsConjugateGradient.h:29
T getConditionNumber()
returns the condition number of the (preconditioned) system matrix
Definition: gsConjugateGradient.hpp:87
static uPtr make(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Make function using a matrix (operator) and optionally a preconditionner.
Definition: gsConjugateGradient.h:55
T m_rhs_norm
The norm of the right-hand-side.
Definition: gsIterativeSolver.h:257
bool initIteration(const VectorType &rhs, VectorType &x)
Init the iteration.
Definition: gsConjugateGradient.hpp:20
void getEigenvalues(VectorType &eigs)
returns the eigenvalues of the Lanczos matrix
Definition: gsConjugateGradient.hpp:116
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
gsConjugateGradient(const OperatorType &mat, const LinOpPtr &precond=LinOpPtr())
Constructor using a matrix (operator) and optionally a preconditionner.
Definition: gsConjugateGradient.h:46
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsConjugateGradient.h:89
T m_error
The relative error as absolute_error/m_rhs_norm.
Definition: gsIterativeSolver.h:258
Abstract class for iterative solvers.
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
void setCalcEigenvalues(bool flag)
specify if you want to store data for eigenvalue estimation
Definition: gsConjugateGradient.h:80
gsConjugateGradient & setOptions(const gsOptionList &opt)
Set the options based on a gsOptionList.
Definition: gsConjugateGradient.h:68
static gsOptionList defaultOptions()
Returns a list of default options.
Definition: gsConjugateGradient.h:59
index_t m_num_iter
The number of iterations performed.
Definition: gsIterativeSolver.h:256
LinOpPtr m_precond
The preconditioner.
Definition: gsIterativeSolver.h:253