|
Anasazi
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Anasazi: Block Eigensolvers Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef ANASAZI_MULTI_VEC_HPP 00030 #define ANASAZI_MULTI_VEC_HPP 00031 00046 00047 #include "AnasaziConfigDefs.hpp" 00048 #include "AnasaziMultiVecTraits.hpp" 00049 00050 namespace Anasazi { 00051 00076 template <class ScalarType> 00077 class MultiVec { 00078 public: 00080 00081 00082 MultiVec() {} 00083 00085 virtual ~MultiVec () {} 00086 00088 00089 00090 00093 virtual MultiVec<ScalarType> * Clone ( const int numvecs ) const = 0; 00094 00097 virtual MultiVec<ScalarType> * CloneCopy () const = 0; 00098 00105 virtual MultiVec<ScalarType> * CloneCopy ( const std::vector<int>& index ) const = 0; 00106 00113 virtual MultiVec<ScalarType> * CloneViewNonConst ( const std::vector<int>& index ) = 0; 00114 00121 virtual const MultiVec<ScalarType> * CloneView ( const std::vector<int>& index ) const = 0; 00122 00124 00125 00126 00128 virtual int GetVecLength () const = 0; 00129 00131 virtual int GetNumberVecs () const = 0; 00132 00134 00135 00136 00138 virtual void 00139 MvTimesMatAddMv (ScalarType alpha, 00140 const MultiVec<ScalarType>& A, 00141 const Teuchos::SerialDenseMatrix<int,ScalarType>& B, ScalarType beta) = 0; 00142 00144 virtual void MvAddMv ( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B ) = 0; 00145 00147 virtual void MvScale ( ScalarType alpha ) = 0; 00148 00150 virtual void MvScale ( const std::vector<ScalarType>& alpha ) = 0; 00151 00155 virtual void MvTransMv ( ScalarType alpha, const MultiVec<ScalarType>& A, Teuchos::SerialDenseMatrix<int,ScalarType>& B 00156 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00157 , ConjType conj = Anasazi::CONJ 00158 #endif 00159 ) const = 0; 00160 00166 virtual void MvDot ( const MultiVec<ScalarType>& A, std::vector<ScalarType> & b 00167 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00168 , ConjType conj = Anasazi::CONJ 00169 #endif 00170 ) const = 0; 00171 00173 00174 00175 00180 virtual void MvNorm ( std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec ) const = 0; 00181 00183 00184 00185 00190 virtual void SetBlock ( const MultiVec<ScalarType>& A, const std::vector<int>& index ) = 0; 00191 00193 virtual void MvRandom () = 0; 00194 00196 virtual void MvInit ( ScalarType alpha ) = 0; 00197 00199 00200 00201 00203 virtual void MvPrint ( std::ostream& os ) const = 0; 00205 00206 #ifdef HAVE_ANASAZI_TSQR 00207 00208 00209 00232 virtual void 00233 factorExplicit (MultiVec<ScalarType>& Q, 00234 Teuchos::SerialDenseMatrix<int, ScalarType>& R, 00235 const bool forceNonnegativeDiagonal=false) 00236 { 00237 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Anasazi::MultiVec<" 00238 << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you " 00239 "are using does not implement the TSQR-related method factorExplicit()."); 00240 } 00241 00276 virtual int 00277 revealRank (Teuchos::SerialDenseMatrix<int, ScalarType>& R, 00278 const typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& tol) 00279 { 00280 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Anasazi::MultiVec<" 00281 << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you " 00282 "are using does not implement the TSQR-related method revealRank()."); 00283 } 00284 00286 #endif // HAVE_ANASAZI_TSQR 00287 }; 00288 00289 namespace details { 00307 template<class ScalarType> 00308 class MultiVecTsqrAdapter { 00309 public: 00310 typedef MultiVec<ScalarType> MV; 00311 typedef ScalarType scalar_type; 00312 typedef int ordinal_type; // This doesn't matter either 00313 typedef int node_type; // Nor does this 00314 typedef Teuchos::SerialDenseMatrix<ordinal_type, scalar_type> dense_matrix_type; 00315 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type; 00316 00318 void 00319 factorExplicit (MV& A, 00320 MV& Q, 00321 dense_matrix_type& R, 00322 const bool forceNonnegativeDiagonal=false) 00323 { 00324 A.factorExplicit (Q, R, forceNonnegativeDiagonal); 00325 } 00326 00328 int 00329 revealRank (MV& Q, 00330 dense_matrix_type& R, 00331 const magnitude_type& tol) 00332 { 00333 return Q.revealRank (R, tol); 00334 } 00335 }; 00336 } // namespace details 00337 00347 template<class ScalarType> 00348 class MultiVecTraits<ScalarType,MultiVec<ScalarType> > { 00349 public: 00351 00352 00355 static Teuchos::RCP<MultiVec<ScalarType> > 00356 Clone (const MultiVec<ScalarType>& mv, const int numvecs) { 00357 return Teuchos::rcp (const_cast<MultiVec<ScalarType>&> (mv).Clone (numvecs)); 00358 } 00359 00364 static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv ) 00365 { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy() ); } 00366 00372 static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv, const std::vector<int>& index ) 00373 { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy(index) ); } 00374 00380 static Teuchos::RCP<MultiVec<ScalarType> > CloneViewNonConst( MultiVec<ScalarType>& mv, const std::vector<int>& index ) 00381 { return Teuchos::rcp( mv.CloneViewNonConst(index) ); } 00382 00388 static Teuchos::RCP<const MultiVec<ScalarType> > CloneView( const MultiVec<ScalarType>& mv, const std::vector<int>& index ) 00389 { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneView(index) ); } 00390 00392 00394 00395 00397 static int GetVecLength( const MultiVec<ScalarType>& mv ) 00398 { return mv.GetVecLength(); } 00399 00401 static int GetNumberVecs( const MultiVec<ScalarType>& mv ) 00402 { return mv.GetNumberVecs(); } 00403 00405 00407 00408 00411 static void MvTimesMatAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, 00412 const Teuchos::SerialDenseMatrix<int,ScalarType>& B, 00413 ScalarType beta, MultiVec<ScalarType>& mv ) 00414 { mv.MvTimesMatAddMv(alpha, A, B, beta); } 00415 00418 static void MvAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B, MultiVec<ScalarType>& mv ) 00419 { mv.MvAddMv(alpha, A, beta, B); } 00420 00423 static void MvTransMv( ScalarType alpha, const MultiVec<ScalarType>& A, const MultiVec<ScalarType>& mv, Teuchos::SerialDenseMatrix<int,ScalarType>& B 00424 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00425 , ConjType conj = Anasazi::CONJ 00426 #endif 00427 ) 00428 { mv.MvTransMv(alpha, A, B 00429 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00430 , conj 00431 #endif 00432 ); } 00433 00436 static void MvDot( const MultiVec<ScalarType>& mv, const MultiVec<ScalarType>& A, std::vector<ScalarType> & b 00437 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00438 , ConjType conj = Anasazi::CONJ 00439 #endif 00440 ) 00441 { mv.MvDot( A, b 00442 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00443 , conj 00444 #endif 00445 ); } 00446 00448 static void MvScale ( MultiVec<ScalarType>& mv, ScalarType alpha ) 00449 { mv.MvScale( alpha ); } 00450 00452 static void MvScale ( MultiVec<ScalarType>& mv, const std::vector<ScalarType>& alpha ) 00453 { mv.MvScale( alpha ); } 00454 00456 00457 00458 00462 static void MvNorm( const MultiVec<ScalarType>& mv, std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec ) 00463 { mv.MvNorm(normvec); } 00464 00466 00467 00468 00473 static void SetBlock( const MultiVec<ScalarType>& A, const std::vector<int>& index, MultiVec<ScalarType>& mv ) 00474 { mv.SetBlock(A, index); } 00475 00478 static void MvRandom( MultiVec<ScalarType>& mv ) 00479 { mv.MvRandom(); } 00480 00483 static void MvInit( MultiVec<ScalarType>& mv, ScalarType alpha = Teuchos::ScalarTraits<ScalarType>::zero() ) 00484 { mv.MvInit(alpha); } 00485 00487 00488 00489 00491 static void MvPrint( const MultiVec<ScalarType>& mv, std::ostream& os ) 00492 { mv.MvPrint(os); } 00493 00495 00496 #ifdef HAVE_ANASAZI_TSQR 00497 00498 00499 00500 00501 00502 00503 00504 typedef details::MultiVecTsqrAdapter<ScalarType> tsqr_adaptor_type; 00505 #endif // HAVE_ANASAZI_TSQR 00506 }; 00507 00508 00509 } // namespace Anasazi 00510 00511 #endif 00512 00513 // end of file AnasaziMultiVec.hpp
1.7.6.1