Belos Package Browser (Single Doxygen Collection) Development
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   
00145   virtual int GetNumberVecs () const = 0;
00146 
00148 
00149 
00150 
00152   virtual void 
00153   MvTimesMatAddMv (const ScalarType alpha, 
00154        const MultiVec<ScalarType>& A, 
00155        const Teuchos::SerialDenseMatrix<int,ScalarType>& B, const ScalarType beta) = 0;
00156   
00158   virtual void MvAddMv ( const ScalarType alpha, const MultiVec<ScalarType>& A, const ScalarType beta, const MultiVec<ScalarType>& B ) = 0;
00159   
00161   virtual void MvScale ( const ScalarType alpha ) = 0;
00162   
00164   virtual void MvScale ( const std::vector<ScalarType>& alpha ) = 0;
00165   
00169   virtual void MvTransMv ( const ScalarType alpha, const MultiVec<ScalarType>& A, Teuchos::SerialDenseMatrix<int,ScalarType>& B) const = 0;
00170 
00176   virtual void MvDot ( const MultiVec<ScalarType>& A, std::vector<ScalarType>& b ) const = 0;
00177   
00179 
00180 
00181   
00187   virtual void MvNorm ( std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>& normvec, NormType type = TwoNorm ) const = 0;
00188   
00190 
00191 
00192 
00197   virtual void SetBlock ( const MultiVec<ScalarType>& A, const std::vector<int>& index ) = 0;
00198 
00200   virtual void MvRandom () = 0;
00201   
00203   virtual void MvInit ( const ScalarType alpha ) = 0;
00204   
00206 
00207 
00208 
00210   virtual void MvPrint ( std::ostream& os ) const = 0;
00212 
00213 #ifdef HAVE_BELOS_TSQR
00214 
00215 
00216 
00239   virtual void 
00240   factorExplicit (MultiVec<ScalarType>& Q, 
00241       Teuchos::SerialDenseMatrix<int, ScalarType>& R,
00242       const bool forceNonnegativeDiagonal=false)
00243   {
00244     TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Belos::MultiVec<" 
00245       << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you "
00246       "are using does not implement the TSQR-related method factorExplicit().");
00247   }
00248 
00283   virtual int
00284   revealRank (Teuchos::SerialDenseMatrix<int, ScalarType>& R,
00285         const typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& tol)
00286   {
00287     TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Belos::MultiVec<" 
00288       << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you "
00289       "are using does not implement the TSQR-related method revealRank().");
00290   }
00291 
00293 #endif // HAVE_BELOS_TSQR
00294 };
00295 
00296 
00297 namespace details {
00315 template<class ScalarType>
00316 class MultiVecTsqrAdapter {
00317 public:
00318   typedef MultiVec<ScalarType> MV;
00319   typedef ScalarType scalar_type; 
00320   typedef int ordinal_type; // This doesn't matter either
00321   typedef int node_type; // Nor does this
00322   typedef Teuchos::SerialDenseMatrix<ordinal_type, scalar_type> dense_matrix_type;
00323   typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00324   
00326   void
00327   factorExplicit (MV& A,
00328       MV& Q,
00329       dense_matrix_type& R,
00330       const bool forceNonnegativeDiagonal=false)
00331   {
00332     A.factorExplicit (Q, R, forceNonnegativeDiagonal);
00333   }
00334 
00336   int
00337   revealRank (MV& Q,
00338         dense_matrix_type& R,
00339         const magnitude_type& tol)
00340   {
00341     return Q.revealRank (R, tol);
00342   }
00343 };
00344 } // namespace details
00345 
00355   template<class ScalarType>
00356   class MultiVecTraits<ScalarType,MultiVec<ScalarType> > {
00357   public:
00359 
00360 
00363     static Teuchos::RCP<MultiVec<ScalarType> > 
00364     Clone (const MultiVec<ScalarType>& mv, const int numvecs) {
00365       return Teuchos::rcp (const_cast<MultiVec<ScalarType>&> (mv).Clone (numvecs)); 
00366     }
00368     static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv )
00369     { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy() ); }
00371     static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv, const std::vector<int>& index )
00372     { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy(index) ); }
00374     static Teuchos::RCP<MultiVec<ScalarType> > CloneViewNonConst( MultiVec<ScalarType>& mv, const std::vector<int>& index )
00375     { return Teuchos::rcp( mv.CloneViewNonConst(index) ); }
00377     static Teuchos::RCP<const MultiVec<ScalarType> > CloneView( const MultiVec<ScalarType>& mv, const std::vector<int>& index )
00378     { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneView(index) ); }
00380     static int GetVecLength( const MultiVec<ScalarType>& mv )
00381     { return mv.GetVecLength(); }
00383     static int GetNumberVecs( const MultiVec<ScalarType>& mv )
00384     { return mv.GetNumberVecs(); }
00386     static void MvTimesMatAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, 
00387          const Teuchos::SerialDenseMatrix<int,ScalarType>& B, 
00388          ScalarType beta, MultiVec<ScalarType>& mv )
00389     { mv.MvTimesMatAddMv(alpha, A, B, beta); }
00391     static void MvAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B, MultiVec<ScalarType>& mv )
00392     { mv.MvAddMv(alpha, A, beta, B); }
00394     static void MvScale ( MultiVec<ScalarType>& mv, const ScalarType alpha )
00395     { mv.MvScale( alpha ); } 
00396 
00397     static void MvScale ( MultiVec<ScalarType>& mv, const std::vector<ScalarType>& alpha )
00398     { mv.MvScale(alpha); }
00400     static void MvTransMv( const ScalarType alpha, const MultiVec<ScalarType>& A, const MultiVec<ScalarType>& mv, Teuchos::SerialDenseMatrix<int,ScalarType>& B )
00401     { mv.MvTransMv(alpha, A, B); }
00403     static void MvDot( const MultiVec<ScalarType>& mv, const MultiVec<ScalarType>& A, std::vector<ScalarType>& b )
00404     { mv.MvDot( A, b ); }
00406     static void MvNorm( const MultiVec<ScalarType>& mv, std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>& normvec, NormType type = TwoNorm )
00407     { mv.MvNorm(normvec,type); }
00409     static void SetBlock( const MultiVec<ScalarType>& A, const std::vector<int>& index, MultiVec<ScalarType>& mv )
00410     { mv.SetBlock(A, index); }
00412     static void MvRandom( MultiVec<ScalarType>& mv )
00413     { mv.MvRandom(); }
00415     static void MvInit( MultiVec<ScalarType>& mv, ScalarType alpha = Teuchos::ScalarTraits<ScalarType>::zero() )
00416     { mv.MvInit(alpha); }
00418     static void MvPrint( const MultiVec<ScalarType>& mv, std::ostream& os )
00419     { mv.MvPrint(os); }
00420 
00421 #ifdef HAVE_BELOS_TSQR
00422 
00423 
00424 
00425 
00426 
00427 
00428 
00429     typedef details::MultiVecTsqrAdapter<ScalarType> tsqr_adaptor_type;
00430 #endif // HAVE_BELOS_TSQR
00431   };
00432 
00433 
00434 } // namespace Belos
00435 
00436 #endif
00437 
00438 // end of file BelosMultiVec.hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines