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;
545 Teuchos::SerialDenseMatrix<int,ScalarType> uotuo(1,1);
547 std::cout <<
"<U, U> = " << printMat(uotuo) << std::endl;
549 std::cout <<
"alpha = " << alpha[0] << std::endl;
551 Teuchos::SerialDenseMatrix<int,ScalarType> utav(1,1);
553 std::cout <<
"<AV, U> = alpha = " << printMat(utav) << std::endl;
559 anorm2 += alpha[0]*alpha[0] + beta[0]*beta[0] + lambda_*lambda_;
562 if ( SCT::real(beta[0]) > zero )
567 if (M_left.is_null())
577 if (! M_right.is_null())
591 if ( SCT::real(alpha[0]) > zero )
598 common = Teuchos::ScalarTraits< ScalarType >::squareroot(rhobar*rhobar + lambda_*lambda_);
599 cs1 = rhobar / common;
600 sn1 = lambda_ / common;
602 phibar = cs1 * phibar;
606 rho = Teuchos::ScalarTraits< ScalarType >::squareroot(rhobar*rhobar + lambda_*lambda_ + beta[0]*beta[0]);
609 theta = sn * alpha[0];
610 rhobar = -cs * alpha[0];
612 phibar = sn * phibar;
616 gammabar = -cs2 * rho;
617 zetabar = (phi - delta*zeta) / gammabar;
618 sol_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(xxnorm + zetabar*zetabar);
619 gamma = Teuchos::ScalarTraits< ScalarType >::squareroot(gammabar*gammabar + theta*theta);
620 cs2 = gammabar / gamma;
622 zeta = (phi - delta*zeta) / gamma;
626 if ( M_right.is_null())
628 MVT::MvAddMv( phi / rho, *W_, one, *cur_soln_vec, *cur_soln_vec);
634 MVT::MvAddMv( phi / rho, *tempInDomainOfA, one, *cur_soln_vec, *cur_soln_vec);
638 ddnorm += (one / rho)*(one / rho) * wnorm2[0]*wnorm2[0];
641 frob_mat_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(anorm2);
642 mat_cond_num_ = frob_mat_norm_ * Teuchos::ScalarTraits< ScalarType >::squareroot(ddnorm);
644 resid_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(phibar*phibar + res);
645 mat_resid_norm_ = alpha[0] * Teuchos::ScalarTraits< ScalarType >::magnitude(tau);