10#ifndef ANASAZI_GENERALIZED_DAVIDSON_SOLMGR_HPP
11#define ANASAZI_GENERALIZED_DAVIDSON_SOLMGR_HPP
17#include "Teuchos_ParameterList.hpp"
18#include "Teuchos_RCPDecl.hpp"
59template <
class ScalarType,
class MV,
class OP>
96 Teuchos::ParameterList &
pl );
119 typedef Teuchos::ScalarTraits<ScalarType> ST;
120 typedef typename ST::magnitudeType MagnitudeType;
121 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
137template <
class MagnitudeType,
class MV,
class OP>
138class GeneralizedDavidsonSolMgr<std::complex<MagnitudeType>,MV,OP>
142 typedef std::complex<MagnitudeType> ScalarType;
143 GeneralizedDavidsonSolMgr(
144 const RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
145 Teuchos::ParameterList &pl )
148 MagnitudeType::this_class_is_missing_a_specialization();
159template <
class ScalarType,
class MV,
class OP>
162 Teuchos::ParameterList &
pl )
168 d_problem->getOperator() == Teuchos::null, std::invalid_argument,
"A operator not supplied on Eigenproblem." );
169 TEUCHOS_TEST_FOR_EXCEPTION( d_problem->getInitVec() == Teuchos::null, std::invalid_argument,
"No vector to clone from on Eigenproblem." );
170 TEUCHOS_TEST_FOR_EXCEPTION( d_problem->getNEV() <= 0, std::invalid_argument,
"Number of requested eigenvalues must be positive.");
172 if( !
pl.isType<
int>(
"Block Size") )
174 pl.set<
int>(
"Block Size",1);
177 if( !
pl.isType<
int>(
"Maximum Subspace Dimension") )
179 pl.set<
int>(
"Maximum Subspace Dimension",3*
problem->getNEV()*
pl.get<
int>(
"Block Size"));
182 if( !
pl.isType<
int>(
"Print Number of Ritz Values") )
184 int numToPrint = std::max(
pl.get<
int>(
"Block Size"), d_problem->getNEV() );
189 MagnitudeType
tol =
pl.get<MagnitudeType>(
"Convergence Tolerance", MT::eps() );
191 std::invalid_argument,
"Convergence Tolerance must be greater than zero." );
194 if(
pl.isType<
int>(
"Maximum Restarts") )
196 d_maxRestarts =
pl.get<
int>(
"Maximum Restarts");
205 d_restartDim =
pl.get<
int>(
"Restart Dimension",d_problem->getNEV());
207 std::invalid_argument,
"Restart Dimension must be at least NEV" );
211 if(
pl.isType<std::string>(
"Initial Guess") )
213 initType =
pl.get<std::string>(
"Initial Guess");
215 "Initial Guess type must be 'User' or 'Random'." );
224 if(
pl.isType<std::string>(
"Which") )
226 which =
pl.get<std::string>(
"Which");
228 std::invalid_argument,
229 "Which must be one of LM,SM,LR,SR,LI,SI." );
240 std::string
ortho =
pl.get<std::string>(
"Orthogonalization",
"SVQB");
242 "Anasazi::GeneralizedDavidsonSolMgr::constructor: Invalid orthogonalization type" );
248 else if(
ortho==
"SVQB" )
252 else if(
ortho==
"ICGS" )
269 int osProc =
pl.get(
"Output Processor", 0);
272 Teuchos::RCP<Teuchos::FancyOStream>
osp;
274 if (
pl.isParameter(
"Output Stream")) {
275 osp = Teuchos::getParameter<Teuchos::RCP<Teuchos::FancyOStream> >(
pl,
"Output Stream");
283 if (
pl.isParameter(
"Verbosity")) {
284 if (Teuchos::isParameterType<int>(
pl,
"Verbosity")) {
287 verbosity = (
int)Teuchos::getParameter<Anasazi::MsgType>(
pl,
"Verbosity");
294 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidsonSolMgr: Building solver" << std::endl;
298 "The maximum size of the subspace dimension (" << d_solver->getMaxSubspaceDim() <<
") must "
299 "not be smaller than the size of the restart space (" << d_restartDim <<
"). "
300 "Please adjust \"Restart Dimension\" and/or \"Maximum Subspace Dimension\" parameters.");
307template <
class ScalarType,
class MV,
class OP>
312 d_problem->setSolution(
sol);
314 d_solver->initialize();
322 if( d_tester->getStatus() ==
Passed )
330 d_solver->sortProblem( d_restartDim );
332 getRestartState(
state );
333 d_solver->initialize(
state );
339 d_solver->currentStatus(d_outputMan->stream(
FinalSummary));
342 sol.numVecs = d_tester->howMany();
343 if(
sol.numVecs > 0 )
345 std::vector<int> whichVecs = d_tester->whichVecs();
346 std::vector<int>
origIndex = d_solver->getRitzIndex();
350 for(
int i=0;
i<
sol.numVecs; ++
i )
354 if( std::find( whichVecs.begin(), whichVecs.end(), whichVecs[
i]+1 ) == whichVecs.end() )
356 whichVecs.push_back( whichVecs[
i]+1 );
362 if( std::find( whichVecs.begin(), whichVecs.end(), whichVecs[
i]-1 ) == whichVecs.end() )
364 whichVecs.push_back( whichVecs[
i]-1 );
370 if( d_outputMan->isVerbosity(
Debug) )
372 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidsonSolMgr: "
373 <<
sol.numVecs <<
" eigenpairs converged" << std::endl;
377 std::vector< Value<ScalarType> >
origVals = d_solver->getRitzValues();
380 for(
int i=0;
i<
sol.numVecs; ++
i )
391 for(
int i=0;
i<
sol.numVecs; ++
i )
396 for(
int i=0;
i<
sol.numVecs; ++
i )
409 sol.index.resize(
sol.numVecs);
410 sol.Evals = d_solver->getRitzValues();
411 sol.Evals.resize(
sol.numVecs);
417 sol.index.resize(
sol.numVecs);
418 sol.Evals.resize(
sol.numVecs);
420 for(
int i=0;
i<
sol.numVecs; ++
i )
426 sol.Evecs = MVT::CloneCopy( *(d_solver->getRitzVectors()),
newWhich );
428 d_problem->setSolution(
sol);
431 if(
sol.numVecs < d_problem->getNEV() )
440template <
class ScalarType,
class MV,
class OP>
445 "Anasazi::GeneralizedDavidsonSolMgr: State dimension at restart is smaller than Restart Dimension" );
447 std::vector<int>
ritzIndex = d_solver->getRitzIndex();
454 d_outputMan->stream(
Debug) <<
" >> Anasazi::GeneralizedDavidsonSolMgr: Restarting with "
464 const Teuchos::SerialDenseMatrix<int,ScalarType>
Z_wanted =
490 if( d_outputMan->isVerbosity(
Debug) )
493 std::stringstream
os;
494 os <<
" >> Anasazi::GeneralizedDavidsonSolMgr: Error in V^T V == I after restart : " <<
orthErr << std::endl;
495 d_outputMan->print(
Debug,
os.str());
508 const Teuchos::SerialDenseMatrix<int,ScalarType>
VAV_orig( Teuchos::View, *
state.VAV,
state.curDim,
state.curDim );
511 TEUCHOS_TEST_FOR_EXCEPTION(
err!=0, std::runtime_error,
"GeneralizedDavidsonSolMgr::getRestartState: multiply returned nonzero error code" );
515 TEUCHOS_TEST_FOR_EXCEPTION(
err!=0, std::runtime_error,
"GeneralizedDavidsonSolMgr::getRestartState: multiply returned nonzero error code" );
517 if( d_problem->getM() != Teuchos::null )
528 const Teuchos::SerialDenseMatrix<int,ScalarType>
VBV_orig( Teuchos::View, *
state.VBV,
state.curDim,
state.curDim );
530 TEUCHOS_TEST_FOR_EXCEPTION(
err!=0, std::runtime_error,
"GeneralizedDavidsonSolMgr::getRestartState: multiply returned nonzero error code" );
534 TEUCHOS_TEST_FOR_EXCEPTION(
err!=0, std::runtime_error,
"GeneralizedDavidsonSolMgr::getRestartState: multiply returned nonzero error code" );
538 state.Q->putScalar( ST::zero() );
539 state.Z->putScalar( ST::zero() );
Basic implementation of the Anasazi::OrthoManager class.
Basic implementation of the Anasazi::SortManager class.
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
Abstract base class which defines the interface required by an eigensolver and status test class to c...
Implementation of a block Generalized Davidson eigensolver.
Basic implementation of the Anasazi::OrthoManager class.
Abstract class definition for Anasazi Output Managers.
Abstract class definition for Anasazi output stream.
Orthogonalization manager based on the SVQB technique described in "A Block Orthogonalization Procedu...
Pure virtual base class which describes the basic interface for a solver manager.
A status test for testing the norm of the eigenvectors residuals.
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
Types and exceptions used within Anasazi solvers and interfaces.
Solver Manager for GeneralizedDavidson.
GeneralizedDavidsonSolMgr(const RCP< Eigenproblem< ScalarType, MV, OP > > &problem, Teuchos::ParameterList &pl)
Basic constructor for GeneralizedDavidsonSolMgr.
int getNumIters() const
Get the iteration count for the most recent call to solve()
ReturnType solve()
This method performs possibly repeated calls to the underlying eigensolver's iterate() routine until ...
const Eigenproblem< ScalarType, MV, OP > & getProblem() const
Return the eigenvalue problem.
Anasazi's templated virtual class for constructing an operator that can interface with the OperatorTr...
Operator()
Default constructor.
The Anasazi::SolverManager is a templated virtual base class that defines the basic interface that an...
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
ReturnType
Enumerated type used to pass back information from a solver manager.
Output managers remove the need for the eigensolver to know any information about the required output...