317 if (!stateStorageInitialized_)
320 TEUCHOS_TEST_FOR_EXCEPTION(!stateStorageInitialized_,std::invalid_argument,
321 "LSQRIter::initialize(): Cannot initialize state storage!");
323 std::string errstr(
"LSQRIter::initialize(): Specified multivectors must have a consistent length and width.");
328 RCP<const MV> lhsMV = lp_->getLHS();
330 const bool debugSerialLSQR =
false;
332 if( debugSerialLSQR )
334 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> lhsNorm(1);
336 std::cout <<
"initializeLSQR lhsNorm " << lhsNorm[0] << std::endl;
340 RCP<const MV> rhsMV = lp_->getInitPrecResVec();
341 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
342 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
345 RCP<const OP> M_left = lp_->getLeftPrec();
346 RCP<const OP> A = lp_->getOperator();
347 RCP<const OP> M_right = lp_->getRightPrec();
349 if( debugSerialLSQR )
351 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> rhsNorm(1);
353 std::cout <<
"initializeLSQR | U_ | : " << rhsNorm[0] << std::endl;
365 if ( M_left.is_null())
378 if (! M_right.is_null())
389 frob_mat_norm_ = zero;
406 if (initialized_ ==
false) {
411 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
412 const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
413 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
416 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> alpha(1);
417 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> beta(1);
418 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> xi(1);
421 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> wnorm2(1);
422 ScalarType rhobar, phibar, cs1, phi, rho, cs, sn, theta, xxnorm = MTzero, common;
423 ScalarType zetabar, sn1, psi, res = zero, ddnorm = zero, gamma, tau;
424 ScalarType anorm2 = zero;
425 ScalarType cs2 = -one, sn2 = zero, gammabar, zeta = zero, delta;
430 Teuchos::RCP<MV> AtU;
432 const bool debugSerialLSQR =
false;
435 Teuchos::RCP<MV> cur_soln_vec = lp_->getCurrLHSVec();
440 "LSQRIter::iterate(): current linear system has more than one vector!" );
445 if( SCT::real(beta[0]) > zero )
458 if( debugSerialLSQR )
462 std::cout << iter_ <<
" First alpha " << alpha[0] <<
" beta " << beta[0] <<
" lambda " << lambda_ << std::endl;
464 if( SCT::real(alpha[0]) > zero )
468 if( beta[0] * alpha[0] > zero )
478 RCP<const OP> M_left = lp_->getLeftPrec();
479 RCP<const OP> A = lp_->getOperator();
480 RCP<const OP> M_right = lp_->getRightPrec();
485 resid_norm_ = beta[0];
486 mat_resid_norm_ = alpha[0] * beta[0];
500 if ( M_right.is_null() )
511 if (! M_left.is_null())
518 if ( !( M_left.is_null() && M_right.is_null() )
519 && debugSerialLSQR && iter_ == 1)
525 if (! M_left.is_null())
535 if ( !( M_right.is_null() ) )
543 std::cout <<
"| V alpha - A' u |= " << xi[0] << std::endl;
550 std::cout <<
"alpha = " << alpha[0] << std::endl;
555 std::cout <<
"<AV, U> = alpha = " <<
DMT::ValueConst(*utav,0,0) << std::endl;
561 anorm2 += alpha[0]*alpha[0] + beta[0]*beta[0] + lambda_*lambda_;
564 if ( SCT::real(beta[0]) > zero )
569 if (M_left.is_null())
579 if (! M_right.is_null())
593 if ( SCT::real(alpha[0]) > zero )
600 common = Teuchos::ScalarTraits< ScalarType >::squareroot(rhobar*rhobar + lambda_*lambda_);
601 cs1 = rhobar / common;
602 sn1 = lambda_ / common;
604 phibar = cs1 * phibar;
608 rho = Teuchos::ScalarTraits< ScalarType >::squareroot(rhobar*rhobar + lambda_*lambda_ + beta[0]*beta[0]);
611 theta = sn * alpha[0];
612 rhobar = -cs * alpha[0];
614 phibar = sn * phibar;
618 gammabar = -cs2 * rho;
619 zetabar = (phi - delta*zeta) / gammabar;
620 sol_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(xxnorm + zetabar*zetabar);
621 gamma = Teuchos::ScalarTraits< ScalarType >::squareroot(gammabar*gammabar + theta*theta);
622 cs2 = gammabar / gamma;
624 zeta = (phi - delta*zeta) / gamma;
628 if ( M_right.is_null())
630 MVT::MvAddMv( phi / rho, *W_, one, *cur_soln_vec, *cur_soln_vec);
636 MVT::MvAddMv( phi / rho, *tempInDomainOfA, one, *cur_soln_vec, *cur_soln_vec);
640 ddnorm += (one / rho)*(one / rho) * wnorm2[0]*wnorm2[0];
643 frob_mat_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(anorm2);
644 mat_cond_num_ = frob_mat_norm_ * Teuchos::ScalarTraits< ScalarType >::squareroot(ddnorm);
646 resid_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(phibar*phibar + res);
647 mat_resid_norm_ = alpha[0] * Teuchos::ScalarTraits< ScalarType >::magnitude(tau);