13 #ifndef _BICGSTABSOLVER_H_ 14 #define _BICGSTABSOLVER_H_ 19 #include "NamespaceHeader.H" 48 virtual void solve(T& a_phi,
const T& a_rhs);
203 CH_TIMER(
"BiCGStabSolver::solve::Initialize",timeInitialize);
204 CH_TIMER(
"BiCGStabSolver::solve::MainLoop",timeMainLoop);
205 CH_TIMER(
"BiCGStabSolver::solve::Cleanup",timeCleanup);
209 T r, r_tilde, e, p, p_tilde, s_tilde, t, v;
211 m_op->create(r, a_rhs);
212 m_op->create(r_tilde, a_rhs);
213 m_op->create(e, a_phi);
214 m_op->create(p, a_rhs);
215 m_op->create(p_tilde, a_phi);
216 m_op->create(s_tilde, a_phi);
217 m_op->create(t, a_rhs);
218 m_op->create(v, a_rhs);
227 m_op->assignLocal(r_tilde, r);
231 m_op->setToZero(p_tilde);
232 m_op->setToZero(s_tilde);
243 Real initial_norm = norm[0];
266 pout() <<
" BiCGStab:: initial Residual norm = " 267 << initial_norm <<
"\n";
291 pout() <<
" BiCGStab:: norm[0] = " << norm[0] <<
", " 292 <<
"norm[1] = " << norm[1]
294 pout() <<
" BiCGStab:: alpha[0] = " << alpha[0] <<
", " 295 <<
"alpha[1] = " << alpha[1]
297 pout() <<
" BiCGStab:: beta[0] = " << beta[0] <<
", " 298 <<
"beta[1] = " << beta[1]
300 pout() <<
" BiCGStab:: omega[0] = " << omega[0] <<
", " 301 <<
"omega[1] = " << omega[1]
307 rho[1] =
m_op->dotProduct(r_tilde, r);
311 pout() <<
" BiCGStab:: rho[1] = " << rho[1] <<
", " 312 <<
"rho[2] = " << rho[2] <<
", " 313 <<
"rho[3] = " << rho[3]
320 m_op->incr(a_phi, e, 1.0);
324 pout() <<
" BiCGStab:: rho = 0, returning" 325 <<
" -- Residual norm = " 340 m_op->clear(r_tilde);
343 m_op->clear(p_tilde);
344 m_op->clear(s_tilde);
355 m_op->assignLocal(p, r);
360 beta[1] = (rho[1]/rho[2])*(alpha[1]/omega[1]);
361 m_op->scale(p, beta[1]);
362 m_op->incr(p, v, -beta[1]*omega[1]);
363 m_op->incr(p, r, 1.0);
368 pout() <<
" BiCGStab:: beta[1] = " << beta[1]
372 m_op->preCond(p_tilde, p);
374 m_op->applyOp(v, p_tilde,
true);
375 Real m =
m_op->dotProduct(r_tilde, v);
380 pout() <<
" BiCGStab:: rho[1] = " << rho[1] <<
", " 381 <<
"m = " << m <<
", " 382 <<
"alpha[0] = " << alpha[0]
388 m_op->incr(r, v, -alpha[0]);
390 m_op->incr(e, p_tilde, alpha[0]);
400 pout() <<
"norm[0] = " << norm[0]
401 <<
" initial_norm = " << initial_norm
408 m_op->preCond(s_tilde, r);
410 m_op->applyOp(t, s_tilde,
true);
411 omega[0] =
m_op->dotProduct(t, r)/
m_op->dotProduct(t, t);
412 m_op->incr(e, s_tilde, omega[0]);
413 m_op->incr(r, t, -omega[0]);
419 pout() <<
" BiCGStab:: iteration = " <<
m_iter <<
", error norm = " << norm[0] <<
", rate = " << norm[1]/norm[0] <<
"\n";
423 if (norm[0] <=
m_eps*initial_norm || norm[0] <=
m_reps*m_initial_residual)
430 if (omega[0] == 0.0 || norm[0] > (1-
m_hang)*norm[1])
439 m_op->incr(a_phi, e, 1.0);
445 pout() <<
" BiCGStab: max restarts reached" << endl;
446 pout() <<
" init norm = " << initial_norm << endl;
447 pout() <<
" final norm = " << norm[0] << endl;
460 m_op->clear(r_tilde);
463 m_op->clear(p_tilde);
464 m_op->clear(s_tilde);
474 CH_TIME(
"BiCGStabSolver::solve::Restart");
478 rho[1]=0.0; rho[1]=0.0; rho[2]=0.0; rho[3]=0.0;
479 alpha[0]=0; beta[0]=0; omega[0]=0;
480 m_op->assignLocal(r_tilde, r);
488 pout() <<
" BiCGStab:: restart = " << restarts <<
"\n";
501 pout() <<
" BiCGStab:: " <<
m_iter <<
" iterations, final Residual norm = " 507 m_op->incr(a_phi, e, 1.0);
510 m_op->clear(r_tilde);
513 m_op->clear(p_tilde);
514 m_op->clear(s_tilde);
529 #include "NamespaceFooter.H" std::ostream & pout()
Use this in place of std::cout for program output.
virtual void setConvergenceMetrics(Real a_metric, Real a_tolerance)
Set a convergence metric, along with solver tolerance, if desired.
Definition: BiCGStabSolver.H:522
#define CH_TIMERS(name)
Definition: CH_Timer.H:133
Real m_convergenceMetric
Definition: BiCGStabSolver.H:97
Real m_eps
Definition: BiCGStabSolver.H:84
Definition: LinearSolver.H:28
int m_imax
Definition: BiCGStabSolver.H:71
#define CH_assert(cond)
Definition: CHArray.H:37
LinearOp< T > * m_op
Definition: BiCGStabSolver.H:65
int m_verbosity
Definition: BiCGStabSolver.H:78
Real m_residual
Definition: BiCGStabSolver.H:127
Real norm(const BoxLayoutData< FArrayBox > &A, const Interval &interval, const int &p=2)
#define CH_START(tpointer)
Definition: CH_Timer.H:145
Real m_reps
Definition: BiCGStabSolver.H:90
int m_exitStatus
Definition: BiCGStabSolver.H:113
#define CH_TIMER(name, tpointer)
Definition: CH_Timer.H:63
Real m_hang
Definition: BiCGStabSolver.H:103
int m_normType
Definition: BiCGStabSolver.H:153
#define CH_TIME(name)
Definition: CH_Timer.H:82
virtual ~BiCGStabSolver()
Definition: BiCGStabSolver.H:186
double Real
Definition: REAL.H:33
int m_numRestarts
Definition: BiCGStabSolver.H:146
int m_iter
Definition: BiCGStabSolver.H:120
T Abs(const T &a_a)
Definition: Misc.H:53
virtual void solve(T &a_phi, const T &a_rhs)
solve the equation.
Definition: BiCGStabSolver.H:199
Definition: LinearSolver.H:156
#define CH_STOP(tpointer)
Definition: CH_Timer.H:150
Real m_initial_residual
Definition: BiCGStabSolver.H:134
virtual void define(LinearOp< T > *a_op, bool a_homogeneous)
Definition: BiCGStabSolver.H:192
BiCGStabSolver()
Definition: BiCGStabSolver.H:166
virtual void setHomogeneous(bool a_homogeneous)
Definition: BiCGStabSolver.H:34
Real m_small
Definition: BiCGStabSolver.H:140
bool m_homogeneous
Definition: BiCGStabSolver.H:59
Definition: BiCGStabSolver.H:26