13 #ifndef _GMRESSOLVER_H_ 14 #define _GMRESSOLVER_H_ 19 #include "NamespaceHeader.H" 57 virtual void solve(T& a_phi,
const T& a_rhs);
150 int &reason,
int &itcount,
Real &rnorm0,
151 const bool avoidnorms =
false);
154 const T &a_bb, T &a_temp );
165 void ApplyAB( T &a_dest,
const T &a_xx, T &a_temp )
const;
181 int hh = (max_k + 2) * (max_k + 1);
182 int hes = (max_k + 1) * (max_k + 1);
183 int rs = (max_k + 2);
184 int cc = (max_k + 1);
185 int size = (hh + hes + rs + 2*cc + 1);
248 #define HH(a,b) (m_hh + (b)*(m_restrtLen+2) + (a)) 249 #define HES(a,b) (m_hes + (b)*(m_restrtLen+1) + (a)) 250 #define CC(a) (m_ee + (a)) 251 #define SS(a) (m_dd + (a)) 252 #define GRS(a) (m_d + (a)) 256 #define VEC_TEMP_RHS m_work_arr[0] 257 #define VEC_TEMP_LHS m_work_arr[1] 258 #define VEC_VV(i) m_work_arr[VEC_OFFSET + i] 268 CH_TIMER(
"GMRESSolver::solve::Initialize",timeInitialize);
269 CH_TIMER(
"GMRESSolver::solve::MainLoop",timeMainLoop);
270 CH_TIMER(
"GMRESSolver::solve::Cleanup",timeCleanup);
276 pout() <<
"GMRESSolver::solve" << endl;
295 m_op->assign( vv_0, a_bb );
296 m_op->setToZero( a_xx );
335 for (
int i=0;i<nwork;i++)
349 #define CONVERGED(r0,r) (r<r0*m_reps || r<m_eps) 353 int &a_reason,
int &a_itcount,
Real &a_rnorm0,
354 const bool a_avoidnorms )
358 Real res_norm,hapbnd,tt;
375 pout() <<
"GMRESSolver::solve zero residual!!!" << endl;
382 m_op->scale( vv_0, tt);
386 a_reason = conv ? 1 : -1;
392 pout() << a_itcount <<
") GMRES residual = " <<
m_residual << endl;
395 const T &vv_it =
VEC_VV(it);
417 pout() <<
"Detected happy breakdown, "<<it<<
") current hapbnd = "<< tt << endl;
423 m_op->scale( vv_it1, 1./tt);
427 *
HH(it+1,it) = tt; *
HES(it+1,it) = tt;
434 a_reason = conv ? 1 : -1;
440 pout() <<
"You reached the happy break down, but convergence was not indicated. Residual norm=" <<
m_residual << endl;
448 pout() << a_itcount <<
") GMRES residual = " <<
m_residual << endl;
462 const T &a_bb, T &a_temp_rhs )
466 m_op->assign( a_vv, a_bb );
467 m_op->incr( a_vv, a_temp_rhs, -1.0);
483 if (*
HH(it,it) == 0.0)
485 pout() <<
"HH(it,it) is identically zero!!! GRS(it) = " << *
GRS(it) << endl;
487 if (*
HH(it,it) != 0.0)
489 nrs[it] = *
GRS(it) / *
HH(it,it);
496 for (ii=1; ii<=it; ii++)
500 for (j=k+1; j<=it; j++) tt = tt - *
HH(k,j) * nrs[j];
501 nrs[k] = tt / *
HH(k,k);
506 m_op->setToZero(temp);
508 for (ii=0; ii<it+1; ii++)
510 m_op->incr(temp, vv_0[ii], nrs[ii]);
517 m_op->preCond( temp_matop, temp );
518 m_op->incr( a_xx, temp_matop, 1.0 );
545 for (j=1; j<=it; j++)
548 *hh = *cc * tt + *ss * *(hh+1);
550 *hh = *cc++ * *hh - (*ss++ * tt);
561 tt = sqrt( *hh * *hh + *(hh+1) * *(hh+1) );
564 pout() <<
"Your matrix or preconditioner is the null operator\n";
568 *
GRS(it+1) = - (*ss * *
GRS(it));
569 *
GRS(it) = *cc * *
GRS(it);
570 *hh = *cc * *hh + *ss * *(hh+1);
658 Real *hh,*hes,*lhh = 0;
660 const T *vv_0 = &(
VEC_VV(0));
663 lhh =
new Real[it+1];
670 for (
int j=0; j<=it; j++)
676 for (
int ncnt = 0 ; ncnt < 2 ; ncnt++ )
687 m_op->mDotProduct(vv_1, it+1, vv_0, lhh);
693 for (
int j=0; j<=it; j++) lhh[j] = - lhh[j];
695 for (
int j=0; j<=it; j++)
697 m_op->incr(vv_1, vv_0[j], lhh[j]);
699 for (
int j=0; j<=it; j++)
715 m_op->preCond( a_tmp_lhs, a_xx );
726 #include "NamespaceFooter.H" std::ostream & pout()
Use this in place of std::cout for program output.
#define CH_TIMERS(name)
Definition: CH_Timer.H:133
Definition: LinearSolver.H:28
#define SS(a)
Definition: GMRESSolver.H:251
LinearOp< T > * m_op
Definition: GMRESSolver.H:91
Real * m_ee
Definition: GMRESSolver.H:169
virtual void setConvergenceMetrics(Real a_metric, Real a_tolerance)
Set a convergence metric, along with solver tolerance, if desired.
Definition: GMRESSolver.H:720
#define CH_assert(cond)
Definition: CHArray.H:37
void allocate()
Definition: GMRESSolver.H:178
int m_exitStatus
Definition: GMRESSolver.H:137
void ResidualGMRES(T &a_vv, const T &a_xx, const T &a_bb, T &a_temp)
Definition: GMRESSolver.H:461
Real * m_hes
Definition: GMRESSolver.H:169
Definition: GMRESSolver.H:29
T * m_work_arr
Definition: GMRESSolver.H:170
Real * m_data
Definition: GMRESSolver.H:168
#define CH_START(tpointer)
Definition: CH_Timer.H:145
#define HH(a, b)
Definition: GMRESSolver.H:248
Real * m_d
Definition: GMRESSolver.H:169
Real m_initial_residual
Definition: GMRESSolver.H:85
#define CONVERGED(r0, r)
Definition: GMRESSolver.H:349
void ApplyAB(T &a_dest, const T &a_xx, T &a_temp) const
Definition: GMRESSolver.H:713
int m_iter
Definition: GMRESSolver.H:71
void setRestartLen(int mm)
Definition: GMRESSolver.H:204
virtual void solve(T &a_phi, const T &a_rhs)
solve the equation.
Definition: GMRESSolver.H:264
#define CH_TIMER(name, tpointer)
Definition: CH_Timer.H:63
#define VEC_VV(i)
Definition: GMRESSolver.H:258
Real m_eps
Definition: GMRESSolver.H:121
void clearData()
Definition: GMRESSolver.H:198
double Real
Definition: REAL.H:33
Real m_residual
Definition: GMRESSolver.H:78
T Abs(const T &a_a)
Definition: Misc.H:53
virtual ~GMRESSolver()
Definition: GMRESSolver.H:232
virtual void setHomogeneous(bool a_homogeneous)
Definition: GMRESSolver.H:39
#define HES(a, b)
Definition: GMRESSolver.H:249
void TwoUnmodifiedGramSchmidtOrthogonalization(const int it)
Definition: GMRESSolver.H:656
#define VEC_TEMP_LHS
Definition: GMRESSolver.H:257
Real * m_dd
Definition: GMRESSolver.H:169
Real m_small
Definition: GMRESSolver.H:143
Real * m_hh
Definition: GMRESSolver.H:169
int m_verbosity
Definition: GMRESSolver.H:115
virtual void define(LinearOp< T > *a_op, bool a_homogeneous=true)
Definition: GMRESSolver.H:239
Definition: LinearSolver.H:156
#define GRS(a)
Definition: GMRESSolver.H:252
bool m_homogeneous
Definition: GMRESSolver.H:64
Real m_reps
Definition: GMRESSolver.H:127
#define CH_STOP(tpointer)
Definition: CH_Timer.H:150
int m_imax
Definition: GMRESSolver.H:109
GMRESSolver()
Definition: GMRESSolver.H:213
int m_normType
Definition: GMRESSolver.H:145
int restartLen() const
Definition: GMRESSolver.H:100
#define VEC_OFFSET
Definition: GMRESSolver.H:255
void CycleGMRES(T &xx, int &reason, int &itcount, Real &rnorm0, const bool avoidnorms=false)
Definition: GMRESSolver.H:352
void BuildGMRESSoln(Real nrs[], T &a_xx, const int it, const T vv_0[])
Definition: GMRESSolver.H:470
void UpdateGMRESHessenberg(const int it, bool hapend, Real &res)
Definition: GMRESSolver.H:534
#define CC(a)
Definition: GMRESSolver.H:250
int m_restrtLen
Definition: GMRESSolver.H:98
#define VEC_TEMP_RHS
Definition: GMRESSolver.H:256