|
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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 00132 virtual ptrdiff_t GetGlobalLength () const { return static_cast<ptrdiff_t>( this->GetVecLength() ); } 00133 00135 virtual int GetNumberVecs () const = 0; 00136 00138 00139 00140 00142 virtual void 00143 MvTimesMatAddMv (ScalarType alpha, 00144 const MultiVec<ScalarType>& A, 00145 const Teuchos::SerialDenseMatrix<int,ScalarType>& B, ScalarType beta) = 0; 00146 00148 virtual void MvAddMv ( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B ) = 0; 00149 00151 virtual void MvScale ( ScalarType alpha ) = 0; 00152 00154 virtual void MvScale ( const std::vector<ScalarType>& alpha ) = 0; 00155 00159 virtual void MvTransMv ( ScalarType alpha, const MultiVec<ScalarType>& A, Teuchos::SerialDenseMatrix<int,ScalarType>& B 00160 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00161 , ConjType conj = Anasazi::CONJ 00162 #endif 00163 ) const = 0; 00164 00170 virtual void MvDot ( const MultiVec<ScalarType>& A, std::vector<ScalarType> & b 00171 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00172 , ConjType conj = Anasazi::CONJ 00173 #endif 00174 ) const = 0; 00175 00177 00178 00179 00184 virtual void MvNorm ( std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec ) const = 0; 00185 00187 00188 00189 00194 virtual void SetBlock ( const MultiVec<ScalarType>& A, const std::vector<int>& index ) = 0; 00195 00197 virtual void MvRandom () = 0; 00198 00200 virtual void MvInit ( ScalarType alpha ) = 0; 00201 00203 00204 00205 00207 virtual void MvPrint ( std::ostream& os ) const = 0; 00209 00210 #ifdef HAVE_ANASAZI_TSQR 00211 00212 00213 00236 virtual void 00237 factorExplicit (MultiVec<ScalarType>& Q, 00238 Teuchos::SerialDenseMatrix<int, ScalarType>& R, 00239 const bool forceNonnegativeDiagonal=false) 00240 { 00241 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Anasazi::MultiVec<" 00242 << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you " 00243 "are using does not implement the TSQR-related method factorExplicit()."); 00244 } 00245 00280 virtual int 00281 revealRank (Teuchos::SerialDenseMatrix<int, ScalarType>& R, 00282 const typename Teuchos::ScalarTraits<ScalarType>::magnitudeType& tol) 00283 { 00284 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "The Anasazi::MultiVec<" 00285 << Teuchos::TypeNameTraits<ScalarType>::name() << "> subclass which you " 00286 "are using does not implement the TSQR-related method revealRank()."); 00287 } 00288 00290 #endif // HAVE_ANASAZI_TSQR 00291 }; 00292 00293 namespace details { 00311 template<class ScalarType> 00312 class MultiVecTsqrAdapter { 00313 public: 00314 typedef MultiVec<ScalarType> MV; 00315 typedef ScalarType scalar_type; 00316 typedef int ordinal_type; // This doesn't matter either 00317 typedef int node_type; // Nor does this 00318 typedef Teuchos::SerialDenseMatrix<ordinal_type, scalar_type> dense_matrix_type; 00319 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type; 00320 00322 void 00323 factorExplicit (MV& A, 00324 MV& Q, 00325 dense_matrix_type& R, 00326 const bool forceNonnegativeDiagonal=false) 00327 { 00328 A.factorExplicit (Q, R, forceNonnegativeDiagonal); 00329 } 00330 00332 int 00333 revealRank (MV& Q, 00334 dense_matrix_type& R, 00335 const magnitude_type& tol) 00336 { 00337 return Q.revealRank (R, tol); 00338 } 00339 }; 00340 } // namespace details 00341 00351 template<class ScalarType> 00352 class MultiVecTraits<ScalarType,MultiVec<ScalarType> > { 00353 public: 00355 00356 00359 static Teuchos::RCP<MultiVec<ScalarType> > 00360 Clone (const MultiVec<ScalarType>& mv, const int numvecs) { 00361 return Teuchos::rcp (const_cast<MultiVec<ScalarType>&> (mv).Clone (numvecs)); 00362 } 00363 00368 static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv ) 00369 { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy() ); } 00370 00376 static Teuchos::RCP<MultiVec<ScalarType> > CloneCopy( const MultiVec<ScalarType>& mv, const std::vector<int>& index ) 00377 { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneCopy(index) ); } 00378 00384 static Teuchos::RCP<MultiVec<ScalarType> > CloneViewNonConst( MultiVec<ScalarType>& mv, const std::vector<int>& index ) 00385 { return Teuchos::rcp( mv.CloneViewNonConst(index) ); } 00386 00392 static Teuchos::RCP<const MultiVec<ScalarType> > CloneView( const MultiVec<ScalarType>& mv, const std::vector<int>& index ) 00393 { return Teuchos::rcp( const_cast<MultiVec<ScalarType>&>(mv).CloneView(index) ); } 00394 00396 00398 00399 00401 static int GetVecLength( const MultiVec<ScalarType>& mv ) 00402 { return mv.GetVecLength(); } 00403 00405 static int GetNumberVecs( const MultiVec<ScalarType>& mv ) 00406 { return mv.GetNumberVecs(); } 00407 00409 00411 00412 00415 static void MvTimesMatAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, 00416 const Teuchos::SerialDenseMatrix<int,ScalarType>& B, 00417 ScalarType beta, MultiVec<ScalarType>& mv ) 00418 { mv.MvTimesMatAddMv(alpha, A, B, beta); } 00419 00422 static void MvAddMv( ScalarType alpha, const MultiVec<ScalarType>& A, ScalarType beta, const MultiVec<ScalarType>& B, MultiVec<ScalarType>& mv ) 00423 { mv.MvAddMv(alpha, A, beta, B); } 00424 00427 static void MvTransMv( ScalarType alpha, const MultiVec<ScalarType>& A, const MultiVec<ScalarType>& mv, Teuchos::SerialDenseMatrix<int,ScalarType>& B 00428 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00429 , ConjType conj = Anasazi::CONJ 00430 #endif 00431 ) 00432 { mv.MvTransMv(alpha, A, B 00433 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00434 , conj 00435 #endif 00436 ); } 00437 00440 static void MvDot( const MultiVec<ScalarType>& mv, const MultiVec<ScalarType>& A, std::vector<ScalarType> & b 00441 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00442 , ConjType conj = Anasazi::CONJ 00443 #endif 00444 ) 00445 { mv.MvDot( A, b 00446 #ifdef HAVE_ANASAZI_EXPERIMENTAL 00447 , conj 00448 #endif 00449 ); } 00450 00452 static void MvScale ( MultiVec<ScalarType>& mv, ScalarType alpha ) 00453 { mv.MvScale( alpha ); } 00454 00456 static void MvScale ( MultiVec<ScalarType>& mv, const std::vector<ScalarType>& alpha ) 00457 { mv.MvScale( alpha ); } 00458 00460 00461 00462 00466 static void MvNorm( const MultiVec<ScalarType>& mv, std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> & normvec ) 00467 { mv.MvNorm(normvec); } 00468 00470 00471 00472 00477 static void SetBlock( const MultiVec<ScalarType>& A, const std::vector<int>& index, MultiVec<ScalarType>& mv ) 00478 { mv.SetBlock(A, index); } 00479 00482 static void MvRandom( MultiVec<ScalarType>& mv ) 00483 { mv.MvRandom(); } 00484 00487 static void MvInit( MultiVec<ScalarType>& mv, ScalarType alpha = Teuchos::ScalarTraits<ScalarType>::zero() ) 00488 { mv.MvInit(alpha); } 00489 00491 00492 00493 00495 static void MvPrint( const MultiVec<ScalarType>& mv, std::ostream& os ) 00496 { mv.MvPrint(os); } 00497 00499 00500 #ifdef HAVE_ANASAZI_TSQR 00501 00502 00503 00504 00505 00506 00507 00508 typedef details::MultiVecTsqrAdapter<ScalarType> tsqr_adaptor_type; 00509 #endif // HAVE_ANASAZI_TSQR 00510 }; 00511 00528 template<class ScalarType> 00529 class MultiVecTraitsExt<ScalarType, MultiVec<ScalarType> > { 00530 public: 00532 00533 00536 static ptrdiff_t GetGlobalLength( const MultiVec<ScalarType>& mv ) 00537 { return mv.GetGlobalLength(); } 00538 00540 }; 00541 00542 } // namespace Anasazi 00543 00544 #endif 00545 00546 // end of file AnasaziMultiVec.hpp
1.7.6.1