|
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 00035 #ifndef ANASAZI_TRACEMIN_DAVIDSON_SOLMGR_HPP 00036 #define ANASAZI_TRACEMIN_DAVIDSON_SOLMGR_HPP 00037 00038 #include "AnasaziConfigDefs.hpp" 00039 #include "AnasaziTraceMinBaseSolMgr.hpp" 00040 #include "AnasaziTraceMinDavidson.hpp" 00041 00060 namespace Anasazi { 00061 namespace Experimental { 00062 00096 template<class ScalarType, class MV, class OP> 00097 class TraceMinDavidsonSolMgr : public TraceMinBaseSolMgr<ScalarType,MV,OP> { 00098 00099 private: 00100 typedef MultiVecTraits<ScalarType,MV> MVT; 00101 typedef MultiVecTraitsExt<ScalarType,MV> MVText; 00102 typedef OperatorTraits<ScalarType,MV,OP> OPT; 00103 typedef Teuchos::ScalarTraits<ScalarType> SCT; 00104 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType; 00105 typedef Teuchos::ScalarTraits<MagnitudeType> MT; 00106 00107 public: 00108 00110 00111 00135 TraceMinDavidsonSolMgr( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem, 00136 Teuchos::ParameterList &pl ); 00138 00139 private: 00140 int maxRestarts_; 00141 00142 // Returns true if the subspace is full 00143 bool needToRestart(const Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver) 00144 { 00145 return (solver->getCurSubspaceDim() == solver->getMaxSubspaceDim()); 00146 }; 00147 00148 // Performs a restart by reinitializing TraceMinDavidson with the most significant part of the basis 00149 bool performRestart(int &numRestarts, Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver); 00150 00151 // Returns a TraceMinDavidson solver 00152 Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > createSolver( 00153 const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter, 00154 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &outputtest, 00155 const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho, 00156 Teuchos::ParameterList &plist) 00157 { 00158 return Teuchos::rcp( new TraceMinDavidson<ScalarType,MV,OP>(this->problem_,sorter,this->printer_,outputtest,ortho,plist) ); 00159 }; 00160 }; 00161 00162 00164 // Basic constructor for TraceMinDavidsonSolMgr 00165 template<class ScalarType, class MV, class OP> 00166 TraceMinDavidsonSolMgr<ScalarType,MV,OP>::TraceMinDavidsonSolMgr( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem, Teuchos::ParameterList &pl ) : 00167 TraceMinBaseSolMgr<ScalarType,MV,OP>(problem,pl) 00168 { 00169 // TODO: Come back tot these exceptions and make the descriptions better. 00170 maxRestarts_ = pl.get("Maximum Restarts", 50); 00171 TEUCHOS_TEST_FOR_EXCEPTION(maxRestarts_ <= 0, std::invalid_argument, 00172 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Maximum Restarts\" must be strictly positive."); 00173 00174 // block size: default is 1 00175 this->blockSize_ = pl.get("Block Size", 1); 00176 TEUCHOS_TEST_FOR_EXCEPTION(this->blockSize_ <= 0, std::invalid_argument, 00177 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Block Size\" must be strictly positive."); 00178 00179 this->numRestartBlocks_ = (int)std::ceil(this->problem_->getNEV() / this->blockSize_); 00180 this->numRestartBlocks_ = pl.get("Num Restart Blocks", this->numRestartBlocks_); 00181 TEUCHOS_TEST_FOR_EXCEPTION(this->numRestartBlocks_ <= 0, std::invalid_argument, 00182 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Restart Blocks\" must be strictly positive."); 00183 00184 this->numBlocks_ = pl.get("Num Blocks", 3*this->numRestartBlocks_); 00185 TEUCHOS_TEST_FOR_EXCEPTION(this->numBlocks_ <= 1, std::invalid_argument, 00186 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Blocks\" must be greater than 1. If you only wish to use one block, please use TraceMinSolMgr instead of TraceMinDavidsonSolMgr."); 00187 00188 TEUCHOS_TEST_FOR_EXCEPTION(this->numRestartBlocks_ >= this->numBlocks_, std::invalid_argument, 00189 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Blocks\" must be strictly greater than \"Num Restart Blocks\"."); 00190 00191 std::stringstream ss; 00192 ss << "Anasazi::TraceMinDavidsonSolMgr::constructor(): Potentially impossible orthogonality requests. Reduce basis size (" << static_cast<ptrdiff_t>(this->numBlocks_)*this->blockSize_ << ") or locking size (" << this->maxLocked_ << ") because " << static_cast<ptrdiff_t>(this->numBlocks_) << "*" << this->blockSize_ << " + " << this->maxLocked_ << " > " << MVText::GetGlobalLength(*this->problem_->getInitVec()) << "."; 00193 TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(this->numBlocks_)*this->blockSize_ + this->maxLocked_ > MVText::GetGlobalLength(*this->problem_->getInitVec()), 00194 std::invalid_argument, ss.str()); 00195 00196 TEUCHOS_TEST_FOR_EXCEPTION(this->maxLocked_ + this->blockSize_ < this->problem_->getNEV(), std::invalid_argument, 00197 "Anasazi::TraceMinDavidsonSolMgr: Not enough storage space for requested number of eigenpairs."); 00198 } 00199 00200 00202 // Performs a restart by reinitializing TraceMinDavidson with the most significant part of the basis 00203 template <class ScalarType, class MV, class OP> 00204 bool TraceMinDavidsonSolMgr<ScalarType,MV,OP>::performRestart(int &numRestarts, Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver) 00205 { 00206 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 00207 Teuchos::TimeMonitor restimer(*this->_timerRestarting); 00208 #endif 00209 00210 if ( numRestarts >= maxRestarts_ ) { 00211 return false; // break from while(1){tm_solver->iterate()} 00212 } 00213 numRestarts++; 00214 00215 this->printer_->stream(IterationDetails) << " Performing restart number " << numRestarts << " of " << maxRestarts_ << std::endl << std::endl; 00216 00217 TraceMinBaseState<ScalarType,MV> oldstate = solver->getState(); 00218 TraceMinBaseState<ScalarType,MV> newstate; 00219 int newdim = this->numRestartBlocks_*this->blockSize_; 00220 std::vector<int> indToCopy(newdim); 00221 for(int i=0; i<newdim; i++) indToCopy[i] = i; 00222 00223 // Copy the relevant parts of the old state to the new one 00224 // This may involve computing parts of X 00225 this->copyPartOfState (oldstate, newstate, indToCopy); 00226 00227 // send the new state to the solver 00228 newstate.NEV = oldstate.NEV; 00229 solver->initialize(newstate); 00230 00231 return true; 00232 } 00233 00234 00235 }} // end Anasazi namespace 00236 00237 #endif /* ANASAZI_TraceMinDavidson_SOLMGR_HPP */
1.7.6.1