29 #ifndef ANASAZI_RTR_SOLMGR_HPP 30 #define ANASAZI_RTR_SOLMGR_HPP 55 #include <Teuchos_TimeMonitor.hpp> 56 #include <Teuchos_FancyOStream.hpp> 69 template<
class ScalarType,
class MV,
class OP>
75 typedef Teuchos::ScalarTraits<ScalarType> SCT;
76 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
77 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
100 Teuchos::ParameterList &pl );
119 Teuchos::Array<Teuchos::RCP<Teuchos::Time> >
getTimers()
const {
120 return Teuchos::tuple(_timerSolve);
146 Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > problem_;
151 MagnitudeType convtol_;
158 Teuchos::RCP<Teuchos::Time> _timerSolve;
159 Teuchos::RCP<BasicOutputManager<ScalarType> > printer_;
160 Teuchos::ParameterList pl_;
165 template<
class ScalarType,
class MV,
class OP>
168 Teuchos::ParameterList &pl ) :
172 convtol_(MT::prec()),
176 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
177 _timerSolve(Teuchos::TimeMonitor::getNewTimer(
"Anasazi: RTRSolMgr::solve()")),
181 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument,
"Problem not given to solver manager.");
182 TEUCHOS_TEST_FOR_EXCEPTION(!problem_->isProblemSet(), std::invalid_argument,
"Problem not set.");
183 TEUCHOS_TEST_FOR_EXCEPTION(!problem_->isHermitian(), std::invalid_argument,
"Problem not symmetric.");
184 TEUCHOS_TEST_FOR_EXCEPTION(problem_->getInitVec() == Teuchos::null,std::invalid_argument,
"Problem does not contain initial vectors to clone from.");
188 whch_ = pl_.get(
"Which",
"SR");
189 TEUCHOS_TEST_FOR_EXCEPTION(whch_ !=
"SR" && whch_ !=
"LR",
190 std::invalid_argument,
"Anasazi::RTRSolMgr: Invalid sorting string. RTR solvers compute only LR or SR.");
193 convtol_ = pl_.get(
"Convergence Tolerance",convtol_);
194 relconvtol_ = pl_.get(
"Relative Convergence Tolerance",relconvtol_);
195 strtmp = pl_.get(
"Convergence Norm",std::string(
"2"));
197 convNorm_ = RES_2NORM;
199 else if (strtmp ==
"M") {
200 convNorm_ = RES_ORTH;
203 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
204 "Anasazi::RTRSolMgr: Invalid Convergence Norm.");
209 maxIters_ = pl_.get(
"Maximum Iterations",maxIters_);
212 skinny_ = pl_.get(
"Skinny Solver",skinny_);
215 numICGS_ = pl_.get(
"Num ICGS",2);
218 std::string fntemplate =
"";
219 bool allProcs =
false;
220 if (pl_.isParameter(
"Output on all processors")) {
221 if (Teuchos::isParameterType<bool>(pl_,
"Output on all processors")) {
222 allProcs = pl_.get(
"Output on all processors",allProcs);
224 allProcs = ( Teuchos::getParameter<int>(pl_,
"Output on all processors") != 0 );
227 fntemplate = pl_.get(
"Output filename template",fntemplate);
232 MPI_Initialized(&mpiStarted);
233 if (mpiStarted) MPI_Comm_rank(MPI_COMM_WORLD, &MyPID);
238 if (fntemplate !=
"") {
239 std::ostringstream MyPIDstr;
243 while ( (pos = fntemplate.find(
"%d",start)) != -1 ) {
244 fntemplate.replace(pos,2,MyPIDstr.str());
248 Teuchos::RCP<ostream> osp;
249 if (fntemplate !=
"") {
250 osp = Teuchos::rcp(
new std::ofstream(fntemplate.c_str(),std::ios::out | std::ios::app) );
252 osp = Teuchos::rcpFromRef(std::cout);
253 std::cout <<
"Anasazi::RTRSolMgr::constructor(): Could not open file for write: " << fntemplate << std::endl;
257 osp = Teuchos::rcpFromRef(std::cout);
261 if (pl_.isParameter(
"Verbosity")) {
262 if (Teuchos::isParameterType<int>(pl_,
"Verbosity")) {
263 verbosity = pl_.get(
"Verbosity", verbosity);
265 verbosity = (int)Teuchos::getParameter<Anasazi::MsgType>(pl_,
"Verbosity");
280 template<
class ScalarType,
class MV,
class OP>
288 const int nev = problem_->getNEV();
294 Teuchos::RCP<Teuchos::FancyOStream>
295 out = Teuchos::getFancyOStream(Teuchos::rcpFromRef(printer_->stream(
Debug)));
296 out->setShowAllFrontMatter(
false).setShowProcRank(
true);
297 *out <<
"Entering Anasazi::RTRSolMgr::solve()\n";
307 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > maxtest;
308 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > ordertest;
309 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > combotest;
310 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convtest;
316 maxtest = Teuchos::null;
324 Teuchos::Array<Teuchos::RCP<StatusTest<ScalarType,MV,OP> > > alltests;
325 alltests.push_back(ordertest);
326 if (maxtest != Teuchos::null) alltests.push_back(maxtest);
330 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputtest;
331 if ( printer_->isVerbosity(
Debug) ) {
340 Teuchos::RCP<ICGSOrthoManager<ScalarType,MV,OP> > ortho
346 bool leftMost =
true;
347 if (whch_ ==
"LR" || whch_ ==
"LM") {
350 pl_.set<
bool>(
"Leftmost",leftMost);
351 Teuchos::RCP<RTRBase<ScalarType,MV,OP> > rtr_solver;
352 if (skinny_ ==
false) {
361 Teuchos::RCP< const MV > probauxvecs = problem_->getAuxVecs();
362 if (probauxvecs != Teuchos::null) {
363 rtr_solver->setAuxVecs( Teuchos::tuple< Teuchos::RCP<const MV> >(probauxvecs) );
366 TEUCHOS_TEST_FOR_EXCEPTION(rtr_solver->getBlockSize() < problem_->getNEV(),std::logic_error,
367 "Anasazi::RTRSolMgr requires block size >= requested number of eigenvalues.");
370 Teuchos::RCP<MV> foundvecs;
371 std::vector<MagnitudeType> foundvals;
375 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 376 Teuchos::TimeMonitor slvtimer(*_timerSolve);
378 rtr_solver->iterate();
379 numIters_ = rtr_solver->getNumIters();
381 catch (
const std::exception &e) {
383 printer_->stream(
Anasazi::Errors) <<
"Exception: " << e.what() << endl;
386 problem_->setSolution(sol);
391 if (convtest->getStatus() ==
Passed || (maxtest != Teuchos::null && maxtest->getStatus() ==
Passed))
393 int num = convtest->howMany();
395 std::vector<int> ind = convtest->whichVecs();
399 foundvals.resize(num);
400 std::vector<Value<ScalarType> > all = rtr_solver->getRitzValues();
401 for (
int i=0; i<num; i++) {
402 foundvals[i] = all[ind[i]].realpart;
408 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Anasazi::RTRSolMgr::solve(): solver returned without satisfy status test.");
414 sol.
Evecs = foundvecs;
417 for (
int i=0; i<sol.
numVecs; i++) {
418 sol.
Evals[i].realpart = foundvals[i];
421 sol.
index.resize(numfound,0);
424 rtr_solver->currentStatus(printer_->stream(
FinalSummary));
427 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 429 Teuchos::TimeMonitor::summarize( printer_->stream(
TimingDetails ) );
434 problem_->setSolution(sol);
435 printer_->stream(
Debug) <<
"Returning " << sol.
numVecs <<
" eigenpairs to eigenproblem." << endl;
Pure virtual base class which describes the basic interface for a solver manager. ...
std::vector< Value< ScalarType > > Evals
The computed eigenvalues.
ResType
Enumerated type used to specify which residual norm used by residual norm status tests.
A special StatusTest for printing other status tests.
This class defines the interface required by an eigensolver and status test class to compute solution...
RTRSolMgr(const Teuchos::RCP< Eigenproblem< ScalarType, MV, OP > > &problem, Teuchos::ParameterList &pl)
Basic constructor for RTRSolMgr.
An implementation of the Anasazi::SortManager that performs a collection of common sorting techniques...
Virtual base class which defines basic traits for the operator type.
Teuchos::RCP< MV > Evecs
The computed eigenvectors.
An implementation of the Anasazi::GenOrthoManager that performs orthogonalization using iterated clas...
Status test for forming logical combinations of other status tests.
The Anasazi::SolverManager is a templated virtual base class that defines the basic interface that an...
The Anasazi::RTRSolMgr provides a simple solver manager over the RTR eigensolver. For more informatio...
virtual ~RTRSolMgr()
Destructor.
Basic implementation of the Anasazi::SortManager class.
int getNumIters() const
Get the iteration count for the most recent call to solve.
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...
int numVecs
The number of computed eigenpairs.
Basic output manager for sending information of select verbosity levels to the appropriate output str...
ReturnType solve()
This method performs possibly repeated calls to the underlying eigensolver's iterate() routine until ...
Teuchos::RCP< MV > Espace
An orthonormal basis for the computed eigenspace.
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.
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...
Struct for storing an eigenproblem solution.
const Eigenproblem< ScalarType, MV, OP > & getProblem() const
Return the eigenvalue problem.
A status test for testing the number of iterations.
Status test for testing the number of iterations.
Special StatusTest for printing status tests.
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
Status test for forming logical combinations of other status tests.
Types and exceptions used within Anasazi solvers and interfaces.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
A status test for testing the norm of the eigenvectors residuals.
Basic implementation of the Anasazi::OrthoManager class.
Class which provides internal utilities for the Anasazi solvers.