Anasazi  Version of the Day
AnasaziTraceMinDavidsonSolMgr.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Anasazi: Block Eigensolvers Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
25 //
26 // ***********************************************************************
27 // @HEADER
28 
35 #ifndef ANASAZI_TRACEMIN_DAVIDSON_SOLMGR_HPP
36 #define ANASAZI_TRACEMIN_DAVIDSON_SOLMGR_HPP
37 
38 #include "AnasaziConfigDefs.hpp"
41 
60 namespace Anasazi {
61 namespace Experimental {
62 
96 template<class ScalarType, class MV, class OP>
97 class TraceMinDavidsonSolMgr : public TraceMinBaseSolMgr<ScalarType,MV,OP> {
98 
99  private:
102  typedef Teuchos::ScalarTraits<ScalarType> SCT;
103  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
104  typedef Teuchos::ScalarTraits<MagnitudeType> MT;
105 
106  public:
107 
109 
110 
135  TraceMinDavidsonSolMgr( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
136  Teuchos::ParameterList &pl );
138 
139  private:
140  int maxRestarts_;
141 
142  // Returns true if the subspace is full
143  bool needToRestart(const Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver)
144  {
145  return (solver->getCurSubspaceDim() == solver->getMaxSubspaceDim());
146  };
147 
148  // Performs a restart by reinitializing TraceMinDavidson with the most significant part of the basis
149  bool performRestart(int &numRestarts, Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver);
150 
151  // Returns a TraceMinDavidson solver
152  Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > createSolver(
153  const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
154  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &outputtest,
155  const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho,
156  Teuchos::ParameterList &plist)
157  {
158  return Teuchos::rcp( new TraceMinDavidson<ScalarType,MV,OP>(this->problem_,sorter,this->printer_,outputtest,ortho,plist) );
159  };
160 };
161 
162 
164 // Basic constructor for TraceMinDavidsonSolMgr
165 template<class ScalarType, class MV, class OP>
166 TraceMinDavidsonSolMgr<ScalarType,MV,OP>::TraceMinDavidsonSolMgr( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem, Teuchos::ParameterList &pl ) :
167  TraceMinBaseSolMgr<ScalarType,MV,OP>(problem,pl)
168 {
169  // TODO: Come back tot these exceptions and make the descriptions better.
170  maxRestarts_ = pl.get("Maximum Restarts", 50);
171  TEUCHOS_TEST_FOR_EXCEPTION(maxRestarts_ <= 0, std::invalid_argument,
172  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Maximum Restarts\" must be strictly positive.");
173 
174  this->useHarmonic_ = pl.get("Use Harmonic Ritz Values", false);
175 
176  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\".");
177 
178  // block size: default is 1
179  this->blockSize_ = pl.get("Block Size", 1);
180  TEUCHOS_TEST_FOR_EXCEPTION(this->blockSize_ <= 0, std::invalid_argument,
181  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Block Size\" must be strictly positive.");
182 
183  this->numRestartBlocks_ = (int)std::ceil(this->problem_->getNEV() / this->blockSize_);
184  this->numRestartBlocks_ = pl.get("Num Restart Blocks", this->numRestartBlocks_);
185  TEUCHOS_TEST_FOR_EXCEPTION(this->numRestartBlocks_ <= 0, std::invalid_argument,
186  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Restart Blocks\" must be strictly positive.");
187 
188  this->numBlocks_ = pl.get("Num Blocks", 3*this->numRestartBlocks_);
189  TEUCHOS_TEST_FOR_EXCEPTION(this->numBlocks_ <= 1, std::invalid_argument,
190  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Blocks\" must be greater than 1. If you only wish to use one block, please use TraceMinSolMgr instead of TraceMinDavidsonSolMgr.");
191 
192  TEUCHOS_TEST_FOR_EXCEPTION(this->numRestartBlocks_ >= this->numBlocks_, std::invalid_argument,
193  "Anasazi::TraceMinDavidsonSolMgr::constructor(): \"Num Blocks\" must be strictly greater than \"Num Restart Blocks\".");
194 
195  std::stringstream ss;
196  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()) << ".";
197  TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(this->numBlocks_)*this->blockSize_ + this->maxLocked_ > MVT::GetGlobalLength(*this->problem_->getInitVec()),
198  std::invalid_argument, ss.str());
199 
200  TEUCHOS_TEST_FOR_EXCEPTION(this->maxLocked_ + this->blockSize_ < this->problem_->getNEV(), std::invalid_argument,
201  "Anasazi::TraceMinDavidsonSolMgr: Not enough storage space for requested number of eigenpairs.");
202 }
203 
204 
206 // Performs a restart by reinitializing TraceMinDavidson with the most significant part of the basis
207 template <class ScalarType, class MV, class OP>
209 {
210 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
211  Teuchos::TimeMonitor restimer(*this->_timerRestarting);
212 #endif
213 
214  if ( numRestarts >= maxRestarts_ ) {
215  return false; // break from while(1){tm_solver->iterate()}
216  }
217  numRestarts++;
218 
219  this->printer_->stream(IterationDetails) << " Performing restart number " << numRestarts << " of " << maxRestarts_ << std::endl << std::endl;
220 
221  TraceMinBaseState<ScalarType,MV> oldstate = solver->getState();
222  TraceMinBaseState<ScalarType,MV> newstate;
223  int newdim = this->numRestartBlocks_*this->blockSize_;
224  std::vector<int> indToCopy(newdim);
225  for(int i=0; i<newdim; i++) indToCopy[i] = i;
226 
227  // Copy the relevant parts of the old state to the new one
228  // This may involve computing parts of X
229  if(this->useHarmonic_)
230  {
231  newstate.V = MVT::CloneView(*solver->getRitzVectors(),indToCopy);
232  newstate.curDim = newdim;
233 
234  }
235  else
236  {
237  this->copyPartOfState (oldstate, newstate, indToCopy);
238  }
239 
240  // send the new state to the solver
241  newstate.NEV = oldstate.NEV;
242  solver->initialize(newstate);
243 
244  return true;
245 }
246 
247 
248 }} // end Anasazi namespace
249 
250 #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...
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...
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
Anasazi&#39;s templated virtual class for providing routines for orthogonalization and orthonormalization...
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.