42 #ifndef ANASAZI_GENERALIZED_DAVIDSON_SOLMGR_HPP 43 #define ANASAZI_GENERALIZED_DAVIDSON_SOLMGR_HPP 49 #include "Teuchos_ParameterList.hpp" 50 #include "Teuchos_RCPDecl.hpp" 90 template <
class ScalarType,
class MV,
class OP>
124 Teuchos::ParameterList &pl );
147 typedef Teuchos::ScalarTraits<ScalarType> ST;
148 typedef typename ST::magnitudeType MagnitudeType;
149 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
151 RCP< Eigenproblem<ScalarType,MV,OP> > d_problem;
152 RCP< GeneralizedDavidson<ScalarType,MV,OP> > d_solver;
153 RCP< OutputManager<ScalarType> > d_outputMan;
154 RCP< OrthoManager<ScalarType,MV> > d_orthoMan;
155 RCP< SortManager<MagnitudeType> > d_sortMan;
156 RCP< StatusTest<ScalarType,MV,OP> > d_tester;
165 template <
class MagnitudeType,
class MV,
class OP>
170 typedef std::complex<MagnitudeType> ScalarType;
173 Teuchos::ParameterList &pl )
176 MagnitudeType::this_class_is_missing_a_specialization();
187 template <
class ScalarType,
class MV,
class OP>
190 Teuchos::ParameterList &pl )
193 TEUCHOS_TEST_FOR_EXCEPTION( d_problem == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager." );
194 TEUCHOS_TEST_FOR_EXCEPTION( !d_problem->isProblemSet(), std::invalid_argument,
"Problem not set." );
195 TEUCHOS_TEST_FOR_EXCEPTION( d_problem->getA() == Teuchos::null &&
196 d_problem->getOperator() == Teuchos::null, std::invalid_argument,
"A operator not supplied on Eigenproblem." );
197 TEUCHOS_TEST_FOR_EXCEPTION( d_problem->getInitVec() == Teuchos::null, std::invalid_argument,
"No vector to clone from on Eigenproblem." );
198 TEUCHOS_TEST_FOR_EXCEPTION( d_problem->getNEV() <= 0, std::invalid_argument,
"Number of requested eigenvalues must be positive.");
200 if( !pl.isType<
int>(
"Block Size") )
202 pl.set<
int>(
"Block Size",1);
205 if( !pl.isType<
int>(
"Maximum Subspace Dimension") )
207 pl.set<
int>(
"Maximum Subspace Dimension",3*problem->getNEV()*pl.get<
int>(
"Block Size"));
210 if( !pl.isType<
int>(
"Print Number of Ritz Values") )
212 int numToPrint = std::max( pl.get<
int>(
"Block Size"), d_problem->getNEV() );
213 pl.set<
int>(
"Print Number of Ritz Values",numToPrint);
217 MagnitudeType tol = pl.get<MagnitudeType>(
"Convergence Tolerance", MT::eps() );
218 TEUCHOS_TEST_FOR_EXCEPTION( pl.get<MagnitudeType>(
"Convergence Tolerance") <= MT::zero(),
219 std::invalid_argument,
"Convergence Tolerance must be greater than zero." );
222 if( pl.isType<
int>(
"Maximum Restarts") )
224 d_maxRestarts = pl.get<
int>(
"Maximum Restarts");
225 TEUCHOS_TEST_FOR_EXCEPTION( d_maxRestarts < 0, std::invalid_argument,
"Maximum Restarts must be non-negative" );
233 d_restartDim = pl.get<
int>(
"Restart Dimension",d_problem->getNEV());
234 TEUCHOS_TEST_FOR_EXCEPTION( d_restartDim < d_problem->getNEV(),
235 std::invalid_argument,
"Restart Dimension must be at least NEV" );
238 std::string initType;
239 if( pl.isType<std::string>(
"Initial Guess") )
241 initType = pl.get<std::string>(
"Initial Guess");
242 TEUCHOS_TEST_FOR_EXCEPTION( initType!=
"User" && initType!=
"Random", std::invalid_argument,
243 "Initial Guess type must be 'User' or 'Random'." );
252 if( pl.isType<std::string>(
"Which") )
254 which = pl.get<std::string>(
"Which");
255 TEUCHOS_TEST_FOR_EXCEPTION( which!=
"LM" && which!=
"SM" && which!=
"LR" && which!=
"SR" && which!=
"LI" && which!=
"SI",
256 std::invalid_argument,
257 "Which must be one of LM,SM,LR,SR,LI,SI." );
268 std::string ortho = pl.get<std::string>(
"Orthogonalization",
"SVQB");
269 TEUCHOS_TEST_FOR_EXCEPTION( ortho!=
"DGKS" && ortho!=
"SVQB" && ortho!=
"ICGS", std::invalid_argument,
270 "Anasazi::GeneralizedDavidsonSolMgr::constructor: Invalid orthogonalization type" );
276 else if( ortho==
"SVQB" )
280 else if( ortho==
"ICGS" )
286 bool scaleRes =
false;
287 bool failOnNaN =
false;
288 RCP<StatusTest<ScalarType,MV,OP> > resNormTest = Teuchos::rcp(
290 RES_2NORM,scaleRes,failOnNaN) );
294 int verbosity = pl.get<
int>(
"Verbosity",
Errors);
296 d_outputMan->setVerbosity( verbosity );
299 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidsonSolMgr: Building solver" << std::endl;
302 TEUCHOS_TEST_FOR_EXCEPTION(d_solver->getMaxSubspaceDim() < d_restartDim, std::invalid_argument,
303 "The maximum size of the subspace dimension (" << d_solver->getMaxSubspaceDim() <<
") must " 304 "not be smaller than the size of the restart space (" << d_restartDim <<
"). " 305 "Please adjust \"Restart Dimension\" and/or \"Maximum Subspace Dimension\" parameters.");
312 template <
class ScalarType,
class MV,
class OP>
317 d_problem->setSolution(sol);
319 d_solver->initialize();
327 if( d_tester->getStatus() ==
Passed )
331 if( restarts == d_maxRestarts )
335 d_solver->sortProblem( d_restartDim );
337 getRestartState( state );
338 d_solver->initialize( state );
344 d_solver->currentStatus(d_outputMan->stream(
FinalSummary));
347 sol.
numVecs = d_tester->howMany();
350 std::vector<int> whichVecs = d_tester->whichVecs();
351 std::vector<int> origIndex = d_solver->getRitzIndex();
355 for(
int i=0; i<sol.
numVecs; ++i )
357 if( origIndex[ whichVecs[i] ] == 1 )
359 if( std::find( whichVecs.begin(), whichVecs.end(), whichVecs[i]+1 ) == whichVecs.end() )
361 whichVecs.push_back( whichVecs[i]+1 );
365 else if( origIndex[ whichVecs[i] ] == -1 )
367 if( std::find( whichVecs.begin(), whichVecs.end(), whichVecs[i]-1 ) == whichVecs.end() )
369 whichVecs.push_back( whichVecs[i]-1 );
375 if( d_outputMan->isVerbosity(
Debug) )
377 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidsonSolMgr: " 378 << sol.
numVecs <<
" eigenpairs converged" << std::endl;
382 std::vector< Value<ScalarType> > origVals = d_solver->getRitzValues();
383 std::vector<MagnitudeType> realParts;
384 std::vector<MagnitudeType> imagParts;
385 for(
int i=0; i<sol.
numVecs; ++i )
387 realParts.push_back( origVals[whichVecs[i]].realpart );
388 imagParts.push_back( origVals[whichVecs[i]].imagpart );
391 std::vector<int> permVec(sol.
numVecs);
392 d_sortMan->sort( realParts, imagParts, Teuchos::rcpFromRef(permVec), sol.
numVecs );
395 std::vector<int> newWhich;
396 for(
int i=0; i<sol.
numVecs; ++i )
397 newWhich.push_back( whichVecs[permVec[i]] );
401 for(
int i=0; i<sol.
numVecs; ++i )
413 sol.
index = origIndex;
415 sol.
Evals = d_solver->getRitzValues();
425 for(
int i=0; i<sol.
numVecs; ++i )
427 sol.
index[i] = origIndex[ newWhich[i] ];
428 sol.
Evals[i] = origVals[ newWhich[i] ];
433 d_problem->setSolution(sol);
436 if( sol.
numVecs < d_problem->getNEV() )
445 template <
class ScalarType,
class MV,
class OP>
449 TEUCHOS_TEST_FOR_EXCEPTION( state.
curDim <= d_restartDim, std::runtime_error,
450 "Anasazi::GeneralizedDavidsonSolMgr: State dimension at restart is smaller than Restart Dimension" );
452 std::vector<int> ritzIndex = d_solver->getRitzIndex();
455 int restartDim = d_restartDim;
456 if( ritzIndex[d_restartDim-1]==1 )
459 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidsonSolMgr: Restarting with " 460 << restartDim <<
" vectors" << std::endl;
469 const Teuchos::SerialDenseMatrix<int,ScalarType> Z_wanted =
470 Teuchos::SerialDenseMatrix<int,ScalarType>(Teuchos::View,*state.
Z,state.
curDim,restartDim);
473 std::vector<int> allIndices(state.
curDim);
474 for(
int i=0; i<state.
curDim; ++i )
480 std::vector<int> restartIndices(restartDim);
481 for(
int i=0; i<restartDim; ++i )
482 restartIndices[i] = i;
488 RCP<MV> restartVecs =
MVT::Clone(*state.
V,restartDim);
495 if( d_outputMan->isVerbosity(
Debug) )
497 MagnitudeType orthErr = d_orthoMan->orthonormError(*V_restart);
498 std::stringstream os;
499 os <<
" >> Anasazi::GeneralizedDavidsonSolMgr: Error in V^T V == I after restart : " << orthErr << std::endl;
500 d_outputMan->print(
Debug,os.str());
513 const Teuchos::SerialDenseMatrix<int,ScalarType> VAV_orig( Teuchos::View, *state.
VAV, state.
curDim, state.
curDim );
514 Teuchos::SerialDenseMatrix<int,ScalarType> tmpMat(state.
curDim, restartDim);
515 err = tmpMat.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS, ST::one(), VAV_orig, Z_wanted, ST::zero() );
516 TEUCHOS_TEST_FOR_EXCEPTION( err!=0, std::runtime_error,
"GeneralizedDavidsonSolMgr::getRestartState: multiply returned nonzero error code" );
518 Teuchos::SerialDenseMatrix<int,ScalarType> VAV_restart( Teuchos::View, *state.
VAV, restartDim, restartDim );
519 err = VAV_restart.multiply( Teuchos::TRANS, Teuchos::NO_TRANS, ST::one(), Z_wanted, tmpMat, ST::zero() );
520 TEUCHOS_TEST_FOR_EXCEPTION( err!=0, std::runtime_error,
"GeneralizedDavidsonSolMgr::getRestartState: multiply returned nonzero error code" );
522 if( d_problem->getM() != Teuchos::null )
533 const Teuchos::SerialDenseMatrix<int,ScalarType> VBV_orig( Teuchos::View, *state.
VBV, state.
curDim, state.
curDim );
534 err = tmpMat.multiply( Teuchos::NO_TRANS, Teuchos::NO_TRANS, ST::one(), VBV_orig, Z_wanted, ST::zero() );
535 TEUCHOS_TEST_FOR_EXCEPTION( err!=0, std::runtime_error,
"GeneralizedDavidsonSolMgr::getRestartState: multiply returned nonzero error code" );
537 Teuchos::SerialDenseMatrix<int,ScalarType> VBV_restart( Teuchos::View, *state.
VBV, restartDim, restartDim );
538 VBV_restart.multiply( Teuchos::TRANS, Teuchos::NO_TRANS, ST::one(), Z_wanted, tmpMat, ST::zero() );
539 TEUCHOS_TEST_FOR_EXCEPTION( err!=0, std::runtime_error,
"GeneralizedDavidsonSolMgr::getRestartState: multiply returned nonzero error code" );
543 state.
Q->putScalar( ST::zero() );
544 state.
Z->putScalar( ST::zero() );
545 for(
int ii=0; ii<restartDim; ii++ )
547 (*state.
Q)(ii,ii)= ST::one();
548 (*state.
Z)(ii,ii)= ST::one();
552 state.
curDim = restartDim;
557 #endif // ANASAZI_GENERALIZED_DAVIDSON_SOLMGR_HPP ReturnType solve()
This method performs possibly repeated calls to the underlying eigensolver's iterate() routine until ...
Pure virtual base class which describes the basic interface for a solver manager. ...
RCP< MV > V
Orthonormal basis for search subspace.
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
std::vector< Value< ScalarType > > Evals
The computed eigenvalues.
RCP< MV > AV
Image of V under A.
This class defines the interface required by an eigensolver and status test class to compute solution...
An implementation of the Anasazi::SortManager that performs a collection of common sorting techniques...
Solves eigenvalue problem using generalized Davidson method.
Teuchos::RCP< MV > Evecs
The computed eigenvectors.
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > VAV
Projection of A onto V.
An implementation of the Anasazi::GenOrthoManager that performs orthogonalization using iterated clas...
The Anasazi::SolverManager is a templated virtual base class that defines the basic interface that an...
int curDim
The current subspace dimension.
Basic implementation of the Anasazi::SortManager class.
const Eigenproblem< ScalarType, MV, OP > & getProblem() const
Return the eigenvalue problem.
An implementation of the Anasazi::MatOrthoManager that performs orthogonalization using the SVQB iter...
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
RCP< MV > BV
Image of V under B.
Structure to contain pointers to GeneralizedDavidson state variables.
int numVecs
The number of computed eigenpairs.
Basic output manager for sending information of select verbosity levels to the appropriate output str...
Anasazi's basic output manager for sending information of select verbosity levels to the appropriate ...
Abstract base class which defines the interface required by an eigensolver and status test class to c...
ReturnType
Enumerated type used to pass back information from a solver manager.
A status test for testing the norm of the eigenvectors residuals.
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Q
Left generalized Schur vectors from QZ decomposition of (VAV,VBV)
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
std::vector< int > index
An index into Evecs to allow compressed storage of eigenvectors for real, non-Hermitian problems...
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
Orthogonalization manager based on the SVQB technique described in "A Block Orthogonalization Procedu...
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
Struct for storing an eigenproblem solution.
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
static void SetBlock(const MV &A, const std::vector< int > &index, MV &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index...
GeneralizedDavidsonSolMgr(const RCP< Eigenproblem< ScalarType, MV, OP > > &problem, Teuchos::ParameterList &pl)
Basic constructor for GeneralizedDavidsonSolMgr.
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > VBV
Projection of B onto V.
RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Z
Right generalized Schur vectors from QZ decomposition of (VAV,VBV)
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
An implementation of the Anasazi::MatOrthoManager that performs orthogonalization using (potentially)...
Types and exceptions used within Anasazi solvers and interfaces.
Solver Manager for GeneralizedDavidson.
A status test for testing the norm of the eigenvectors residuals.
Basic implementation of the Anasazi::OrthoManager class.
Basic implementation of the Anasazi::OrthoManager class.
static Teuchos::RCP< MV > Clone(const MV &mv, const int numvecs)
Creates a new empty MV containing numvecs columns.
Implementation of a block Generalized Davidson eigensolver.
int getNumIters() const
Get the iteration count for the most recent call to solve()