Anasazi  Version of the Day
AnasaziTraceMinSolMgr.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 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef ANASAZI_TRACEMIN_SOLMGR_HPP
43 #define ANASAZI_TRACEMIN_SOLMGR_HPP
44 
51 #include "AnasaziConfigDefs.hpp"
52 #include "AnasaziTypes.hpp"
53 
54 #include "AnasaziEigenproblem.hpp"
55 #include "AnasaziSolverUtils.hpp"
56 
57 #include "AnasaziTraceMin.hpp"
59 #include "AnasaziBasicSort.hpp"
64 #include "AnasaziOutputManager.hpp"
65 #include "Teuchos_BLAS.hpp"
66 #include "Teuchos_LAPACK.hpp"
67 #include "Teuchos_TimeMonitor.hpp"
68 #ifdef TEUCHOS_DEBUG
69 # include <Teuchos_FancyOStream.hpp>
70 #endif
71 #ifdef HAVE_MPI
72 #include <mpi.h>
73 #endif
74 
75 
76 namespace Anasazi {
77 namespace Experimental {
78 
79 template<class ScalarType, class MV, class OP>
80 
113 class TraceMinSolMgr : public TraceMinBaseSolMgr<ScalarType,MV,OP> {
114 
115  private:
118  typedef Teuchos::ScalarTraits<ScalarType> SCT;
119  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
120  typedef Teuchos::ScalarTraits<MagnitudeType> MT;
121 
122  public:
123 
125 
126 
137  TraceMinSolMgr( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
138  Teuchos::ParameterList &pl );
140 
141  private:
142 
143  int maxits_;
144 
145  // Test whether we have exceeded the maximum number of iterations
146  bool exceededMaxIter() { return (this->iter_ >= maxits_); };
147 
148  // TraceMin does not restart, so this will always return false
149  bool needToRestart(const Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver) { return false; };
150 
151  // TraceMin does not restart, so this will throw an exception
152  bool performRestart(int &numRestarts, Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver)
153  { TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Anasazi::TraceMinSolMgr::performRestart(): TraceMin does not perform restarts!"); };
154 
155  // Returns a new TraceMin solver object
156  Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > createSolver(
157  const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
158  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &outputtest,
159  const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho,
160  Teuchos::ParameterList &plist
161  );
162 };
163 
164 
165 //---------------------------------------------------------------------------//
166 // Prevent instantiation on complex scalar type
167 // FIXME: this really is just a current flaw in the implementation, TraceMin
168 // *should* work for Hermitian matrices
169 //---------------------------------------------------------------------------//
170 template <class MagnitudeType, class MV, class OP>
171 class TraceMinSolMgr<std::complex<MagnitudeType>,MV,OP>
172 {
173  public:
174 
175  typedef std::complex<MagnitudeType> ScalarType;
177  const RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
178  Teuchos::ParameterList &pl )
179  {
180  // Provide a compile error when attempting to instantiate on complex type
181  MagnitudeType::this_class_is_missing_a_specialization();
182  }
183 };
184 
186 // Constructor - accepts maximum iterations in addition to the other parameters of the abstract base class
187 template<class ScalarType, class MV, class OP>
188 TraceMinSolMgr<ScalarType,MV,OP>::TraceMinSolMgr( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem, Teuchos::ParameterList &pl ) :
189  TraceMinBaseSolMgr<ScalarType,MV,OP>(problem,pl)
190 {
191  // Get the maximum number of iterations
192  maxits_ = pl.get("Maximum Iterations", 100);
193  TEUCHOS_TEST_FOR_EXCEPTION(maxits_ < 1, std::invalid_argument, "Anasazi::TraceMinSolMgr::constructor(): \"Maximum Iterations\" must be strictly positive.");
194 
195  // block size: default is 2* nev()
196  // TODO: Find out minimum value
197  this->blockSize_ = pl.get("Block Size",2*this->problem_->getNEV());
198  TEUCHOS_TEST_FOR_EXCEPTION(this->blockSize_ < this->problem_->getNEV(), std::invalid_argument,
199  "Anasazi::TraceMinSolMgr::constructor(): \"Block Size\" must be greater than or equal to the number of desired eigenpairs.");
200 
201  this->useHarmonic_ = pl.get("Use Harmonic Ritz Values", false);
202  TEUCHOS_TEST_FOR_EXCEPTION(this->useHarmonic_, std::invalid_argument,
203  "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?");
204 
205  // TraceMin does not restart, so the number of blocks and number of restart blocks will always be 1
206  this->numBlocks_ = 1;
207  this->numRestartBlocks_ = 1;
208 
209  TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(this->numBlocks_)*this->blockSize_ + this->maxLocked_ > MVT::GetGlobalLength(*this->problem_->getInitVec()),
210  std::invalid_argument,
211  "Anasazi::TraceMinSolMgr::constructor(): Potentially impossible orthogonality requests. Reduce basis size or locking size.");
212 
213  TEUCHOS_TEST_FOR_EXCEPTION(this->maxLocked_ + this->blockSize_ < this->problem_->getNEV(), std::invalid_argument,
214  "Anasazi::TraceMinDavidsonSolMgr: Not enough storage space for requested number of eigenpairs.");
215 }
216 
217 
219 // Returns a new TraceMin solver object
220 template <class ScalarType, class MV, class OP>
221 Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > TraceMinSolMgr<ScalarType,MV,OP>::createSolver(
222  const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
223  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &outputtest,
224  const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho,
225  Teuchos::ParameterList &plist
226  )
227 {
228  return Teuchos::rcp( new TraceMin<ScalarType,MV,OP>(this->problem_,sorter,this->printer_,outputtest,ortho,plist) );
229 }
230 
231 
232 }} // end Anasazi namespace
233 
234 #endif /* ANASAZI_TRACEMIN_SOLMGR_HPP */
AnasaziStatusTestOutput.hpp
Special StatusTest for printing status tests.
Anasazi::MultiVecTraits
Traits class which defines basic operations on multivectors.
Definition: AnasaziMultiVecTraits.hpp:127
AnasaziBasicSort.hpp
Basic implementation of the Anasazi::SortManager class.
Anasazi::Experimental::TraceMin
This class implements a TraceMIN iteration, a preconditioned iteration for solving linear symmetric p...
Definition: AnasaziTraceMin.hpp:131
AnasaziTypes.hpp
Types and exceptions used within Anasazi solvers and interfaces.
AnasaziSolverUtils.hpp
Class which provides internal utilities for the Anasazi solvers.
Anasazi::SortManager
Anasazi's templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
Definition: AnasaziSortManager.hpp:79
AnasaziEigenproblem.hpp
Abstract base class which defines the interface required by an eigensolver and status test class to c...
AnasaziStatusTestCombo.hpp
Status test for forming logical combinations of other status tests.
AnasaziStatusTestResNorm.hpp
A status test for testing the norm of the eigenvectors residuals.
Anasazi::MultiVecTraits::GetGlobalLength
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
Definition: AnasaziMultiVecTraits.hpp:210
Experimental
Anasazi::MatOrthoManager
Anasazi's templated virtual class for providing routines for orthogonalization and orthonormalization...
Definition: AnasaziMatOrthoManager.hpp:76
Anasazi::OperatorTraits
Virtual base class which defines basic traits for the operator type.
Definition: AnasaziOperatorTraits.hpp:84
Anasazi::Experimental::TraceMinBaseSolMgr
The Anasazi::TraceMinBaseSolMgr provides an abstract base class for the TraceMin series of solver man...
Definition: AnasaziTraceMinBaseSolMgr.hpp:111
AnasaziTraceMinBaseSolMgr.hpp
The Anasazi::TraceMinBaseSolMgr provides an abstract base class for the TraceMin series of solver man...
Anasazi::Experimental::TraceMinSolMgr::TraceMinSolMgr
TraceMinSolMgr(const Teuchos::RCP< Eigenproblem< ScalarType, MV, OP > > &problem, Teuchos::ParameterList &pl)
Basic constructor for TraceMinSolMgr.
Definition: AnasaziTraceMinSolMgr.hpp:188
Anasazi::Experimental::TraceMinSolMgr
The Anasazi::TraceMinSolMgr provides a flexible solver manager over the TraceMin eigensolver.
Definition: AnasaziTraceMinSolMgr.hpp:113
Anasazi
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
Anasazi::Experimental::TraceMinBase
This is an abstract base class for the trace minimization eigensolvers.
Definition: AnasaziTraceMinBase.hpp:182
Anasazi::Eigenproblem
This class defines the interface required by an eigensolver and status test class to compute solution...
Definition: AnasaziEigenproblem.hpp:64
Anasazi::StatusTest
Common interface of stopping criteria for Anasazi's solvers.
Definition: AnasaziStatusTest.hpp:75
AnasaziTraceMin.hpp
Implementation of the trace minimization eigensolver.
AnasaziConfigDefs.hpp
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
AnasaziStatusTestWithOrdering.hpp
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
AnasaziOutputManager.hpp
Abstract class definition for Anasazi Output Managers.