Anasazi  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AnasaziMultiVec.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 
10 #ifndef ANASAZI_MULTI_VEC_HPP
11 #define ANASAZI_MULTI_VEC_HPP
12 
27 
28 #include "AnasaziConfigDefs.hpp"
30 
31 namespace Anasazi {
32 
57 template <class ScalarType>
58 class MultiVec {
59 public:
61 
62  MultiVec() {}
64 
66  virtual ~MultiVec () {}
67 
69 
71 
74  virtual MultiVec<ScalarType> * Clone ( const int numvecs ) const = 0;
75 
78  virtual MultiVec<ScalarType> * CloneCopy () const = 0;
79 
86  virtual MultiVec<ScalarType> * CloneCopy ( const std::vector<int>& index ) const = 0;
87 
94  virtual MultiVec<ScalarType> * CloneViewNonConst ( const std::vector<int>& index ) = 0;
95 
102  virtual const MultiVec<ScalarType> * CloneView ( const std::vector<int>& index ) const = 0;
103 
105 
107 
109  virtual ptrdiff_t GetGlobalLength () const = 0;
110 
112  virtual int GetNumberVecs () const = 0;
113 
115 
117 
119  virtual void
120  MvTimesMatAddMv (ScalarType alpha,
121  const MultiVec<ScalarType>& A,
122  const Teuchos::SerialDenseMatrix<int,ScalarType>& B, ScalarType beta) = 0;
123 
125  virtual void MvAddMv ( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B ) = 0;
126 
128  virtual void MvScale ( ScalarType alpha ) = 0;
129 
131  virtual void MvScale ( const std::vector<ScalarType>& alpha ) = 0;
132 
136  virtual void MvTransMv ( ScalarType alpha, const MultiVec<ScalarType>& A, Teuchos::SerialDenseMatrix<int,ScalarType>& B
137 #ifdef HAVE_ANASAZI_EXPERIMENTAL
138  , ConjType conj = Anasazi::CONJ
139 #endif
140  ) const = 0;
141 
147  virtual void MvDot ( const MultiVec<ScalarType>& A, std::vector<ScalarType> & b
148 #ifdef HAVE_ANASAZI_EXPERIMENTAL
149  , ConjType conj = Anasazi::CONJ
150 #endif
151  ) const = 0;
152 
154 
156 
161  virtual void MvNorm ( std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec ) const = 0;
162 
164 
166 
171  virtual void SetBlock ( const MultiVec<ScalarType>& A, const std::vector<int>& index ) = 0;
172 
174  virtual void MvRandom () = 0;
175 
177  virtual void MvInit ( ScalarType alpha ) = 0;
178 
180 
182 
184  virtual void MvPrint ( std::ostream& os ) const = 0;
186 
187 #ifdef HAVE_ANASAZI_TSQR
188 
190 
213  virtual void
214  factorExplicit (MultiVec<ScalarType>& Q,
216  const bool forceNonnegativeDiagonal=false)
217  {
218  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Anasazi::MultiVec<"
219  << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you "
220  "are using does not implement the TSQR-related method factorExplicit().");
221  }
222 
257  virtual int
260  {
261  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Anasazi::MultiVec<"
262  << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you "
263  "are using does not implement the TSQR-related method revealRank().");
264  }
265 
267 #endif // HAVE_ANASAZI_TSQR
268 };
269 
270 namespace details {
288 template<class ScalarType>
290 public:
291  typedef MultiVec<ScalarType> MV;
292  typedef ScalarType scalar_type;
293  typedef int ordinal_type; // This doesn't matter either
294  typedef int node_type; // Nor does this
296  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
297 
299  void
301  MV& Q,
303  const bool forceNonnegativeDiagonal=false)
304  {
305  A.factorExplicit (Q, R, forceNonnegativeDiagonal);
306  }
307 
309  int
312  const magnitude_type& tol)
313  {
314  return Q.revealRank (R, tol);
315  }
316 };
317 } // namespace details
318 
328  template<class ScalarType>
329  class MultiVecTraits<ScalarType,MultiVec<ScalarType> > {
330  public:
332 
333 
337  Clone (const MultiVec<ScalarType>& mv, const int numvecs) {
338  return Teuchos::rcp (const_cast<MultiVec<ScalarType>&> (mv).Clone (numvecs));
339  }
340 
346  { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy() ); }
347 
353  static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv, const std::vector<int>& index )
354  { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy(index) ); }
355 
361  static Teuchos::RCP<MultiVec<ScalarType> > CloneViewNonConst( MultiVec<ScalarType>& mv, const std::vector<int>& index )
362  { return Teuchos::rcp( mv.CloneViewNonConst(index) ); }
363 
369  static Teuchos::RCP<const MultiVec<ScalarType> > CloneView( const MultiVec<ScalarType>& mv, const std::vector<int>& index )
370  { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneView(index) ); }
371 
373 
375 
376 
378  static ptrdiff_t GetGlobalLength( const MultiVec<ScalarType>& mv )
379  { return mv.GetGlobalLength(); }
380 
382  static int GetNumberVecs( const MultiVec<ScalarType>& mv )
383  { return mv.GetNumberVecs(); }
384 
386 
388 
389 
392  static void MvTimesMatAddMv( ScalarType alpha, const MultiVec<ScalarType>& A,
394  ScalarType beta, MultiVec<ScalarType>& mv )
395  { mv.MvTimesMatAddMv(alpha, A, B, beta); }
396 
399  static void MvAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B, MultiVec<ScalarType>& mv )
400  { mv.MvAddMv(alpha, A, beta, B); }
401 
405 #ifdef HAVE_ANASAZI_EXPERIMENTAL
406  , ConjType conj = Anasazi::CONJ
407 #endif
408  )
409  { mv.MvTransMv(alpha, A, B
410 #ifdef HAVE_ANASAZI_EXPERIMENTAL
411  , conj
412 #endif
413  ); }
414 
417  static void MvDot( const MultiVec<ScalarType>& mv, const MultiVec<ScalarType>& A, std::vector<ScalarType> & b
418 #ifdef HAVE_ANASAZI_EXPERIMENTAL
419  , ConjType conj = Anasazi::CONJ
420 #endif
421  )
422  { mv.MvDot( A, b
423 #ifdef HAVE_ANASAZI_EXPERIMENTAL
424  , conj
425 #endif
426  ); }
427 
429  static void MvScale ( MultiVec<ScalarType>& mv, ScalarType alpha )
430  { mv.MvScale( alpha ); }
431 
433  static void MvScale ( MultiVec<ScalarType>& mv, const std::vector<ScalarType>& alpha )
434  { mv.MvScale( alpha ); }
435 
437 
439 
443  static void MvNorm( const MultiVec<ScalarType>& mv, std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec )
444  { mv.MvNorm(normvec); }
445 
447 
449 
454  static void SetBlock( const MultiVec<ScalarType>& A, const std::vector<int>& index, MultiVec<ScalarType>& mv )
455  { mv.SetBlock(A, index); }
456 
459  static void MvRandom( MultiVec<ScalarType>& mv )
460  { mv.MvRandom(); }
461 
464  static void MvInit( MultiVec<ScalarType>& mv, ScalarType alpha = Teuchos::ScalarTraits<ScalarType>::zero() )
465  { mv.MvInit(alpha); }
466 
468 
470 
472  static void MvPrint( const MultiVec<ScalarType>& mv, std::ostream& os )
473  { mv.MvPrint(os); }
474 
476 
477 #ifdef HAVE_ANASAZI_TSQR
478  typedef details::MultiVecTsqrAdapter<ScalarType> tsqr_adaptor_type;
486 #endif // HAVE_ANASAZI_TSQR
487  };
488 
489 } // namespace Anasazi
490 
491 #endif
492 
493 // end of file AnasaziMultiVec.hpp
virtual void MvRandom()=0
Fill all the vectors in *this with random numbers.
static void MvScale(MultiVec< ScalarType > &mv, ScalarType alpha)
Scale each element of the vectors in *this with alpha.
static void MvPrint(const MultiVec< ScalarType > &mv, std::ostream &os)
Print the mv multi-vector to the os output stream.
void factorExplicit(MV &A, MV &Q, dense_matrix_type &R, const bool forceNonnegativeDiagonal=false)
Compute QR factorization A = QR, using TSQR.
virtual void MvInit(ScalarType alpha)=0
Replace each element of the vectors in *this with alpha.
static void MvInit(MultiVec< ScalarType > &mv, ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
Replace each element of the vectors in mv with alpha.
virtual void SetBlock(const MultiVec< ScalarType > &A, const std::vector< int > &index)=0
Copy the vectors in A to a set of vectors in *this.
virtual void MvDot(const MultiVec< ScalarType > &A, std::vector< ScalarType > &b) const =0
Compute the dot product of each column of *this with the corresponding column of A.
virtual void MvAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, ScalarType beta, const MultiVec< ScalarType > &B)=0
Replace *this with alpha * A + beta * B.
virtual void MvPrint(std::ostream &os) const =0
Print *this multivector to the os output stream.
virtual ptrdiff_t GetGlobalLength() const =0
The number of rows in the multivector.
Declaration of basic traits for the multivector type.
static void SetBlock(const MultiVec< ScalarType > &A, const std::vector< int > &index, MultiVec< ScalarType > &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static Teuchos::RCP< MultiVec< ScalarType > > Clone(const MultiVec< ScalarType > &mv, const int numvecs)
Create a new empty MultiVec containing numvecs columns.
static void MvAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, ScalarType beta, const MultiVec< ScalarType > &B, MultiVec< ScalarType > &mv)
Replace mv with .
static void MvNorm(const MultiVec< ScalarType > &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec)
Compute the 2-norm of each individual vector of mv. Upon return, normvec[i] holds the value of ...
static void MvRandom(MultiVec< ScalarType > &mv)
Replace the vectors in mv with random vectors.
virtual const MultiVec< ScalarType > * CloneView(const std::vector< int > &index) const =0
Creates a new Anasazi::MultiVec that shares the selected contents of *this. The index of the numvecs ...
int revealRank(MV &Q, dense_matrix_type &R, const magnitude_type &tol)
Compute rank-revealing decomposition using results of factorExplicit().
static void MvDot(const MultiVec< ScalarType > &mv, const MultiVec< ScalarType > &A, std::vector< ScalarType > &b)
Compute a vector b where the components are the individual dot-products of the i-th columns of A and ...
virtual void MvNorm(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec) const =0
Compute the 2-norm of each vector in *this.
static Teuchos::RCP< MultiVec< ScalarType > > CloneViewNonConst(MultiVec< ScalarType > &mv, const std::vector< int > &index)
Creates a new Anasazi::MultiVec that shares the selected contents of mv (shallow copy).
ConjType
Enumerated types used to specify conjugation arguments.
virtual int GetNumberVecs() const =0
The number of vectors (i.e., columns) in the multivector.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void MvTransMv(ScalarType alpha, const MultiVec< ScalarType > &A, Teuchos::SerialDenseMatrix< int, ScalarType > &B) const =0
Compute a dense matrix B through the matrix-matrix multiply alpha * A^T * (*this).
MultiVec()
Default constructor.
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
static Teuchos::RCP< const MultiVec< ScalarType > > CloneView(const MultiVec< ScalarType > &mv, const std::vector< int > &index)
Creates a new const Anasazi::MultiVec that shares the selected contents of mv (shallow copy)...
static int GetNumberVecs(const MultiVec< ScalarType > &mv)
Obtain the number of vectors in mv.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
static void MvTimesMatAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, ScalarType beta, MultiVec< ScalarType > &mv)
Update mv with .
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
static Teuchos::RCP< MultiVec< ScalarType > > CloneCopy(const MultiVec< ScalarType > &mv)
Creates a new Anasazi::MultiVec and copies contents of mv into the new vector (deep copy)...
static void MvTransMv(ScalarType alpha, const MultiVec< ScalarType > &A, const MultiVec< ScalarType > &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
virtual void MvScale(ScalarType alpha)=0
Scale each element of the vectors in *this with alpha.
virtual MultiVec< ScalarType > * CloneViewNonConst(const std::vector< int > &index)=0
Creates a new Anasazi::MultiVec that shares the selected contents of *this. The index of the numvecs ...
virtual MultiVec< ScalarType > * CloneCopy() const =0
Create a new MultiVec and copy contents of *this into it (deep copy).
virtual void MvTimesMatAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, ScalarType beta)=0
Update *this with alpha * A * B + beta * (*this).
virtual ~MultiVec()
Destructor (virtual for memory safety of derived classes).
virtual MultiVec< ScalarType > * Clone(const int numvecs) const =0
Create a new MultiVec with numvecs columns.
static Teuchos::RCP< MultiVec< ScalarType > > CloneCopy(const MultiVec< ScalarType > &mv, const std::vector< int > &index)
Creates a new Anasazi::MultiVec and copies the selected contents of mv into the new vector (deep copy...
static void MvScale(MultiVec< ScalarType > &mv, const std::vector< ScalarType > &alpha)
Scale each element of the i-th vector in *this with alpha[i].
Interface for multivectors used by Anasazi&#39;s linear solvers.
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
static ptrdiff_t GetGlobalLength(const MultiVec< ScalarType > &mv)
Obtain the vector length of mv.