Belos Version of the Day
BelosMultiVec.hpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 //
00004 //                 Belos: Block Linear Solvers Package
00005 //                  Copyright 2004 Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ************************************************************************
00040 //@HEADER
00041 
00042 #ifndef BELOS_MULTI_VEC_HPP
00043 #define BELOS_MULTI_VEC_HPP
00044 
00059 
00060 #include "BelosMultiVecTraits.hpp"
00061 #include "BelosTypes.hpp"
00062 #include "BelosConfigDefs.hpp"
00063 
00064 namespace Belos {
00065 
00090 template <class ScalarType>
00091 class MultiVec {
00092 public:
00094 
00095 
00096   MultiVec() {};
00097   
00099   virtual ~MultiVec () {};
00100   
00102 
00103 
00104   
00107   virtual MultiVec<ScalarType> * Clone ( const int numvecs ) const = 0;
00108   
00111   virtual MultiVec<ScalarType> * CloneCopy () const = 0;
00112   
00119   virtual MultiVec<ScalarType> * CloneCopy ( const std::vector<int>& index ) const = 0;
00120   
00127   virtual MultiVec<ScalarType> * CloneViewNonConst ( const std::vector<int>& index ) = 0;
00128   
00135   virtual const MultiVec<ScalarType> * CloneView ( const std::vector<int>& index ) const = 0;
00136 
00138 
00139 
00140 
00142   virtual int GetVecLength () const = 0;
00143  
00146   virtual ptrdiff_t GetGlobalLength () const { return static_cast<ptrdiff_t>( this->GetVecLength() ); }
00147  
00149   virtual int GetNumberVecs () const = 0;
00150 
00152 
00153 
00154 
00156   virtual void 
00157   MvTimesMatAddMv (const ScalarType alpha, 
00158        const MultiVec<ScalarType>& A, 
00159        const Teuchos::SerialDenseMatrix<int,ScalarType>& B, const ScalarType beta) = 0;
00160   
00162   virtual void MvAddMv ( const ScalarType alpha, const MultiVec<ScalarType>& A, const ScalarType beta, const MultiVec<ScalarType>& B ) = 0;
00163   
00165   virtual void MvScale ( const ScalarType alpha ) = 0;
00166   
00168   virtual void MvScale ( const std::vector<ScalarType>& alpha ) = 0;
00169   
00173   virtual void MvTransMv ( const ScalarType alpha, const MultiVec<ScalarType>& A, Teuchos::SerialDenseMatrix<int,ScalarType>& B) const = 0;
00174 
00180   virtual void MvDot ( const MultiVec<ScalarType>& A, std::vector<ScalarType>& b ) const = 0;
00181   
00183 
00184 
00185   
00191   virtual void MvNorm ( std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>& normvec, NormType type = TwoNorm ) const = 0;
00192   
00194 
00195 
00196 
00201   virtual void SetBlock ( const MultiVec<ScalarType>& A, const std::vector<int>& index ) = 0;
00202 
00204   virtual void MvRandom () = 0;
00205   
00207   virtual void MvInit ( const ScalarType alpha ) = 0;
00208   
00210 
00211 
00212 
00214   virtual void MvPrint ( std::ostream& os ) const = 0;
00216 
00217 #ifdef HAVE_BELOS_TSQR
00218 
00219 
00220 
00243   virtual void 
00244   factorExplicit (MultiVec<ScalarType>& Q, 
00245       Teuchos::SerialDenseMatrix<int, ScalarType>& R,
00246       const bool forceNonnegativeDiagonal=false)
00247   {
00248     TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Belos::MultiVec<" 
00249       << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you "
00250       "are using does not implement the TSQR-related method factorExplicit().");
00251   }
00252 
00287   virtual int
00288   revealRank (Teuchos::SerialDenseMatrix<int, ScalarType>& R,
00289         const typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& tol)
00290   {
00291     TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Belos::MultiVec<" 
00292       << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you "
00293       "are using does not implement the TSQR-related method revealRank().");
00294   }
00295 
00297 #endif // HAVE_BELOS_TSQR
00298 };
00299 
00300 
00301 namespace details {
00319 template<class ScalarType>
00320 class MultiVecTsqrAdapter {
00321 public:
00322   typedef MultiVec<ScalarType> MV;
00323   typedef ScalarType scalar_type; 
00324   typedef int ordinal_type; // This doesn't matter either
00325   typedef int node_type; // Nor does this
00326   typedef Teuchos::SerialDenseMatrix<ordinal_type, scalar_type> dense_matrix_type;
00327   typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00328   
00330   void
00331   factorExplicit (MV& A,
00332       MV& Q,
00333       dense_matrix_type& R,
00334       const bool forceNonnegativeDiagonal=false)
00335   {
00336     A.factorExplicit (Q, R, forceNonnegativeDiagonal);
00337   }
00338 
00340   int
00341   revealRank (MV& Q,
00342         dense_matrix_type& R,
00343         const magnitude_type& tol)
00344   {
00345     return Q.revealRank (R, tol);
00346   }
00347 };
00348 } // namespace details
00349 
00359   template<class ScalarType>
00360   class MultiVecTraits<ScalarType,MultiVec<ScalarType> > {
00361   public:
00363 
00364 
00367     static Teuchos::RCP<MultiVec<ScalarType> > 
00368     Clone (const MultiVec<ScalarType>& mv, const int numvecs) {
00369       return Teuchos::rcp (const_cast<MultiVec<ScalarType>&> (mv).Clone (numvecs)); 
00370     }
00372     static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv )
00373     { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy() ); }
00375     static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv, const std::vector<int>& index )
00376     { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy(index) ); }
00378     static Teuchos::RCP<MultiVec<ScalarType> > CloneViewNonConst( MultiVec<ScalarType>& mv, const std::vector<int>& index )
00379     { return Teuchos::rcp( mv.CloneViewNonConst(index) ); }
00381     static Teuchos::RCP<const MultiVec<ScalarType> > CloneView( const MultiVec<ScalarType>& mv, const std::vector<int>& index )
00382     { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneView(index) ); }
00384     static int GetVecLength( const MultiVec<ScalarType>& mv )
00385     { return mv.GetVecLength(); }
00387     static int GetNumberVecs( const MultiVec<ScalarType>& mv )
00388     { return mv.GetNumberVecs(); }
00390     static void MvTimesMatAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, 
00391          const Teuchos::SerialDenseMatrix<int,ScalarType>& B, 
00392          ScalarType beta, MultiVec<ScalarType>& mv )
00393     { mv.MvTimesMatAddMv(alpha, A, B, beta); }
00395     static void MvAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B, MultiVec<ScalarType>& mv )
00396     { mv.MvAddMv(alpha, A, beta, B); }
00398     static void MvScale ( MultiVec<ScalarType>& mv, const ScalarType alpha )
00399     { mv.MvScale( alpha ); } 
00400 
00401     static void MvScale ( MultiVec<ScalarType>& mv, const std::vector<ScalarType>& alpha )
00402     { mv.MvScale(alpha); }
00404     static void MvTransMv( const ScalarType alpha, const MultiVec<ScalarType>& A, const MultiVec<ScalarType>& mv, Teuchos::SerialDenseMatrix<int,ScalarType>& B )
00405     { mv.MvTransMv(alpha, A, B); }
00407     static void MvDot( const MultiVec<ScalarType>& mv, const MultiVec<ScalarType>& A, std::vector<ScalarType>& b )
00408     { mv.MvDot( A, b ); }
00410     static void MvNorm( const MultiVec<ScalarType>& mv, std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>& normvec, NormType type = TwoNorm )
00411     { mv.MvNorm(normvec,type); }
00413     static void SetBlock( const MultiVec<ScalarType>& A, const std::vector<int>& index, MultiVec<ScalarType>& mv )
00414     { mv.SetBlock(A, index); }
00416     static void MvRandom( MultiVec<ScalarType>& mv )
00417     { mv.MvRandom(); }
00419     static void MvInit( MultiVec<ScalarType>& mv, ScalarType alpha = Teuchos::ScalarTraits<ScalarType>::zero() )
00420     { mv.MvInit(alpha); }
00422     static void MvPrint( const MultiVec<ScalarType>& mv, std::ostream& os )
00423     { mv.MvPrint(os); }
00424 
00425 #ifdef HAVE_BELOS_TSQR
00426 
00427 
00428 
00429 
00430 
00431 
00432 
00433     typedef details::MultiVecTsqrAdapter<ScalarType> tsqr_adaptor_type;
00434 #endif // HAVE_BELOS_TSQR
00435   };
00436 
00437 
00438 } // namespace Belos
00439 
00440 #endif
00441 
00442 // end of file BelosMultiVec.hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines