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;
76 vVEC.reserve(maxiter+1);
77 zVEC.reserve(maxiter+1);
81 double xnrm2 = dot_product(x, x);
88 precond.multiply(r, s);
90 double dotRr0 = dot_product(r, s);
91 double normReduction = 1.0;
92 double rdots = dotRr0;
93 double rdots_old = 0.0;
103 Log::info() << std::endl;
104 for (
int jiter = 0; jiter < maxiter; ++jiter) {
105 Log::info() <<
" PCG Starting Iteration " << jiter+1 << std::endl;
110 double beta = dot_product(s, r)/rdots_old;
111 Log::info() <<
"PCG beta = " << beta << std::endl;
119 double alpha = rdots/dot_product(p, ap);
125 for (
int iiter = 0; iiter < jiter; ++iiter) {
126 double proj = dot_product(r, zVEC[iiter]);
127 r.axpy(-proj, vVEC[iiter]);
130 precond.multiply(r, s);
133 rdots = dot_product(r, s);
142 normReduction = sqrt(rdots/dotRr0);
144 Log::info() <<
"PCG end of iteration " << jiter+1 <<
". Norm reduction= "
145 << util::full_precision(normReduction) << std::endl << std::endl;
147 if (normReduction < tolerance) {
148 Log::info() <<
"PCG: Achieved required reduction in residual norm." << std::endl;
153 Log::info() <<
"PCG: end" << std::endl;
155 return normReduction;
160 #endif // OOPS_ASSIMILATION_PCG_H_