48 #ifndef ANASAZI_TRACEMIN_DAVIDSON_SOLMGR_HPP
49 #define ANASAZI_TRACEMIN_DAVIDSON_SOLMGR_HPP
109 template<
class ScalarType,
class MV,
class OP>
115 typedef Teuchos::ScalarTraits<ScalarType> SCT;
116 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
117 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
149 Teuchos::ParameterList &pl );
158 return (solver->getCurSubspaceDim() == solver->getMaxSubspaceDim());
165 Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > createSolver(
166 const Teuchos::RCP<
SortManager<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
169 Teuchos::ParameterList &plist)
181 template <
class MagnitudeType,
class MV,
class OP>
186 typedef std::complex<MagnitudeType> ScalarType;
189 Teuchos::ParameterList &pl )
192 MagnitudeType::this_class_is_missing_a_specialization();
198 template<
class ScalarType,
class MV,
class OP>
203 maxRestarts_ = pl.get(
"Maximum Restarts", 50);
204 TEUCHOS_TEST_FOR_EXCEPTION(maxRestarts_ <= 0, std::invalid_argument,
205 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Maximum Restarts\" must be strictly positive.");
207 this->useHarmonic_ = pl.get(
"Use Harmonic Ritz Values",
false);
209 TEUCHOS_TEST_FOR_EXCEPTION(this->useHarmonic_ && problem->getM() != Teuchos::null, std::invalid_argument,
"Anasazi::TraceMinDavidsonSolMgr::constructor(): Harmonic Ritz values do not currently work with generalized eigenvalue problems. Please disable \"Use Harmonic Ritz Values\".");
212 this->blockSize_ = pl.get(
"Block Size", 1);
213 TEUCHOS_TEST_FOR_EXCEPTION(this->blockSize_ <= 0, std::invalid_argument,
214 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Block Size\" must be strictly positive.");
216 this->numRestartBlocks_ = (int)std::ceil(this->problem_->getNEV() / this->blockSize_);
217 this->numRestartBlocks_ = pl.get(
"Num Restart Blocks", this->numRestartBlocks_);
218 TEUCHOS_TEST_FOR_EXCEPTION(this->numRestartBlocks_ <= 0, std::invalid_argument,
219 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Restart Blocks\" must be strictly positive.");
221 this->numBlocks_ = pl.get(
"Num Blocks", 3*this->numRestartBlocks_);
222 TEUCHOS_TEST_FOR_EXCEPTION(this->numBlocks_ <= 1, std::invalid_argument,
223 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Blocks\" must be greater than 1. If you only wish to use one block, please use TraceMinSolMgr instead of TraceMinDavidsonSolMgr.");
225 TEUCHOS_TEST_FOR_EXCEPTION(this->numRestartBlocks_ >= this->numBlocks_, std::invalid_argument,
226 "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Blocks\" must be strictly greater than \"Num Restart Blocks\".");
228 std::stringstream ss;
229 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_ <<
" > " <<
MVT::GetGlobalLength(*this->problem_->getInitVec()) <<
".";
230 TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(this->numBlocks_)*this->blockSize_ + this->maxLocked_ >
MVT::GetGlobalLength(*this->problem_->getInitVec()),
231 std::invalid_argument, ss.str());
233 TEUCHOS_TEST_FOR_EXCEPTION(this->maxLocked_ + this->blockSize_ < this->problem_->getNEV(), std::invalid_argument,
234 "Anasazi::TraceMinDavidsonSolMgr: Not enough storage space for requested number of eigenpairs.");
240 template <
class ScalarType,
class MV,
class OP>
243 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
244 Teuchos::TimeMonitor restimer(*this->_timerRestarting);
247 if ( numRestarts >= maxRestarts_ ) {
252 this->printer_->stream(
IterationDetails) <<
" Performing restart number " << numRestarts <<
" of " << maxRestarts_ << std::endl << std::endl;
254 TraceMinBaseState<ScalarType,MV> oldstate = solver->getState();
255 TraceMinBaseState<ScalarType,MV> newstate;
256 int newdim = this->numRestartBlocks_*this->blockSize_;
257 std::vector<int> indToCopy(newdim);
258 for(
int i=0; i<newdim; i++) indToCopy[i] = i;
262 if(this->useHarmonic_)
264 newstate.V = MVT::CloneView(*solver->getRitzVectors(),indToCopy);
265 newstate.curDim = newdim;
270 this->copyPartOfState (oldstate, newstate, indToCopy);
274 newstate.NEV = oldstate.NEV;
275 solver->initialize(newstate);