Belos  Version of the Day
BelosLSQRIter.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
42 #ifndef BELOS_LSQR_ITER_HPP
43 #define BELOS_LSQR_ITER_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 #include "BelosLSQRIteration.hpp"
52 
53 #include "BelosLinearProblem.hpp"
54 #include "BelosOutputManager.hpp"
55 #include "BelosStatusTest.hpp"
56 #include "BelosOperatorTraits.hpp"
57 #include "BelosMultiVecTraits.hpp"
58 //#include "BelosMatOrthoManager.hpp" (needed for blocks)
59 
60 //#include "Teuchos_BLAS.hpp" (needed for blocks)
61 #include "Teuchos_SerialDenseMatrix.hpp"
62 #include "Teuchos_SerialDenseVector.hpp"
63 #include "Teuchos_ScalarTraits.hpp"
64 #include "Teuchos_ParameterList.hpp"
65 #include "Teuchos_TimeMonitor.hpp"
66 
74 namespace Belos {
75 
76 template<class ScalarType, class MV, class OP>
77 class LSQRIter : virtual public Belos::Iteration<ScalarType,MV,OP> {
78 
79  public:
80 
81  //
82  // Convenience typedefs
83  //
86  typedef Teuchos::ScalarTraits<ScalarType> SCT;
87  typedef typename SCT::magnitudeType MagnitudeType;
88 
90 
91 
98  LSQRIter( const Teuchos::RCP<Belos::LinearProblem<ScalarType,MV,OP> > &problem,
99  const Teuchos::RCP<Belos::OutputManager<ScalarType> > &printer,
100  const Teuchos::RCP<Belos::StatusTest<ScalarType,MV,OP> > &tester,
101  Teuchos::ParameterList &params );
102 
103 // If either blocks or reorthogonalization exist, then
104 // const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho,
105 
106 
108  virtual ~LSQRIter() {};
110 
111 
113 
114 
126  void iterate();
127 
138 
141  void initialize()
142  {
144  initializeLSQR(empty);
145  }
146 
156  state.U = U_; // right Lanczos vector
157  state.V = V_; // left Lanczos vector
158  state.W = W_; // OP * V
159  state.lambda = lambda_;
160  state.resid_norm = resid_norm_;
161  state.frob_mat_norm = frob_mat_norm_;
162  state.mat_cond_num = mat_cond_num_;
163  state.mat_resid_norm = mat_resid_norm_;
164  state.sol_norm = sol_norm_;
165  state.bnorm = bnorm_;
166  return state;
167  }
168 
170 
171 
173 
174 
176  int getNumIters() const { return iter_; }
177 
179  void resetNumIters( int iter = 0 ) { iter_ = iter; }
180 
183  Teuchos::RCP<const MV> getNativeResiduals( std::vector<MagnitudeType> *norms ) const { return Teuchos::null; }
184 
186 
188  Teuchos::RCP<MV> getCurrentUpdate() const { return Teuchos::null; }
189 
191 
193 
194 
196  const Belos::LinearProblem<ScalarType,MV,OP>& getProblem() const { return *lp_; }
197 
199  int getBlockSize() const { return 1; }
200 
201 
203  //This is unique to single vector methods.
204  void setBlockSize(int blockSize) {
205  TEUCHOS_TEST_FOR_EXCEPTION(blockSize!=1,std::invalid_argument,
206  "LSQRIter::setBlockSize(): Cannot use a block size that is not one.");
207  }
208 
210  bool isInitialized() { return initialized_; }
211 
213 
214  private:
215 
216  //
217  // Internal methods
218  //
220  void setStateSize();
221 
222  //
223  // Classes inputed through constructor that define the linear problem to be solved.
224  //
225  const Teuchos::RCP<Belos::LinearProblem<ScalarType,MV,OP> > lp_;
226  const Teuchos::RCP<Belos::OutputManager<ScalarType> > om_;
227  const Teuchos::RCP<Belos::StatusTest<ScalarType,MV,OP> > stest_;
228 // const Teuchos::RCP<OrthoManager<ScalarType,MV> > ortho_;
229 
230  //
231  // Current solver state
232  //
233  // initialized_ specifies that the basis vectors have been initialized and the iterate()
234  // routine is capable of running; _initialize is controlled by the initialize() member
235  // method. For the implications of the state of initialized_, please see documentation
236  // for initialize()
237  bool initialized_;
238 
239  // stateStorageInitialized_ specifies that the state storage has been initialized.
240  // This initialization may be postponed if the linear problem was generated without
241  // the right-hand side or solution vectors.
242  bool stateStorageInitialized_;
243 
244  // Current number of iterations performed.
245  int iter_;
246 
247  //
248  // State Storage
249  //
250  //
251  // Bidiagonalization vector
252  Teuchos::RCP<MV> U_;
253  //
254  // Bidiagonalization vector
255  Teuchos::RCP<MV> V_;
256  //
257  // Direction vector
258  Teuchos::RCP<MV> W_;
259  //
260  // Damping value
261  MagnitudeType lambda_;
262  //
263  // Residual norm estimate
264  ScalarType resid_norm_;
265  //
266  // Frobenius norm estimate
267  ScalarType frob_mat_norm_;
268  //
269  // Condition number estimate
270  ScalarType mat_cond_num_;
271  //
272  // A^T*resid norm estimate
273  ScalarType mat_resid_norm_;
274  //
275  // Solution norm estimate
276  ScalarType sol_norm_;
277  //
278  // RHS norm
279  ScalarType bnorm_;
280 
281 };
282 
284  // Constructor.
285 
286 // const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho,
287 
288  template<class ScalarType, class MV, class OP>
290  const Teuchos::RCP<Belos::OutputManager<ScalarType> > &printer,
291  const Teuchos::RCP<Belos::StatusTest<ScalarType,MV,OP> > &tester,
292  Teuchos::ParameterList &params ):
293  lp_(problem),
294  om_(printer),
295  stest_(tester),
296  initialized_(false),
297  stateStorageInitialized_(false),
298  iter_(0),
299  lambda_(params.get<MagnitudeType> ("Lambda"))
300  {
301  }
302 
304  // Setup the state storage.
305  template <class ScalarType, class MV, class OP>
307  {
308  if (!stateStorageInitialized_) {
309  // Check if there is any multivector to clone from.
310  Teuchos::RCP<const MV> rhsMV = lp_->getInitPrecResVec();
311  Teuchos::RCP<const MV> lhsMV = lp_->getLHS();
312  if (lhsMV == Teuchos::null || rhsMV == Teuchos::null) {
313  stateStorageInitialized_ = false;
314  return;
315  }
316  else {
317  // Initialize the state storage
318  // If the subspace has not been initialized before, generate it
319  // using the LHS and RHS from lp_.
320  if (U_ == Teuchos::null) {
321  // Get the multivectors.
322  TEUCHOS_TEST_FOR_EXCEPTION(rhsMV == Teuchos::null, std::invalid_argument, "LSQRIter::setStateSize(): linear problem does not specify right hand multivector to clone from.");
323  TEUCHOS_TEST_FOR_EXCEPTION(lhsMV == Teuchos::null, std::invalid_argument, "LSQRIter::setStateSize(): linear problem does not specify left hand multivector to clone from.");
324 
325  U_ = MVT::Clone( *rhsMV, 1 ); // LeftPrecond * rhs
326  V_ = MVT::Clone( *lhsMV, 1 ); // zero, overwrittein in
327  W_ = MVT::Clone( *lhsMV, 1 ); // zero, initializeLSQR
328  }
329 
330  // State storage has now been initialized.
331  stateStorageInitialized_ = true;
332  }
333  }
334  }
335 
336 
338  // Initialize this iteration object
339  template <class ScalarType, class MV, class OP>
341  {
342  using Teuchos::RCP;
343 
344  // Initialize the state storage if it isn't already.
345  if (!stateStorageInitialized_)
346  setStateSize();
347 
348  TEUCHOS_TEST_FOR_EXCEPTION(!stateStorageInitialized_,std::invalid_argument,
349  "LSQRIter::initialize(): Cannot initialize state storage!");
350 
351  std::string errstr("LSQRIter::initialize(): Specified multivectors must have a consistent length and width.");
352 
353 
354  // Compute initial bidiagonalization vectors and search direction
355  //
356  RCP<const MV> lhsMV = lp_->getLHS(); // contains initial guess,
357 
358  bool debugSerialLSQR = false;
359 
360  if( debugSerialLSQR )
361  {
362  std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> lhsNorm(1);
363  MVT::MvNorm( *lhsMV, lhsNorm );
364  std::cout << "initializeLSQR lhsNorm " << lhsNorm[0] << std::endl;
365  }
366 
367  // LinearProlbem provides right-hand side vectors including RHS CurrRHSVec InitResVec.
368  RCP<const MV> rhsMV = lp_->getInitPrecResVec();
369  const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
370  const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
371  MVT::MvAddMv( one, *rhsMV, zero, *U_, *U_);
372 
373  RCP<const OP> M_left = lp_->getLeftPrec();
374  RCP<const OP> A = lp_->getOperator();
375  RCP<const OP> M_right = lp_->getRightPrec();
376 
377  if( debugSerialLSQR )
378  {
379  std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> rhsNorm(1);
380  MVT::MvNorm( *U_, rhsNorm );
381  std::cout << "initializeLSQR | U_ | : " << rhsNorm[0] << std::endl;
382  //U_->Print(std::cout);
383  }
384 
385  //MVT::MvScale( *V_, zero );
386 
387  // Apply the (conjugate) transpose of the preconditioned operator:
388  //
389  // V := (M_L A M_R)^* U, which means
390  // V := M_R^* (A^* (M_L^* U)).
391  //
392  //OPT::Apply(*(lp_->getOperator()), *U_, *V_, CONJTRANS);
393  if ( M_left.is_null())
394  {
395  OPT::Apply (*A, *U_, *V_, CONJTRANS); // V_ = A' U_
396  //std::cout << "*************** V_ ****************" << std::endl;
397  //V_->Print(std::cout);
398  }
399  else
400  {
401  RCP<MV> tempInRangeOfA = MVT::CloneCopy (*U_);
402  OPT::Apply (*M_left, *U_, *tempInRangeOfA, CONJTRANS);
403  OPT::Apply (*A, *tempInRangeOfA, *V_, CONJTRANS); // V_ = A' LeftPrec' U_
404  //std::cout << "mLeft V_ = " << *V_ << std::endl;
405  }
406  if (! M_right.is_null())
407  {
408  RCP<MV> tempInDomainOfA = MVT::CloneCopy (*V_);
409 
410  OPT::Apply (*M_right, *tempInDomainOfA, *V_, CONJTRANS); // V:= RtPrec' A' LeftPrec' U
411  //std::cout << "mRight V_ = " << *V_ << std::endl;
412  }
413 
414  // W := V (copy the vector)
415  MVT::MvAddMv( one, *V_, zero, *V_, *W_);
416 
417  frob_mat_norm_ = zero; // These are
418  mat_cond_num_ = one; // lower
419  sol_norm_ = zero; // bounds.
420 
421  // The solver is initialized.
422  initialized_ = true;
423  }
424 
425 
427  // Iterate until the status test informs us we should stop.
428  template <class ScalarType, class MV, class OP>
430  {
431  //
432  // Allocate/initialize data structures
433  //
434  if (initialized_ == false) {
435  initialize();
436  }
437 
438  // Create convenience variables for zero and one.
439  const ScalarType one = Teuchos::ScalarTraits<ScalarType>::one();
440  const MagnitudeType MTzero = Teuchos::ScalarTraits<MagnitudeType>::zero();
441  const ScalarType zero = Teuchos::ScalarTraits<ScalarType>::zero();
442 
443  // Allocate memory for scalars.
444  std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> alpha(1);
445  std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> beta(1);
446  std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> xi(1);
447  // xi is a dumb scalar used for storing inner products.
448  // Eventually SDM will replace the "vectors".
449  std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> wnorm2(1);
450  ScalarType rhobar, phibar, cs1, phi, rho, cs, sn, theta, xxnorm = MTzero, common;
451  ScalarType zetabar, sn1, psi, res = zero, ddnorm = zero, gamma, tau;
452  ScalarType anorm2 = zero;
453  ScalarType cs2 = -one, sn2 = zero, gammabar, zeta = zero, delta;
454 
455  // The pair of work vectors AV and AtU are
456  Teuchos::RCP<MV> AV; // used in applying A to V_ and
457  AV = MVT::Clone( *U_, 1);
458  Teuchos::RCP<MV> AtU; // used in applying A^TRANS to U_ respectively.
459  AtU = MVT::Clone( *V_, 1);
460  bool debugSerialLSQR = false;
461 
462  // Get the current solution vector.
463  Teuchos::RCP<MV> cur_soln_vec = lp_->getCurrLHSVec();
464 
465 
466  // Check that the current solution vector only has one column.
467  TEUCHOS_TEST_FOR_EXCEPTION( MVT::GetNumberVecs(*cur_soln_vec) != 1, LSQRIterateFailure,
468  "LSQRIter::iterate(): current linear system has more than one vector!" );
469 
470  // In initializeLSQR among other things V = A' U.
471  // alpha and beta normalize these vectors.
472  MVT::MvNorm( *U_, beta );
473  if( SCT::real(beta[0]) > zero )
474  {
475  MVT::MvScale( *U_, one / beta[0] );
476 
477  //std::cout << "*************** U/beta ****************" << std::endl;
478  //U_->Print(std::cout);
479 
480  MVT::MvScale( *V_, one / beta[0] ); // scale V = A'U to normalize U
481 
482  //std::cout << "*************** V/beta ****************" << std::endl;
483  //V_->Print(std::cout);
484  }
485  MVT::MvNorm( *V_, alpha );
486  if( debugSerialLSQR )
487  {
488  // used to compare with implementations
489  // initializing mat_resid_norm to alpha/beta
490  std::cout << iter_ << " First alpha " << alpha[0] << " beta " << beta[0] << " lambda " << lambda_ << std::endl;
491  }
492  if( SCT::real(alpha[0]) > zero )
493  {
494  MVT::MvScale( *V_, one / alpha[0] ); // V alpha = A' U to normalize V
495  }
496  if( beta[0] * alpha[0] > zero )
497  {
498  MVT::MvScale( *W_, one / (beta[0] * alpha[0]) ); // W = V
499  }
500  else
501  {
502  MVT::MvScale( *W_, zero );
503  }
504 
505  using Teuchos::RCP;
506  RCP<const OP> M_left = lp_->getLeftPrec();
507  RCP<const OP> A = lp_->getOperator();
508  RCP<const OP> M_right = lp_->getRightPrec();
509 
510  rhobar = alpha[0];
511  phibar = beta[0];
512  bnorm_ = beta[0];
513  resid_norm_ = beta[0];
514  mat_resid_norm_ = alpha[0] * beta[0];
515 
516 
518  // Iterate until the status test tells us to stop.
519  //
520  while (stest_->checkStatus(this) != Belos::Passed) {
521  // Increment the iteration
522  iter_++;
523 
524  // Perform the next step of the bidiagonalization.
525  // The next U_ and V_ vectors and scalars alpha and beta satisfy
526  // U_ betaNew := AV - U_ alphaOld ...
527 
528  if ( M_right.is_null() )
529  {
530  OPT::Apply(*A, *V_, *AV); // AV := A * V_
531  }
532  else
533  {
534  RCP<MV> tempInDomainOfA = MVT::CloneCopy (*V_);
535  OPT::Apply (*M_right, *V_, *tempInDomainOfA);
536  OPT::Apply(*A, *tempInDomainOfA, *AV);
537  }
538 
539  if (! M_left.is_null())
540  {
541  RCP<MV> tempInRangeOfA = MVT::CloneCopy (*AV);
542  OPT::Apply (*M_left, *tempInRangeOfA, *AV); // AV may change
543  }
544 
545 
546  if ( !( M_left.is_null() && M_right.is_null() )
547  && debugSerialLSQR && iter_ == 1)
548  {
549  // In practice, LSQR may reveal bugs in transposed preconditioners.
550  // This is the test that catches this type of bug.
551  // 1. confirm that V alpha = A' U
552 
553  if (! M_left.is_null())
554  {
555  RCP<MV> tempInRangeOfA = MVT::CloneCopy (*U_);
556  OPT::Apply (*M_left, *U_, *tempInRangeOfA, CONJTRANS);
557  OPT::Apply (*A, *tempInRangeOfA, *AtU, CONJTRANS); // AtU = B'L'U
558  }
559  else
560  {
561  OPT::Apply (*A, *U_, *AtU, CONJTRANS); // AtU = B'U
562  }
563  if ( !( M_right.is_null() ) )
564  {
565  RCP<MV> tempInDomainOfA = MVT::CloneCopy (*AtU);
566  OPT::Apply (*M_right, *tempInDomainOfA, *AtU, CONJTRANS); // AtU := R' AtU
567  }
568 
569  MVT::MvAddMv( one, *AtU, -alpha[0], *V_, *AtU );
570  MVT::MvNorm( *AtU, xi );
571  std::cout << "| V alpha - A' u |= " << xi[0] << std::endl;
572  // 2. confirm that U is a unit vector
573  Teuchos::SerialDenseMatrix<int,ScalarType> uotuo(1,1);
574  MVT::MvTransMv( one, *U_, *U_, uotuo );
575  std::cout << "<U, U> = " << uotuo << std::endl;
576  // 3. print alpha = <V, A'U>
577  std::cout << "alpha = " << alpha[0] << std::endl;
578  // 4. compute < AV, U> which ought to be alpha
579  Teuchos::SerialDenseMatrix<int,ScalarType> utav(1,1);
580  MVT::MvTransMv( one, *AV, *U_, utav );
581  std::cout << "<AV, U> = alpha = " << utav << std::endl;
582  }
583 
584  MVT::MvAddMv( one, *AV, -alpha[0], *U_, *U_ ); // uNew := Av - uOld alphaOld
585  MVT::MvNorm( *U_, beta);
586 
587  anorm2 += alpha[0]*alpha[0] + beta[0]*beta[0] + lambda_*lambda_;
588 
589 
590  if ( SCT::real(beta[0]) > zero )
591  {
592 
593  MVT::MvScale( *U_, one / beta[0] );
594 
595  if (M_left.is_null())
596  { // ... and V_ alphaNew := AtU - V_ betaNew
597  OPT::Apply(*A, *U_, *AtU, CONJTRANS);
598  }
599  else
600  {
601  RCP<MV> tempInRangeOfA = MVT::CloneCopy (*U_);
602  OPT::Apply (*M_left, *U_, *tempInRangeOfA, CONJTRANS);
603  OPT::Apply(*A, *tempInRangeOfA, *AtU, CONJTRANS);
604  }
605  if (! M_right.is_null())
606  {
607  RCP<MV> tempInDomainOfA = MVT::CloneCopy (*AtU);
608  OPT::Apply (*M_right, *tempInDomainOfA, *AtU, CONJTRANS); // AtU may change
609  }
610 
611  MVT::MvAddMv( one, *AtU, -beta[0], *V_, *V_ );
612  MVT::MvNorm( *V_, alpha );
613  }
614  else // beta = 0
615  {
616  alpha[0] = zero;
617  }
618 
619  if ( SCT::real(alpha[0]) > zero )
620  {
621  MVT::MvScale( *V_, one / alpha[0] );
622  }
623 
624  // Use a plane rotation to eliminate the damping parameter.
625  // This alters the diagonal (rhobar) of the lower-bidiagonal matrix.
626  common = Teuchos::ScalarTraits< ScalarType >::squareroot(rhobar*rhobar + lambda_*lambda_);
627  cs1 = rhobar / common;
628  sn1 = lambda_ / common;
629  psi = sn1 * phibar;
630  phibar = cs1 * phibar;
631 
632  // Use a plane rotation to eliminate the subdiagonal element (beta)
633  // of the lower-bidiagonal matrix, giving an upper-bidiagonal matrix.
634  rho = Teuchos::ScalarTraits< ScalarType >::squareroot(rhobar*rhobar + lambda_*lambda_ + beta[0]*beta[0]);
635  cs = common / rho;
636  sn = beta[0] / rho;
637  theta = sn * alpha[0];
638  rhobar = -cs * alpha[0];
639  phi = cs * phibar;
640  phibar = sn * phibar; // If beta vanishes, so do sn, theta, phibar and eventually resid_norm
641  tau = sn * phi;
642 
643  delta = sn2 * rho;
644  gammabar = -cs2 * rho;
645  zetabar = (phi - delta*zeta) / gammabar;
646  sol_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(xxnorm + zetabar*zetabar);
647  gamma = Teuchos::ScalarTraits< ScalarType >::squareroot(gammabar*gammabar + theta*theta);
648  cs2 = gammabar / gamma;
649  sn2 = theta / gamma;
650  zeta = (phi - delta*zeta) / gamma;
651  xxnorm += zeta*zeta;
652 
653  //The next task may be addressed by some form of lp_->updateSolution.
654  if ( M_right.is_null())
655  {
656  MVT::MvAddMv( phi / rho, *W_, one, *cur_soln_vec, *cur_soln_vec);
657  }
658  else
659  {
660  RCP<MV> tempInDomainOfA = MVT::CloneCopy (*W_);
661  OPT::Apply (*M_right, *W_, *tempInDomainOfA);
662  MVT::MvAddMv( phi / rho, *tempInDomainOfA, one, *cur_soln_vec, *cur_soln_vec);
663  }
664 
665  MVT::MvNorm( *W_, wnorm2 );
666  ddnorm += (one / rho)*(one / rho) * wnorm2[0]*wnorm2[0];
667  MVT::MvAddMv( one, *V_, -theta / rho, *W_, *W_ );
668 
669  frob_mat_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(anorm2);
670  mat_cond_num_ = frob_mat_norm_ * Teuchos::ScalarTraits< ScalarType >::squareroot(ddnorm);
671  res+= psi*psi;
672  resid_norm_ = Teuchos::ScalarTraits< ScalarType >::squareroot(phibar*phibar + res);
673  mat_resid_norm_ = alpha[0] * Teuchos::ScalarTraits< ScalarType >::magnitude(tau);
674 
675  } // end while (sTest_->checkStatus(this) != Passed)
676  } // iterate()
677 
678 } // end Belos namespace
679 
680 #endif /* BELOS_LSQR_ITER_HPP */
Teuchos::RCP< const MV > U
Bidiagonalization vector.
Collection of types and exceptions used within the Belos solvers.
IterationState contains the data that defines the state of the LSQR solver at any given time...
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which manages the output and verbosity of the Belos solvers.
ScalarType resid_norm
The current residual norm.
Teuchos::ScalarTraits< ScalarType >::magnitudeType lambda
The damping value.
void resetNumIters(int iter=0)
Reset the iteration count.
Pure virtual base class for defining the status testing capabilities of Belos.
Declaration of basic traits for the multivector type.
ScalarType sol_norm
An estimate of the norm of the solution.
ScalarType mat_cond_num
An approximation to the condition number of A.
static void MvTransMv(const ScalarType alpha, const MV &A, const MV &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
A pure virtual class for defining the status tests for the Belos iterative solvers.
Belos::OperatorTraits< ScalarType, MV, OP > OPT
Class which defines basic traits for the operator type.
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
Traits class which defines basic operations on multivectors.
void iterate()
This method performs LSQR iterations until the status test indicates the need to stop or an error occ...
ScalarType frob_mat_norm
An approximation to the Frobenius norm of A.
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
ScalarType mat_resid_norm
An estimate of the norm of A^T*resid.
static void Apply(const OP &Op, const MV &x, MV &y, ETrans trans=NOTRANS)
Apply Op to x, putting the result into y.
Teuchos::RCP< const MV > W
The search direction vector.
Teuchos::RCP< const MV > V
Bidiagonalization vector.
virtual ~LSQRIter()
Destructor.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
int getNumIters() const
Get the current iteration count.
LSQRIter(const Teuchos::RCP< Belos::LinearProblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< Belos::OutputManager< ScalarType > > &printer, const Teuchos::RCP< Belos::StatusTest< ScalarType, MV, OP > > &tester, Teuchos::ParameterList &params)
LSQRIter constructor with linear problem, solver utilities, and parameter list of solver options...
Teuchos::ScalarTraits< ScalarType > SCT
Teuchos::RCP< MV > getCurrentUpdate() const
Get the current update to the linear system.
Belos::MultiVecTraits< ScalarType, MV > MVT
SCT::magnitudeType MagnitudeType
LSQRIterationState< ScalarType, MV > getState() const
Get the current state of the linear solver.
void initialize()
The solver is initialized using initializeLSQR.
static void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm)
Compute the 2-norm of each individual vector of mv. Upon return, normvec[i] holds the value of ...
Class which defines basic traits for the operator type.
Implementation of the LSQR iteration.
static void MvScale(MV &mv, const ScalarType alpha)
Scale each element of the vectors in mv with alpha.
ScalarType bnorm
The norm of the RHS vector b.
int getBlockSize() const
Get the blocksize to be used by the iterative solver in solving this linear problem.
Teuchos::RCP< const MV > getNativeResiduals(std::vector< MagnitudeType > *norms) const
Get the norms of the residuals native to the solver.
bool isInitialized()
States whether the solver has been initialized or not.
Structure to contain pointers to LSQRIteration state variables, ...
Belos header file which uses auto-configuration information to include necessary C++ headers...
const Belos::LinearProblem< ScalarType, MV, OP > & getProblem() const
Get a constant reference to the linear problem.
LSQRIterateFailure is thrown when the LSQRIteration object is unable to compute the next iterate in t...
void setBlockSize(int blockSize)
Set the blocksize to be used by the iterative solver to solve this linear problem.
void initializeLSQR(LSQRIterationState< ScalarType, MV > newstate)
Initialize the solver to an iterate, completing the initial state.