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 //
4 // Anasazi: Block Eigensolvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under 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 ANASAZI_MULTI_VEC_HPP
43 #define ANASAZI_MULTI_VEC_HPP
44 
59 
60 #include "AnasaziConfigDefs.hpp"
62 
63 namespace Anasazi {
64 
89 template <class ScalarType>
90 class MultiVec {
91 public:
93 
94  MultiVec() {}
96 
98  virtual ~MultiVec () {}
99 
101 
103 
106  virtual MultiVec<ScalarType> * Clone ( const int numvecs ) const = 0;
107 
110  virtual MultiVec<ScalarType> * CloneCopy () const = 0;
111 
118  virtual MultiVec<ScalarType> * CloneCopy ( const std::vector<int>& index ) const = 0;
119 
126  virtual MultiVec<ScalarType> * CloneViewNonConst ( const std::vector<int>& index ) = 0;
127 
134  virtual const MultiVec<ScalarType> * CloneView ( const std::vector<int>& index ) const = 0;
135 
137 
139 
141  virtual ptrdiff_t GetGlobalLength () const = 0;
142 
144  virtual int GetNumberVecs () const = 0;
145 
147 
149 
151  virtual void
152  MvTimesMatAddMv (ScalarType alpha,
153  const MultiVec<ScalarType>& A,
154  const Teuchos::SerialDenseMatrix<int,ScalarType>& B, ScalarType beta) = 0;
155 
157  virtual void MvAddMv ( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B ) = 0;
158 
160  virtual void MvScale ( ScalarType alpha ) = 0;
161 
163  virtual void MvScale ( const std::vector<ScalarType>& alpha ) = 0;
164 
168  virtual void MvTransMv ( ScalarType alpha, const MultiVec<ScalarType>& A, Teuchos::SerialDenseMatrix<int,ScalarType>& B
169 #ifdef HAVE_ANASAZI_EXPERIMENTAL
170  , ConjType conj = Anasazi::CONJ
171 #endif
172  ) const = 0;
173 
179  virtual void MvDot ( const MultiVec<ScalarType>& A, std::vector<ScalarType> & b
180 #ifdef HAVE_ANASAZI_EXPERIMENTAL
181  , ConjType conj = Anasazi::CONJ
182 #endif
183  ) const = 0;
184 
186 
188 
193  virtual void MvNorm ( std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec ) const = 0;
194 
196 
198 
203  virtual void SetBlock ( const MultiVec<ScalarType>& A, const std::vector<int>& index ) = 0;
204 
206  virtual void MvRandom () = 0;
207 
209  virtual void MvInit ( ScalarType alpha ) = 0;
210 
212 
214 
216  virtual void MvPrint ( std::ostream& os ) const = 0;
218 
219 #ifdef HAVE_ANASAZI_TSQR
220 
222 
245  virtual void
246  factorExplicit (MultiVec<ScalarType>& Q,
248  const bool forceNonnegativeDiagonal=false)
249  {
250  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Anasazi::MultiVec<"
251  << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you "
252  "are using does not implement the TSQR-related method factorExplicit().");
253  }
254 
289  virtual int
292  {
293  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Anasazi::MultiVec<"
294  << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you "
295  "are using does not implement the TSQR-related method revealRank().");
296  }
297 
299 #endif // HAVE_ANASAZI_TSQR
300 };
301 
302 namespace details {
320 template<class ScalarType>
322 public:
323  typedef MultiVec<ScalarType> MV;
324  typedef ScalarType scalar_type;
325  typedef int ordinal_type; // This doesn't matter either
326  typedef int node_type; // Nor does this
328  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
329 
331  void
333  MV& Q,
335  const bool forceNonnegativeDiagonal=false)
336  {
337  A.factorExplicit (Q, R, forceNonnegativeDiagonal);
338  }
339 
341  int
344  const magnitude_type& tol)
345  {
346  return Q.revealRank (R, tol);
347  }
348 };
349 } // namespace details
350 
360  template<class ScalarType>
361  class MultiVecTraits<ScalarType,MultiVec<ScalarType> > {
362  public:
364 
365 
369  Clone (const MultiVec<ScalarType>& mv, const int numvecs) {
370  return Teuchos::rcp (const_cast<MultiVec<ScalarType>&> (mv).Clone (numvecs));
371  }
372 
378  { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy() ); }
379 
385  static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv, const std::vector<int>& index )
386  { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy(index) ); }
387 
393  static Teuchos::RCP<MultiVec<ScalarType> > CloneViewNonConst( MultiVec<ScalarType>& mv, const std::vector<int>& index )
394  { return Teuchos::rcp( mv.CloneViewNonConst(index) ); }
395 
401  static Teuchos::RCP<const MultiVec<ScalarType> > CloneView( const MultiVec<ScalarType>& mv, const std::vector<int>& index )
402  { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneView(index) ); }
403 
405 
407 
408 
410  static ptrdiff_t GetGlobalLength( const MultiVec<ScalarType>& mv )
411  { return mv.GetGlobalLength(); }
412 
414  static int GetNumberVecs( const MultiVec<ScalarType>& mv )
415  { return mv.GetNumberVecs(); }
416 
418 
420 
421 
424  static void MvTimesMatAddMv( ScalarType alpha, const MultiVec<ScalarType>& A,
426  ScalarType beta, MultiVec<ScalarType>& mv )
427  { mv.MvTimesMatAddMv(alpha, A, B, beta); }
428 
431  static void MvAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B, MultiVec<ScalarType>& mv )
432  { mv.MvAddMv(alpha, A, beta, B); }
433 
437 #ifdef HAVE_ANASAZI_EXPERIMENTAL
438  , ConjType conj = Anasazi::CONJ
439 #endif
440  )
441  { mv.MvTransMv(alpha, A, B
442 #ifdef HAVE_ANASAZI_EXPERIMENTAL
443  , conj
444 #endif
445  ); }
446 
449  static void MvDot( const MultiVec<ScalarType>& mv, const MultiVec<ScalarType>& A, std::vector<ScalarType> & b
450 #ifdef HAVE_ANASAZI_EXPERIMENTAL
451  , ConjType conj = Anasazi::CONJ
452 #endif
453  )
454  { mv.MvDot( A, b
455 #ifdef HAVE_ANASAZI_EXPERIMENTAL
456  , conj
457 #endif
458  ); }
459 
461  static void MvScale ( MultiVec<ScalarType>& mv, ScalarType alpha )
462  { mv.MvScale( alpha ); }
463 
465  static void MvScale ( MultiVec<ScalarType>& mv, const std::vector<ScalarType>& alpha )
466  { mv.MvScale( alpha ); }
467 
469 
471 
475  static void MvNorm( const MultiVec<ScalarType>& mv, std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec )
476  { mv.MvNorm(normvec); }
477 
479 
481 
486  static void SetBlock( const MultiVec<ScalarType>& A, const std::vector<int>& index, MultiVec<ScalarType>& mv )
487  { mv.SetBlock(A, index); }
488 
491  static void MvRandom( MultiVec<ScalarType>& mv )
492  { mv.MvRandom(); }
493 
496  static void MvInit( MultiVec<ScalarType>& mv, ScalarType alpha = Teuchos::ScalarTraits<ScalarType>::zero() )
497  { mv.MvInit(alpha); }
498 
500 
502 
504  static void MvPrint( const MultiVec<ScalarType>& mv, std::ostream& os )
505  { mv.MvPrint(os); }
506 
508 
509 #ifdef HAVE_ANASAZI_TSQR
510  typedef details::MultiVecTsqrAdapter<ScalarType> tsqr_adaptor_type;
518 #endif // HAVE_ANASAZI_TSQR
519  };
520 
521 } // namespace Anasazi
522 
523 #endif
524 
525 // 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.