Anasazi  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AnasaziTraceMinSolMgr.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 
10 #ifndef ANASAZI_TRACEMIN_SOLMGR_HPP
11 #define ANASAZI_TRACEMIN_SOLMGR_HPP
12 
19 #include "AnasaziConfigDefs.hpp"
20 #include "AnasaziTypes.hpp"
21 
22 #include "AnasaziEigenproblem.hpp"
23 #include "AnasaziSolverUtils.hpp"
24 
25 #include "AnasaziTraceMin.hpp"
27 #include "AnasaziBasicSort.hpp"
32 #include "AnasaziOutputManager.hpp"
33 #include "Teuchos_BLAS.hpp"
34 #include "Teuchos_LAPACK.hpp"
35 #include "Teuchos_TimeMonitor.hpp"
36 #ifdef TEUCHOS_DEBUG
37 # include <Teuchos_FancyOStream.hpp>
38 #endif
39 #ifdef HAVE_MPI
40 #include <mpi.h>
41 #endif
42 
43 
44 namespace Anasazi {
45 namespace Experimental {
46 
47 template<class ScalarType, class MV, class OP>
48 
81 class TraceMinSolMgr : public TraceMinBaseSolMgr<ScalarType,MV,OP> {
82 
83  private:
87  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
89 
90  public:
91 
93 
94 
108 
109  private:
110 
111  int maxits_;
112 
113  // Test whether we have exceeded the maximum number of iterations
114  bool exceededMaxIter() { return (this->iter_ >= maxits_); };
115 
116  // TraceMin does not restart, so this will always return false
117  bool needToRestart(const Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver) { return false; };
118 
119  // TraceMin does not restart, so this will throw an exception
120  bool performRestart(int &numRestarts, Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver)
121  { TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Anasazi::TraceMinSolMgr::performRestart(): TraceMin does not perform restarts!"); };
122 
123  // Returns a new TraceMin solver object
126  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &outputtest,
129  );
130 };
131 
132 
133 //---------------------------------------------------------------------------//
134 // Prevent instantiation on complex scalar type
135 // FIXME: this really is just a current flaw in the implementation, TraceMin
136 // *should* work for Hermitian matrices
137 //---------------------------------------------------------------------------//
138 template <class MagnitudeType, class MV, class OP>
139 class TraceMinSolMgr<std::complex<MagnitudeType>,MV,OP>
140 {
141  public:
142 
143  typedef std::complex<MagnitudeType> ScalarType;
145  const RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
147  {
148  // Provide a compile error when attempting to instantiate on complex type
149  MagnitudeType::this_class_is_missing_a_specialization();
150  }
151 };
152 
154 // Constructor - accepts maximum iterations in addition to the other parameters of the abstract base class
155 template<class ScalarType, class MV, class OP>
157  TraceMinBaseSolMgr<ScalarType,MV,OP>(problem,pl)
158 {
159  // Get the maximum number of iterations
160  maxits_ = pl.get("Maximum Iterations", 100);
161  TEUCHOS_TEST_FOR_EXCEPTION(maxits_ < 1, std::invalid_argument, "Anasazi::TraceMinSolMgr::constructor(): \"Maximum Iterations\" must be strictly positive.");
162 
163  // block size: default is 2* nev()
164  // TODO: Find out minimum value
165  this->blockSize_ = pl.get("Block Size",2*this->problem_->getNEV());
166  TEUCHOS_TEST_FOR_EXCEPTION(this->blockSize_ < this->problem_->getNEV(), std::invalid_argument,
167  "Anasazi::TraceMinSolMgr::constructor(): \"Block Size\" must be greater than or equal to the number of desired eigenpairs.");
168 
169  this->useHarmonic_ = pl.get("Use Harmonic Ritz Values", false);
170  TEUCHOS_TEST_FOR_EXCEPTION(this->useHarmonic_, std::invalid_argument,
171  "Anasazi::TraceMinSolMgr::constructor(): Please disable the harmonic Ritz values. It doesn't make sense to use them with TraceMin, which does not use expanding subspaces. Perhaps you wanted TraceMin-Davidson?");
172 
173  // TraceMin does not restart, so the number of blocks and number of restart blocks will always be 1
174  this->numBlocks_ = 1;
175  this->numRestartBlocks_ = 1;
176 
177  TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(this->numBlocks_)*this->blockSize_ + this->maxLocked_ > MVT::GetGlobalLength(*this->problem_->getInitVec()),
178  std::invalid_argument,
179  "Anasazi::TraceMinSolMgr::constructor(): Potentially impossible orthogonality requests. Reduce basis size or locking size.");
180 
181  TEUCHOS_TEST_FOR_EXCEPTION(this->maxLocked_ + this->blockSize_ < this->problem_->getNEV(), std::invalid_argument,
182  "Anasazi::TraceMinDavidsonSolMgr: Not enough storage space for requested number of eigenpairs.");
183 }
184 
185 
187 // Returns a new TraceMin solver object
188 template <class ScalarType, class MV, class OP>
191  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &outputtest,
194  )
195 {
196  return Teuchos::rcp( new TraceMin<ScalarType,MV,OP>(this->problem_,sorter,this->printer_,outputtest,ortho,plist) );
197 }
198 
199 
200 }} // end Anasazi namespace
201 
202 #endif /* ANASAZI_TRACEMIN_SOLMGR_HPP */
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
This class implements a TraceMIN iteration, a preconditioned iteration for solving linear symmetric p...
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.
Basic implementation of the Anasazi::SortManager class.
The Anasazi::TraceMinBaseSolMgr provides an abstract base class for the TraceMin series of solver man...
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
Anasazi&#39;s templated virtual class for providing routines for orthogonalization and orthonormalization...
TraceMinSolMgr(const Teuchos::RCP< Eigenproblem< ScalarType, MV, OP > > &problem, Teuchos::ParameterList &pl)
Basic constructor for TraceMinSolMgr.
Abstract class definition for Anasazi Output Managers.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Abstract base class which defines the interface required by an eigensolver and status test class to c...
A status test for testing the norm of the eigenvectors residuals.
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::TraceMinSolMgr provides a flexible solver manager over the TraceMin eigensolver.
Special StatusTest for printing status tests.
Status test for forming logical combinations of other status tests.
Types and exceptions used within Anasazi solvers and interfaces.
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.
Implementation of the trace minimization eigensolver.
Class which provides internal utilities for the Anasazi solvers.