6 #ifndef TBCI_SOLVER_BICGSTAB_H
7 #define TBCI_SOLVER_BICGSTAB_H
9 #include "tbci/vector.h"
10 #include "tbci/solver/precond.h"
17 #ifndef NO_BICGSTAB_RESTART
18 # define BICGSTAB_RESTART
90 template < typename T, typename SysMatrix, typename T_tol /*= double*/>
93 T_tol& tol,
const unsigned off = 0)
95 const unsigned int dim = A.rows();
96 typename SysMatrix::value_type rho_1, rho_2((
typename SysMatrix::value_type)1),
97 alpha((
typename SysMatrix::value_type)0), beta,
98 omega((
typename SysMatrix::value_type)0);
100 Vector<T> p(dim), phat(dim), s(dim), shat(dim), t(dim),
v(dim);
106 if (normbsqr <= (T_tol)1e-32)
107 normbsqr = T_tol(1e32);
109 normbsqr = T_tol(1) / normbsqr;
120 alpha = beta = omega = rho_1 = (
typename SysMatrix::value_type)0;
123 if (off) cnvg.open (
"bicgstab_cnvg.gnu",
STD__ ios::app);
124 else cnvg.open (
"bicgstab_cnvg.gnu");
125 cnvg <<
"# Iter res alpha beta omega rho_1 rho_2 rho_1 / sqr(normb)" <<
STD__ endl;
128 for (
unsigned int i = 1;
i <= max_iter; ++
i) {
133 rho_1 =
dot (rtilde, r);
134 if (
UNLIKELY(rho_1 == (
typename SysMatrix::value_type)0)) {
135 #ifdef BICGSTAB_RESTART
136 # ifdef BICGSTAB_REPORT_RESTART
137 STD__ cerr <<
"BiCGstab failure 2 (iter " <<
i
138 <<
") rho1 == " << rho_1 <<
". Restart.\n";
141 rtilde = b - A*
x; r = rtilde;
153 beta = (rho_1 * alpha) / (rho_2 * omega);
154 p = r + beta * (
p - omega *
v);
158 alpha = rho_1 /
dot (rtilde, v);
160 if ((residsqr = s.fabssqr() * normbsqr) < tolsqr) {
169 x += alpha * phat + omega * shat;
174 if ((residsqr = r.
fabssqr() * normbsqr) < tolsqr) {
182 if (
UNLIKELY(omega == (
typename SysMatrix::value_type)0)) {
184 STD__ cerr <<
"BiCGstab failure 3: omega == 0\n";
const Vector< T > const Vector< T > & x
Abstract base class for all Preconditioners.
const Vector< T > const Vector< T > const Vector< T > & p
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
NAMESPACE_TBCI double class NN friend int BiCGSTAB(const BdMatrix< T > &, Vector< T > &, const Vector< T > &, const Preconditioner_Sig< T, BdMatrix< T > > &, unsigned int &, double &, const unsigned)
Matrix class with optimized Matrix-Vector multiplication for symmetrical Matrices.
cplx< T > sqr(const cplx< T > &c)
double fabssqr() const HOT
T dot(const T &a1, const T &a2)
virtual TVector< T > solve(const Vector< T > &) const =0
double fabssqr(const double a)
const Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > Vector< T > long int int char v
< find minimun of func on grid with resolution res
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...