Anasazi  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AnasaziTraceMinDavidsonSolMgr.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Anasazi: Block Eigensolvers Package
4 //
5 // Copyright 2004 NTESS and the Anasazi contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
16 #ifndef ANASAZI_TRACEMIN_DAVIDSON_SOLMGR_HPP
17 #define ANASAZI_TRACEMIN_DAVIDSON_SOLMGR_HPP
18 
19 #include "AnasaziConfigDefs.hpp"
22 
41 namespace Anasazi {
42 namespace Experimental {
43 
77 template<class ScalarType, class MV, class OP>
78 class TraceMinDavidsonSolMgr : public TraceMinBaseSolMgr<ScalarType,MV,OP> {
79 
80  private:
84  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
86 
87  public:
88 
90 
91 
119 
120  private:
121  int maxRestarts_;
122 
123  // Returns true if the subspace is full
124  bool needToRestart(const Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver)
125  {
126  return (solver->getCurSubspaceDim() == solver->getMaxSubspaceDim());
127  };
128 
129  // Performs a restart by reinitializing TraceMinDavidson with the most significant part of the basis
130  bool performRestart(int &numRestarts, Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver);
131 
132  // Returns a TraceMinDavidson solver
135  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &outputtest,
137  Teuchos::ParameterList &plist)
138  {
139  return Teuchos::rcp( new TraceMinDavidson<ScalarType,MV,OP>(this->problem_,sorter,this->printer_,outputtest,ortho,plist) );
140  };
141 };
142 
143 
144 //---------------------------------------------------------------------------//
145 // Prevent instantiation on complex scalar type
146 // FIXME: this really is just a current flaw in the implementation, TraceMin
147 // *should* work for Hermitian matrices
148 //---------------------------------------------------------------------------//
149 template <class MagnitudeType, class MV, class OP>
150 class TraceMinDavidsonSolMgr<std::complex<MagnitudeType>,MV,OP>
151 {
152  public:
153 
154  typedef std::complex<MagnitudeType> ScalarType;
156  const RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
158  {
159  // Provide a compile error when attempting to instantiate on complex type
160  MagnitudeType::this_class_is_missing_a_specialization();
161  }
162 };
163 
165 // Basic constructor for TraceMinDavidsonSolMgr
166 template<class ScalarType, class MV, class OP>
168  TraceMinBaseSolMgr<ScalarType,MV,OP>(problem,pl)
169 {
170  // TODO: Come back tot these exceptions and make the descriptions better.
171  maxRestarts_ = pl.get("Maximum Restarts", 50);
172  TEUCHOS_TEST_FOR_EXCEPTION(maxRestarts_ <= 0, std::invalid_argument,
173  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Maximum Restarts\" must be strictly positive.");
174 
175  this->useHarmonic_ = pl.get("Use Harmonic Ritz Values", false);
176 
177  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\".");
178 
179  // block size: default is 1
180  this->blockSize_ = pl.get("Block Size", 1);
181  TEUCHOS_TEST_FOR_EXCEPTION(this->blockSize_ <= 0, std::invalid_argument,
182  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Block Size\" must be strictly positive.");
183 
184  this->numRestartBlocks_ = (int)std::ceil(this->problem_->getNEV() / this->blockSize_);
185  this->numRestartBlocks_ = pl.get("Num Restart Blocks", this->numRestartBlocks_);
186  TEUCHOS_TEST_FOR_EXCEPTION(this->numRestartBlocks_ <= 0, std::invalid_argument,
187  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Restart Blocks\" must be strictly positive.");
188 
189  this->numBlocks_ = pl.get("Num Blocks", 3*this->numRestartBlocks_);
190  TEUCHOS_TEST_FOR_EXCEPTION(this->numBlocks_ <= 1, std::invalid_argument,
191  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Blocks\" must be greater than 1. If you only wish to use one block, please use TraceMinSolMgr instead of TraceMinDavidsonSolMgr.");
192 
193  TEUCHOS_TEST_FOR_EXCEPTION(this->numRestartBlocks_ >= this->numBlocks_, std::invalid_argument,
194  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Blocks\" must be strictly greater than \"Num Restart Blocks\".");
195 
196  std::stringstream ss;
197  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()) << ".";
198  TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(this->numBlocks_)*this->blockSize_ + this->maxLocked_ > MVT::GetGlobalLength(*this->problem_->getInitVec()),
199  std::invalid_argument, ss.str());
200 
201  TEUCHOS_TEST_FOR_EXCEPTION(this->maxLocked_ + this->blockSize_ < this->problem_->getNEV(), std::invalid_argument,
202  "Anasazi::TraceMinDavidsonSolMgr: Not enough storage space for requested number of eigenpairs.");
203 }
204 
205 
207 // Performs a restart by reinitializing TraceMinDavidson with the most significant part of the basis
208 template <class ScalarType, class MV, class OP>
210 {
211 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
212  Teuchos::TimeMonitor restimer(*this->_timerRestarting);
213 #endif
214 
215  if ( numRestarts >= maxRestarts_ ) {
216  return false; // break from while(1){tm_solver->iterate()}
217  }
218  numRestarts++;
219 
220  this->printer_->stream(IterationDetails) << " Performing restart number " << numRestarts << " of " << maxRestarts_ << std::endl << std::endl;
221 
222  TraceMinBaseState<ScalarType,MV> oldstate = solver->getState();
223  TraceMinBaseState<ScalarType,MV> newstate;
224  int newdim = this->numRestartBlocks_*this->blockSize_;
225  std::vector<int> indToCopy(newdim);
226  for(int i=0; i<newdim; i++) indToCopy[i] = i;
227 
228  // Copy the relevant parts of the old state to the new one
229  // This may involve computing parts of X
230  if(this->useHarmonic_)
231  {
232  newstate.V = MVT::CloneView(*solver->getRitzVectors(),indToCopy);
233  newstate.curDim = newdim;
234 
235  }
236  else
237  {
238  this->copyPartOfState (oldstate, newstate, indToCopy);
239  }
240 
241  // send the new state to the solver
242  newstate.NEV = oldstate.NEV;
243  solver->initialize(newstate);
244 
245  return true;
246 }
247 
248 
249 }} // end Anasazi namespace
250 
251 #endif /* ANASAZI_TraceMinDavidson_SOLMGR_HPP */
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
This class defines the interface required by an eigensolver and status test class to compute solution...
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Virtual base class which defines basic traits for the operator type.
TraceMinDavidsonSolMgr(const Teuchos::RCP< Eigenproblem< ScalarType, MV, OP > > &problem, Teuchos::ParameterList &pl)
Basic constructor for TraceMinDavidsonSolMgr.
The Anasazi::TraceMinBaseSolMgr provides an abstract base class for the TraceMin series of solver man...
Anasazi&#39;s templated virtual class for providing routines for orthogonalization and orthonormalization...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Traits class which defines basic operations on multivectors.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
The Anasazi::TraceMinBaseSolMgr provides an abstract base class for the TraceMin series of solver man...
The Anasazi::TraceMinDavidsonSolMgr provides a flexible solver manager over the TraceMinDavidson eige...
This class implements a TraceMin-Davidson iteration for solving symmetric generalized eigenvalue prob...
Implementation of the TraceMin-Davidson method.
This is an abstract base class for the trace minimization eigensolvers.
Anasazi&#39;s templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
Common interface of stopping criteria for Anasazi&#39;s solvers.