11 #ifndef OOPS_ASSIMILATION_PLANCZOS_H_ 12 #define OOPS_ASSIMILATION_PLANCZOS_H_ 18 #include "oops/util/dot_product.h" 19 #include "oops/util/formats.h" 20 #include "oops/util/Logger.h" 61 template <
typename VECTOR,
typename AMATRIX,
typename PMATRIX>
63 const AMATRIX & A,
const PMATRIX & precond,
64 const int maxiter,
const double tolerance) {
68 std::vector<VECTOR> vVEC;
69 std::vector<VECTOR> zVEC;
70 std::vector<double> alphas;
71 std::vector<double> betas;
72 std::vector<double> dd;
73 std::vector<double> yy;
77 double xnrm2 = dot_product(xx, xx);
84 precond.multiply(rr, zz);
86 double normReduction = 1.0;
87 double beta0 = sqrt(dot_product(rr, zz));
99 for (jiter = 0; jiter < maxiter; ++jiter) {
100 Log::info() <<
" PLanczos Starting Iteration " << jiter+1 << std::endl;
104 if (jiter > 0) ww.axpy(-
beta, vVEC[jiter-1]);
106 double alpha = dot_product(zz, ww);
111 for (
int iiter = 0; iiter < jiter; ++iiter) {
112 double proj = dot_product(ww, zVEC[iiter]);
113 ww.axpy(-proj, vVEC[iiter]);
116 precond.multiply(ww, zz);
118 beta = sqrt(dot_product(zz, ww));
127 alphas.push_back(
alpha);
130 yy.push_back(beta0/
alpha);
134 dd.push_back(beta0*dot_product(zVEC[0], vv));
139 double rznorm =
beta*std::abs(yy[jiter]);
141 normReduction = rznorm/beta0;
143 betas.push_back(
beta);
145 Log::info() <<
"PLanczos end of iteration " << jiter+1 <<
". Norm reduction= " 146 << util::full_precision(normReduction) << std::endl << std::endl;
149 Log::info() <<
"PLanczos: Achieved required reduction in residual norm." << std::endl;
155 for (
int iiter = 0; iiter < jiter; ++iiter) {
156 xx.axpy(yy[iiter], zVEC[iiter]);
159 Log::info() <<
"PLanczos: end" << std::endl;
161 return normReduction;
166 #endif // OOPS_ASSIMILATION_PLANCZOS_H_ real, dimension(:,:), allocatable, private bb
double PLanczos(VECTOR &xx, const VECTOR &bb, const AMATRIX &A, const PMATRIX &precond, const int maxiter, const double tolerance)
void TriDiagSolve(const std::vector< double > &diag, const std::vector< double > &sub, const std::vector< double > &rhs, std::vector< double > &sol)
The namespace for the main oops code.
subroutine, public info(self)
real(fp), parameter, public tolerance