26#include <ql/math/matrixutilities/bicgstab.hpp>
35 : A_(
std::move(A)), M_(
std::move(preConditioner)), maxIter_(maxIter), relTol_(relTol) {}
48 Array p, pTld, v, s, sTld, t;
51 Real alpha = 0.0, beta;
55 for (i=0; i < maxIter_ && error >=
relTol_; ++i) {
57 if (rho == 0.0 || omega == 0.0)
61 beta = (rho / rhoTld) * (alpha / omega);
62 p = r + beta * (p - omega * v);
67 pTld = (!
M_ ? p :
M_(p));
74 error =
Norm2(s)/bnorm2;
78 sTld = (!
M_ ? s :
M_(s));
81 x += alpha*pTld + omega*sTld;
83 error =
Norm2(r)/bnorm2;
87 QL_REQUIRE(i <
maxIter_,
"max number of iterations exceeded");
88 QL_REQUIRE(error <
relTol_,
"could not converge");
1-D array used in linear algebra.
bool empty() const
whether the array is empty
BiCGStabResult solve(const Array &b, const Array &x0=Array()) const
ext::function< Array(const Array &)> MatrixMult
BiCGstab(MatrixMult A, Size maxIter, Real relTol, MatrixMult preConditioner=MatrixMult())
std::size_t Size
size of a container
Real Norm2(const Array &v)
Real DotProduct(const Array &v1, const Array &v2)