Go to the documentation of this file.
21 #ifndef THUNDEREGG_ITERATIVE_BICGSTAB_H
22 #define THUNDEREGG_ITERATIVE_BICGSTAB_H
47 int max_iterations = 1000;
51 double tolerance = 1e-12;
55 std::shared_ptr<Timer> timer =
nullptr;
57 void applyWithPreconditioner(
const Operator<D>* M_l,
63 if (M_l ==
nullptr && M_r ==
nullptr) {
65 }
else if (M_l ==
nullptr && M_r !=
nullptr) {
116 void setTimer(std::shared_ptr<Timer> timer_in) { timer = timer_in; }
123 std::shared_ptr<Timer>
getTimer()
const {
return timer; }
131 std::ostream& os = std::cout)
const override
148 double rho = rhat.
dot(resid);
151 double residual = resid.
twoNorm() / r0_norm;
154 sprintf(buf,
"%5d %16.8e\n", num_its, residual);
155 os << std::string(buf);
160 while (residual > tolerance && num_its < max_iterations) {
162 timer->start(
"Iteration");
166 throw BreakdownError(
"BiCGStab broke down, rho was 0 on iteration " +
167 std::to_string(num_its));
170 applyWithPreconditioner(
nullptr, A, Mr, p, ap);
171 double alpha = rho / rhat.
dot(ap);
174 if (s.
twoNorm() / r0_norm <= tolerance) {
177 timer->stop(
"Iteration");
181 applyWithPreconditioner(
nullptr, A, Mr, s, as);
182 double omega = as.
dot(s) / as.
dot(as);
187 double rho_new = resid.
dot(rhat);
188 double beta = rho_new * alpha / (rho * omega);
194 residual = resid.
twoNorm() / r0_norm;
198 sprintf(buf,
"%5d %16.8e\n", num_its, residual);
199 os << std::string(buf);
202 timer->stop(
"Iteration");
209 x.
add(initial_guess);
void scaleThenAdd(double alpha, const Vector< D > &b)
this = alpha * this + b
Definition: Vector.h:509
int getMaxIterations() const
Get the maximum number of iterations.
Definition: BiCGStab.h:94
Breakdown exception for iterative methods.
Definition: BreakdownError.h:35
void setMaxIterations(int max_iterations_in)
Set the maximum number of iterations.
Definition: BiCGStab.h:86
void setTolerance(double tolerance_in)
Set the stopping tolerance.
Definition: BiCGStab.h:102
void set(double alpha)
set all value in the vector
Definition: Vector.h:391
void addScaled(double alpha, const Vector< D > &b)
this = this + alpha * b
Definition: Vector.h:483
Iterative Solvers.
Definition: BiCGStab.h:34
void copy(const Vector< D > &b)
copy the values of the other vector
Definition: Vector.h:443
int solve(const Operator< D > &A, Vector< D > &x, const Vector< D > &b, const Operator< D > *Mr=nullptr, bool output=false, std::ostream &os=std::cout) const override
Perform an iterative solve.
Definition: BiCGStab.h:126
virtual void apply(const Vector< D > &x, Vector< D > &b) const =0
Virtual function that base classes have to implement.
double twoNorm() const
get the l2norm
Definition: Vector.h:553
void add(const Vector< D > &b)
add the other vector to this vector
Definition: Vector.h:471
double getTolerance() const
Get the stopping tolerance.
Definition: BiCGStab.h:110
BiCGStab iterative solver.
Definition: BiCGStab.h:41
void setTimer(std::shared_ptr< Timer > timer_in)
Set the Timer object.
Definition: BiCGStab.h:116
std::shared_ptr< Timer > getTimer() const
Get the Timer object.
Definition: BiCGStab.h:123
Base class for operators.
Definition: Operator.h:37
Abstract interface for Iterative solvers.
Definition: Solver.h:39
Vector class for use in thunderegg.
Definition: Vector.h:42
double dot(const Vector< D > &b) const
get the dot product
Definition: Vector.h:583
Vector< D > getZeroClone() const
Get a vector of the same length initialized to zero.
Definition: Vector.h:601
BiCGStab< D > * clone() const override
Clone this solver.
Definition: BiCGStab.h:78