11 #ifndef OOPS_ASSIMILATION_PCG_H_ 12 #define OOPS_ASSIMILATION_PCG_H_ 17 #include "oops/util/dot_product.h" 18 #include "oops/util/formats.h" 19 #include "oops/util/Logger.h" 62 template <
typename VECTOR,
typename AMATRIX,
typename PMATRIX>
63 double PCG(VECTOR & x,
const VECTOR &
b,
64 const AMATRIX & A,
const PMATRIX & precond,
65 const int maxiter,
const double tolerance ) {
73 std::vector<VECTOR> vVEC;
74 std::vector<VECTOR> zVEC;
78 double xnrm2 = dot_product(x, x);
85 precond.multiply(r, s);
87 double dotRr0 = dot_product(r, s);
88 double normReduction = 1.0;
89 double rdots = dotRr0;
90 double rdots_old = 0.0;
101 for (
int jiter = 0; jiter < maxiter; ++jiter) {
102 Log::info() <<
" PCG Starting Iteration " << jiter+1 << std::endl;
107 double beta = dot_product(s, r)/rdots_old;
116 double alpha = rdots/dot_product(
p, ap);
122 for (
int iiter = 0; iiter < jiter; ++iiter) {
123 double proj = dot_product(r, zVEC[iiter]);
124 r.axpy(-proj, vVEC[iiter]);
127 precond.multiply(r, s);
130 rdots = dot_product(r, s);
139 normReduction = sqrt(rdots/dotRr0);
141 Log::info() <<
"PCG end of iteration " << jiter+1 <<
". Norm reduction= " 142 << util::full_precision(normReduction) << std::endl << std::endl;
145 Log::info() <<
"PCG: Achieved required reduction in residual norm." << std::endl;
152 return normReduction;
157 #endif // OOPS_ASSIMILATION_PCG_H_
real(r8), dimension(cast_m, cast_n) p
The namespace for the main oops code.
subroutine, public info(self)
real(fp), parameter, public tolerance
double PCG(VECTOR &x, const VECTOR &b, const AMATRIX &A, const PMATRIX &precond, const int maxiter, const double tolerance)