13 #ifndef _GMRESSOLVER_H_ 14 #define _GMRESSOLVER_H_ 19 #include "NamespaceHeader.H" 57 virtual void solve(T& a_phi,
const T& a_rhs);
129 int &reason,
int &itcount,
Real &rnorm0,
130 const bool avoidnorms =
false);
133 const T &a_bb, T &a_temp );
144 void ApplyAB( T &a_dest,
const T &a_xx, T &a_temp )
const;
160 int hh = (max_k + 2) * (max_k + 1);
161 int hes = (max_k + 1) * (max_k + 1);
162 int rs = (max_k + 2);
163 int cc = (max_k + 1);
164 int size = (hh + hes + rs + 2*cc + 1);
224 #define HH(a,b) (m_hh + (b)*(m_restrtLen+2) + (a)) 225 #define HES(a,b) (m_hes + (b)*(m_restrtLen+1) + (a)) 226 #define CC(a) (m_ee + (a)) 227 #define SS(a) (m_dd + (a)) 228 #define GRS(a) (m_d + (a)) 232 #define VEC_TEMP_RHS m_work_arr[0] 233 #define VEC_TEMP_LHS m_work_arr[1] 234 #define VEC_VV(i) m_work_arr[VEC_OFFSET + i] 244 CH_TIMER(
"GMRESSolver::solve::Initialize",timeInitialize);
245 CH_TIMER(
"GMRESSolver::solve::MainLoop",timeMainLoop);
246 CH_TIMER(
"GMRESSolver::solve::Cleanup",timeCleanup);
252 pout() <<
"GMRESSolver::solve" << endl;
269 m_op->assign( vv_0, a_bb );
270 m_op->setToZero( a_xx );
307 for (
int i=0;i<nwork;i++)
321 #define CONVERGED(r0,r) (r<r0*m_reps || r<m_eps) 325 int &a_reason,
int &a_itcount,
Real &a_rnorm0,
326 const bool a_avoidnorms )
329 Real res_norm,res,hapbnd,tt;
345 pout() <<
"GMRESSolver::solve zero residual!!!" << endl;
352 m_op->scale( vv_0, tt);
354 if ( a_itcount == 0 ) a_rnorm0 = res;
356 a_reason = conv ? 1 : -1;
362 pout() << a_itcount <<
") GMRES residual = " << res << endl;
365 const T &vv_it =
VEC_VV(it);
387 pout() <<
"Detected happy breakdown, "<<it<<
") current hapbnd = "<< tt << endl;
393 m_op->scale( vv_it1, 1./tt);
397 *
HH(it+1,it) = tt; *
HES(it+1,it) = tt;
404 a_reason = conv ? 1 : -1;
410 pout() <<
"You reached the happy break down, but convergence was not indicated. Residual norm=" << res << endl;
418 pout() << a_itcount <<
") GMRES residual = " << res << endl;
432 const T &a_bb, T &a_temp_rhs )
435 m_op->applyOp( a_temp_rhs, a_xx,
true);
436 m_op->assign( a_vv, a_bb );
437 m_op->incr( a_vv, a_temp_rhs, -1.0);
453 if (*
HH(it,it) == 0.0)
455 pout() <<
"HH(it,it) is identically zero!!! GRS(it) = " << *
GRS(it) << endl;
457 if (*
HH(it,it) != 0.0)
459 nrs[it] = *
GRS(it) / *
HH(it,it);
466 for (ii=1; ii<=it; ii++)
470 for (j=k+1; j<=it; j++) tt = tt - *
HH(k,j) * nrs[j];
471 nrs[k] = tt / *
HH(k,k);
476 m_op->setToZero(temp);
478 for (ii=0; ii<it+1; ii++)
480 m_op->incr(temp, vv_0[ii], nrs[ii]);
487 m_op->preCond( temp_matop, temp );
488 m_op->incr( a_xx, temp_matop, 1.0 );
515 for (j=1; j<=it; j++)
518 *hh = *cc * tt + *ss * *(hh+1);
520 *hh = *cc++ * *hh - (*ss++ * tt);
531 tt = sqrt( *hh * *hh + *(hh+1) * *(hh+1) );
534 pout() <<
"Your matrix or preconditioner is the null operator\n";
538 *
GRS(it+1) = - (*ss * *
GRS(it));
539 *
GRS(it) = *cc * *
GRS(it);
540 *hh = *cc * *hh + *ss * *(hh+1);
541 res = fabs( *
GRS(it+1) );
628 Real *hh,*hes,*lhh = 0;
630 const T *vv_0 = &(
VEC_VV(0));
633 lhh =
new Real[it+1];
640 for (
int j=0; j<=it; j++)
646 for (
int ncnt = 0 ; ncnt < 2 ; ncnt++ )
657 m_op->mDotProduct(vv_1, it+1, vv_0, lhh);
663 for (
int j=0; j<=it; j++) lhh[j] = - lhh[j];
665 for (
int j=0; j<=it; j++)
667 m_op->incr(vv_1, vv_0[j], lhh[j]);
669 for (
int j=0; j<=it; j++)
685 m_op->preCond( a_tmp_lhs, a_xx );
686 m_op->applyOp( a_dest, a_tmp_lhs,
true);
696 #include "NamespaceFooter.H" std::ostream & pout()
Use this in place of std::cout for program output.
#define CH_TIMERS(name)
Definition: CH_Timer.H:70
Definition: LinearSolver.H:28
#define SS(a)
Definition: GMRESSolver.H:227
LinearOp< T > * m_op
Definition: GMRESSolver.H:70
Real * m_ee
Definition: GMRESSolver.H:148
virtual void setConvergenceMetrics(Real a_metric, Real a_tolerance)
Set a convergence metric, along with solver tolerance, if desired.
Definition: GMRESSolver.H:690
#define CH_assert(cond)
Definition: CHArray.H:37
void allocate()
Definition: GMRESSolver.H:157
int m_exitStatus
Definition: GMRESSolver.H:116
void ResidualGMRES(T &a_vv, const T &a_xx, const T &a_bb, T &a_temp)
Definition: GMRESSolver.H:431
Real * m_hes
Definition: GMRESSolver.H:148
Definition: GMRESSolver.H:29
T * m_work_arr
Definition: GMRESSolver.H:149
Real * m_data
Definition: GMRESSolver.H:147
#define CH_START(tpointer)
Definition: CH_Timer.H:78
#define HH(a, b)
Definition: GMRESSolver.H:224
Real * m_d
Definition: GMRESSolver.H:148
#define CONVERGED(r0, r)
Definition: GMRESSolver.H:321
void ApplyAB(T &a_dest, const T &a_xx, T &a_temp) const
Definition: GMRESSolver.H:683
void setRestartLen(int mm)
Definition: GMRESSolver.H:183
virtual void solve(T &a_phi, const T &a_rhs)
solve the equation.
Definition: GMRESSolver.H:240
#define CH_TIMER(name, tpointer)
Definition: CH_Timer.H:55
#define VEC_VV(i)
Definition: GMRESSolver.H:234
Real m_eps
Definition: GMRESSolver.H:100
void clearData()
Definition: GMRESSolver.H:177
double Real
Definition: REAL.H:33
virtual ~GMRESSolver()
Definition: GMRESSolver.H:208
virtual void setHomogeneous(bool a_homogeneous)
Definition: GMRESSolver.H:39
#define HES(a, b)
Definition: GMRESSolver.H:225
void TwoUnmodifiedGramSchmidtOrthogonalization(const int it)
Definition: GMRESSolver.H:626
#define VEC_TEMP_LHS
Definition: GMRESSolver.H:233
Real * m_dd
Definition: GMRESSolver.H:148
Real m_small
Definition: GMRESSolver.H:122
Real * m_hh
Definition: GMRESSolver.H:148
int m_verbosity
Definition: GMRESSolver.H:94
virtual void define(LinearOp< T > *a_op, bool a_homogeneous=true)
Definition: GMRESSolver.H:215
Definition: LinearSolver.H:158
#define GRS(a)
Definition: GMRESSolver.H:228
bool m_homogeneous
Definition: GMRESSolver.H:64
Real m_reps
Definition: GMRESSolver.H:106
#define CH_STOP(tpointer)
Definition: CH_Timer.H:80
int m_imax
Definition: GMRESSolver.H:88
GMRESSolver()
Definition: GMRESSolver.H:192
int m_normType
Definition: GMRESSolver.H:124
int restartLen() const
Definition: GMRESSolver.H:79
#define VEC_OFFSET
Definition: GMRESSolver.H:231
void CycleGMRES(T &xx, int &reason, int &itcount, Real &rnorm0, const bool avoidnorms=false)
Definition: GMRESSolver.H:324
void BuildGMRESSoln(Real nrs[], T &a_xx, const int it, const T vv_0[])
Definition: GMRESSolver.H:440
void UpdateGMRESHessenberg(const int it, bool hapend, Real &res)
Definition: GMRESSolver.H:504
#define CC(a)
Definition: GMRESSolver.H:226
int m_restrtLen
Definition: GMRESSolver.H:77
#define VEC_TEMP_RHS
Definition: GMRESSolver.H:232