Anasazi  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AnasaziTsqrOrthoManager.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Anasazi: Block Eigensolvers Package
4 //
5 // Copyright 2004 NTESS and the Anasazi contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
12 
13 #ifndef __AnasaziTsqrOrthoManager_hpp
14 #define __AnasaziTsqrOrthoManager_hpp
15 
16 #include "AnasaziTsqrOrthoManagerImpl.hpp"
18 
19 
20 namespace Anasazi {
21 
43  template<class Scalar, class MV>
45  public:
46  typedef Scalar scalar_type;
47  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitude_type;
50  typedef MV multivector_type;
51 
54 
63  virtual int
64  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const = 0;
65 
84  virtual int
86  MV& X_out,
88  mat_ptr B,
90 
93  };
94 
101  template<class Scalar, class MV>
103  public OrthoManager<Scalar, MV>,
104  public OutOfPlaceNormalizerMixin<Scalar, MV>,
106  {
107  public:
108  typedef Scalar scalar_type;
109  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitude_type;
111  typedef MV multivector_type;
112 
115 
116  void setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& params) {
117  impl_.setParameterList (params);
118  }
119 
120  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList () {
121  return impl_.getNonconstParameterList ();
122  }
123 
124  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList () {
125  return impl_.unsetParameterList ();
126  }
127 
136  return impl_.getValidParameters();
137  }
138 
149  return impl_.getFastParameters();
150  }
151 
169  const std::string& label = "Anasazi") :
170  impl_ (params, label)
171  {}
172 
177  TsqrOrthoManager (const std::string& label) :
178  impl_ (label)
179  {}
180 
182  virtual ~TsqrOrthoManager() {}
183 
184  void innerProd (const MV &X, const MV& Y, mat_type& Z) const {
185  return impl_.innerProd (X, Y, Z);
186  }
187 
188  void norm (const MV& X, std::vector<magnitude_type>& normVec) const {
189  return impl_.norm (X, normVec);
190  }
191 
192  void
193  project (MV &X,
196  = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,Scalar> >(Teuchos::null))) const
197  {
198  return impl_.project (X, C, Q);
199  }
200 
201  int
202  normalize (MV &X, mat_ptr B = Teuchos::null) const
203  {
204  return impl_.normalize (X, B);
205  }
206 
207  int
211  = Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix<int,Scalar> >(Teuchos::null)),
212  Teuchos::RCP<Teuchos::SerialDenseMatrix<int,Scalar> > B = Teuchos::null) const
213  {
214  return impl_.projectAndNormalize (X, C, B, Q);
215  }
216 
233  int
234  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const
235  {
236  return impl_.normalizeOutOfPlace (X, Q, B);
237  }
238 
259  int
261  MV& X_out,
263  mat_ptr B,
265  {
266  return impl_.projectAndNormalizeOutOfPlace (X_in, X_out, C, B, Q);
267  }
268 
269  magnitude_type orthonormError (const MV &X) const {
270  return impl_.orthonormError (X);
271  }
272 
273  magnitude_type orthogError (const MV &X1, const MV &X2) const {
274  return impl_.orthogError (X1, X2);
275  }
276 
277  private:
283  mutable TsqrOrthoManagerImpl<Scalar, MV> impl_;
284  };
285 
286 
299  template<class Scalar, class MV, class OP>
301  public MatOrthoManager<Scalar, MV, OP>,
302  public OutOfPlaceNormalizerMixin<Scalar, MV>,
304  {
305  public:
306  typedef Scalar scalar_type;
307  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitude_type;
309  typedef MV multivector_type;
311  typedef OP operator_type;
312 
315 
316  private:
326 
330 
334 
338 
339  public:
361  const std::string& label = "Belos",
362  Teuchos::RCP<const OP> Op = Teuchos::null) :
363  MatOrthoManager<Scalar, MV, OP> (Op),
364  tsqr_ (params, label),
365  pSvqb_ (Teuchos::null) // Initialized lazily
366  {}
367 
376  TsqrMatOrthoManager (const std::string& label = "Belos",
377  Teuchos::RCP<const OP> Op = Teuchos::null) :
378  MatOrthoManager<Scalar, MV, OP> (Op),
379  tsqr_ (label),
380  pSvqb_ (Teuchos::null) // Initialized lazily
381  {}
382 
384  virtual ~TsqrMatOrthoManager() {}
385 
394  return tsqr_.getValidParameters ();
395  }
396 
407  return tsqr_.getFastParameters ();
408  }
409 
410  void setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& params) {
411  tsqr_.setParameterList (params);
412  }
413 
414  virtual void
416  {
417  // We override the base class' setOp() so that the
418  // SVQBOrthoManager instance gets the new op.
419  //
420  // The base_type notation helps C++ resolve the name for a
421  // member function of a templated base class.
422  base_type::setOp (Op); // base class gets a copy of the Op too
423 
424  if (! Op.is_null()) {
425  ensureSvqbInit (); // Make sure the SVQB object has been initialized
426  pSvqb_->setOp (Op);
427  }
428  }
429 
431  // The base_type notation helps C++ resolve the name for a
432  // member function of a templated base class.
433  return base_type::getOp();
434  }
435 
436  void
437  projectMat (MV &X,
440  Teuchos::tuple (Teuchos::RCP<mat_type> (Teuchos::null)),
441  Teuchos::RCP<MV> MX = Teuchos::null,
443  Teuchos::tuple (Teuchos::null)) const
444  {
445  if (getOp().is_null()) {
446  // FIXME (mfh 12 Jan 2011): Do we need to check if C is null
447  // and allocate space if so?
448  tsqr_.project (X, C, Q);
449  // FIXME (mfh 20 Jul 2010) What about MX and MQ?
450  //
451  // FIXME (mfh 12 Jan 2011) Need to port MVT::Assign from Belos to Anasazi
452 #if 0
453  if (! MX.is_null()) {
454  // MX gets a copy of X; M is the identity operator.
455  MVT::Assign (X, *MX);
456  }
457 #endif // 0
458  } else {
459  ensureSvqbInit ();
460  pSvqb_->projectMat (X, Q, C, MX, MQ);
461  }
462  }
463 
464  int
465  normalizeMat (MV &X,
466  mat_ptr B = Teuchos::null,
467  Teuchos::RCP<MV> MX = Teuchos::null) const
468  {
469  if (getOp().is_null()) {
470  // FIXME (mfh 12 Jan 2011): Do we need to check if B is null
471  // and allocate space if so?
472  const int rank = tsqr_.normalize (X, B);
473  // FIXME (mfh 20 Jul 2010) What about MX?
474  //
475  // FIXME (mfh 12 Jan 2011) Need to port MVT::Assign from Belos to Anasazi
476 #if 0
477  if (! MX.is_null()) {
478  // MX gets a copy of X; M is the identity operator.
479  MVT::Assign (X, *MX);
480  }
481 #endif // 0
482  return rank;
483  } else {
484  ensureSvqbInit ();
485  return pSvqb_->normalizeMat (X, B, MX);
486  }
487  }
488 
489  int
493  Teuchos::tuple (Teuchos::RCP<mat_type> (Teuchos::null)),
494  Teuchos::RCP<mat_type> B = Teuchos::null,
495  Teuchos::RCP<MV> MX = Teuchos::null,
497  Teuchos::tuple (Teuchos::RCP<const MV> (Teuchos::null))) const
498  {
499  if (getOp().is_null()) {
500  // FIXME (mfh 12 Jan 2011): Do we need to check if C and B
501  // are null and allocate space if so?
502  const int rank = tsqr_.projectAndNormalize (X, C, B, Q);
503  // FIXME (mfh 20 Jul 2010) What about MX and MQ?
504  // mfh 12 Jan 2011: Ignore MQ (assume Q == MQ).
505  //
506  // FIXME (mfh 12 Jan 2011) Need to port MVT::Assign from Belos to Anasazi
507 #if 0
508  if (! MX.is_null()) {
509  // MX gets a copy of X; M is the identity operator.
510  MVT::Assign (X, *MX);
511  }
512 #endif // 0
513  return rank;
514  } else {
515  ensureSvqbInit ();
516  return pSvqb_->projectAndNormalizeMat (X, Q, C, B, MX, MQ);
517  }
518  }
519 
520  int
521  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const
522  {
523  if (getOp().is_null()) {
524  return tsqr_.normalizeOutOfPlace (X, Q, B);
525  } else {
526  // SVQB normalizes in place, so we have to copy.
527  ensureSvqbInit ();
528  const int rank = pSvqb_->normalize (X, B);
529  MVT::Assign (X, Q);
530  return rank;
531  }
532  }
533 
534  int
536  MV& X_out,
538  mat_ptr B,
540  {
541  using Teuchos::null;
542 
543  if (getOp().is_null()) {
544  return tsqr_.projectAndNormalizeOutOfPlace (X_in, X_out, C, B, Q);
545  } else {
546  ensureSvqbInit ();
547  // SVQB's projectAndNormalize wants an Array, not an ArrayView.
548  // Copy into a temporary Array and copy back afterwards.
550  const int rank = pSvqb_->projectAndNormalize (X_in, Q_array, C, B);
551  Q.assign (Q_array);
552  // SVQB normalizes in place, so we have to copy X_in to X_out.
553  MVT::Assign (X_in, X_out);
554  return rank;
555  }
556  }
557 
558  magnitude_type
559  orthonormErrorMat (const MV &X, Teuchos::RCP<const MV> MX = Teuchos::null) const
560  {
561  if (getOp().is_null()) {
562  return tsqr_.orthonormError (X);
563  // FIXME (mfh 20 Jul 2010) What about MX?
564  } else {
565  ensureSvqbInit ();
566  return pSvqb_->orthonormErrorMat (X, MX);
567  }
568  }
569 
570  magnitude_type
571  orthogErrorMat (const MV &X,
572  const MV &Y,
573  Teuchos::RCP<const MV> MX = Teuchos::null,
574  Teuchos::RCP<const MV> MY = Teuchos::null) const
575  {
576  if (getOp().is_null()) {
577  return tsqr_.orthogError (X, Y);
578  // FIXME (mfh 20 Jul 2010) What about MX and MY?
579  } else {
580  ensureSvqbInit ();
581  return pSvqb_->orthogErrorMat (X, Y, MX, MY);
582  }
583  }
584 
585  private:
587  void
588  ensureSvqbInit () const
589  {
590  // NOTE (mfh 12 Oct 2011) For now, we rely on the default values
591  // of SVQB parameters.
592  if (pSvqb_.is_null()) {
593  pSvqb_ = Teuchos::rcp (new svqb_type (getOp()));
594  }
595  }
596 
604  mutable tsqr_type tsqr_;
605 
610  mutable Teuchos::RCP<svqb_type> pSvqb_;
611  };
612 
613 } // namespace Anasazi
614 
615 #endif // __AnasaziTsqrOrthoManager_hpp
616 
magnitude_type orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
MatOrthoManager subclass using TSQR or SVQB.
bool is_null(const boost::shared_ptr< T > &p)
void projectMat(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< mat_type > > C=Teuchos::tuple(Teuchos::RCP< mat_type >(Teuchos::null)), Teuchos::RCP< MV > MX=Teuchos::null, Teuchos::Array< Teuchos::RCP< const MV > > MQ=Teuchos::tuple(Teuchos::null)) const
Provides matrix-based projection method.
TSQR-based OrthoManager subclass implementation.
MV multivector_type
Multivector type with which this class was specialized.
virtual void setOp(Teuchos::RCP< const OP > Op)
Set operator used for inner product.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get &quot;fast&quot; parameters for TsqrMatOrthoManager.
int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Project and normalize X_in into X_out.
Mixin for out-of-place orthogonalization.
int projectAndNormalize(MV &X, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q)
Project X against Q and normalize X.
TsqrMatOrthoManager(const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null)
Constructor (that sets default parameters).
magnitude_type orthogErrorMat(const MV &X, const MV &Y, Teuchos::RCP< const MV > MX=Teuchos::null, Teuchos::RCP< const MV > MY=Teuchos::null) const
This method computes the error in orthogonality of two multivectors.
MV multivector_type
Multivector type with which this class was specialized.
virtual ~TsqrMatOrthoManager()
Destructor (declared virtual for memory safety of derived classes).
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Default valid parameter list.
TsqrMatOrthoManager(const Teuchos::RCP< Teuchos::ParameterList > &params, const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null)
Constructor (that sets user-specified parameters).
An implementation of the Anasazi::MatOrthoManager that performs orthogonalization using the SVQB iter...
static void Assign(const MV &A, MV &mv)
mv := A
magnitude_type orthonormError(const MV &X) const
Return .
virtual int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const =0
Normalize X into Q*B.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set parameters from the given parameter list.
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const
Normalize X into Q*B, overwriting X with invalid values.
virtual ~OutOfPlaceNormalizerMixin()
Trivial virtual destructor, to silence compiler warnings.
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const
Normalize X into Q*B.
virtual Teuchos::RCP< const OP > getOp() const
Get operator used for inner product.
int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Project and normalize X_in into X_out; overwrite X_in.
Anasazi&#39;s templated virtual class for providing routines for orthogonalization and orthonormalization...
magnitude_type orthonormErrorMat(const MV &X, Teuchos::RCP< const MV > MX=Teuchos::null) const
This method computes the error in orthonormality of a multivector.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int projectAndNormalizeMat(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< mat_type > > C=Teuchos::tuple(Teuchos::RCP< mat_type >(Teuchos::null)), Teuchos::RCP< mat_type > B=Teuchos::null, Teuchos::RCP< MV > MX=Teuchos::null, Teuchos::Array< Teuchos::RCP< const MV > > MQ=Teuchos::tuple(Teuchos::RCP< const MV >(Teuchos::null))) const
Provides matrix-based projection/orthonormalization method.
Traits class which defines basic operations on multivectors.
Teuchos::RCP< const OP > getOp() const
Get operator used for inner product.
magnitude_type orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get &quot;fast&quot; parameters for TsqrOrthoManagerImpl.
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q)
Compute and .
void innerProd(const MV &X, const MV &Y, mat_type &Z) const
Provides the inner product defining the orthogonality concepts.
Orthogonalization manager based on the SVQB technique described in &quot;A Block Orthogonalization Procedu...
int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q)
Project and normalize X_in into X_out; overwrite X_in.
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B)
Normalize X into Q*B, overwriting X.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Default valid parameter list.
TsqrOrthoManager(const Teuchos::RCP< Teuchos::ParameterList > &params, const std::string &label="Anasazi")
Constructor (that sets user-specified parameters).
TSQR-based OrthoManager subclass.
virtual ~TsqrOrthoManager()
Destructor, declared virtual for safe inheritance.
TsqrOrthoManager(const std::string &label)
Constructor (that sets default parameters).
magnitude_type orthogError(const MV &X1, const MV &X2) const
Return the Frobenius norm of the inner product of X1 with itself.
OP operator_type
Operator type with which this class was specialized.
Anasazi&#39;s templated virtual class for providing routines for orthogonalization and orthonormalization...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get default parameters for TsqrMatOrthoManager.
int projectAndNormalize(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, Scalar > > > C=Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, Scalar > >(Teuchos::null)), Teuchos::RCP< Teuchos::SerialDenseMatrix< int, Scalar > > B=Teuchos::null) const
Given a set of bases Q[i] and a multivector X, this method computes an orthonormal basis for ...
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const
Get &quot;fast&quot; parameters for TsqrOrthoManager.
int normalize(MV &X, mat_ptr B)
Orthogonalize the columns of X in place.
virtual void setOp(Teuchos::RCP< const OP > Op)
Set operator used for inner product.
void project(MV &X, Teuchos::Array< Teuchos::RCP< const MV > > Q, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, Scalar > > > C=Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, Scalar > >(Teuchos::null))) const
Given a list of mutually orthogonal and internally orthonormal bases Q, this method projects a multiv...
virtual int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const =0
Project and normalize X_in into X_out.
bool is_null() const