349 if (!stateStorageInitialized_)
352 TEUCHOS_TEST_FOR_EXCEPTION(!stateStorageInitialized_,std::invalid_argument,
353 "LSQRIter::initialize(): Cannot initialize state storage!");
355 std::string errstr(
"LSQRIter::initialize(): Specified multivectors must have a consistent length and width.");
360 RCP<const MV> lhsMV = lp_->getLHS();
362 const bool debugSerialLSQR =
false;
364 if( debugSerialLSQR )
366 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> lhsNorm(1);
368 std::cout <<
"initializeLSQR lhsNorm " << lhsNorm[0] << std::endl;
372 RCP<const MV> rhsMV = lp_->getInitPrecResVec();
373 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
374 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
377 RCP<const OP> M_left = lp_->getLeftPrec();
378 RCP<const OP> A = lp_->getOperator();
379 RCP<const OP> M_right = lp_->getRightPrec();
381 if( debugSerialLSQR )
383 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> rhsNorm(1);
385 std::cout <<
"initializeLSQR | U_ | : " << rhsNorm[0] << std::endl;
397 if ( M_left.is_null())
410 if (! M_right.is_null())
421 frob_mat_norm_ = zero;
438 if (initialized_ ==
false) {
443 const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
444 const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
445 const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
448 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> alpha(1);
449 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> beta(1);
450 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> xi(1);
453 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> wnorm2(1);
454 ScalarType rhobar, phibar, cs1, phi, rho, cs, sn, theta, xxnorm = MTzero, common;
455 ScalarType zetabar, sn1, psi, res = zero, ddnorm = zero, gamma, tau;
456 ScalarType anorm2 = zero;
457 ScalarType cs2 = -one, sn2 = zero, gammabar, zeta = zero, delta;
462 Teuchos::RCP<MV> AtU;
464 const bool debugSerialLSQR =
false;
467 Teuchos::RCP<MV> cur_soln_vec = lp_->getCurrLHSVec();
472 "LSQRIter::iterate(): current linear system has more than one vector!" );
477 if( SCT::real(beta[0]) > zero )
490 if( debugSerialLSQR )
494 std::cout << iter_ <<
" First alpha " << alpha[0] <<
" beta " << beta[0] <<
" lambda " << lambda_ << std::endl;
496 if( SCT::real(alpha[0]) > zero )
500 if( beta[0] * alpha[0] > zero )
510 RCP<const OP> M_left = lp_->getLeftPrec();
511 RCP<const OP> A = lp_->getOperator();
512 RCP<const OP> M_right = lp_->getRightPrec();
517 resid_norm_ = beta[0];
518 mat_resid_norm_ = alpha[0] * beta[0];
532 if ( M_right.is_null() )
543 if (! M_left.is_null())
550 if ( !( M_left.is_null() && M_right.is_null() )
551 && debugSerialLSQR && iter_ == 1)
557 if (! M_left.is_null())
567 if ( !( M_right.is_null() ) )
575 std::cout <<
"| V alpha - A' u |= " << xi[0] << std::endl;
577 Teuchos::SerialDenseMatrix<int,ScalarType> uotuo(1,1);
579 std::cout <<
"<U, U> = " << printMat(uotuo) << std::endl;
581 std::cout <<
"alpha = " << alpha[0] << std::endl;
583 Teuchos::SerialDenseMatrix<int,ScalarType> utav(1,1);
585 std::cout <<
"<AV, U> = alpha = " << printMat(utav) << std::endl;
591 anorm2 += alpha[0]*alpha[0] + beta[0]*beta[0] + lambda_*lambda_;
594 if ( SCT::real(beta[0]) > zero )
599 if (M_left.is_null())
609 if (! M_right.is_null())
623 if ( SCT::real(alpha[0]) > zero )
630 common = Teuchos::ScalarTraits< ScalarType >::squareroot(rhobar*rhobar + lambda_*lambda_);
631 cs1 = rhobar / common;
632 sn1 = lambda_ / common;
634 phibar = cs1 * phibar;
638 rho = Teuchos::ScalarTraits< ScalarType >::squareroot(rhobar*rhobar + lambda_*lambda_ + beta[0]*beta[0]);
641 theta = sn * alpha[0];
642 rhobar = -cs * alpha[0];
644 phibar = sn * phibar;
648 gammabar = -cs2 * rho;
649 zetabar = (phi - delta*zeta) / gammabar;
650 sol_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(xxnorm + zetabar*zetabar);
651 gamma = Teuchos::ScalarTraits< ScalarType >::squareroot(gammabar*gammabar + theta*theta);
652 cs2 = gammabar / gamma;
654 zeta = (phi - delta*zeta) / gamma;
658 if ( M_right.is_null())
660 MVT::MvAddMv( phi / rho, *W_, one, *cur_soln_vec, *cur_soln_vec);
666 MVT::MvAddMv( phi / rho, *tempInDomainOfA, one, *cur_soln_vec, *cur_soln_vec);
670 ddnorm += (one / rho)*(one / rho) * wnorm2[0]*wnorm2[0];
673 frob_mat_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(anorm2);
674 mat_cond_num_ = frob_mat_norm_ * Teuchos::ScalarTraits< ScalarType >::squareroot(ddnorm);
676 resid_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(phibar*phibar + res);
677 mat_resid_norm_ = alpha[0] * Teuchos::ScalarTraits< ScalarType >::magnitude(tau);