Belos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosTFQMRSolMgr.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Belos: Block Linear Solvers Package
4 //
5 // Copyright 2004-2016 NTESS and the Belos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef BELOS_TFQMR_SOLMGR_HPP
11 #define BELOS_TFQMR_SOLMGR_HPP
12 
17 #include "BelosConfigDefs.hpp"
18 #include "BelosTypes.hpp"
19 
20 #include "BelosLinearProblem.hpp"
21 #include "BelosSolverManager.hpp"
22 
23 #include "BelosTFQMRIter.hpp"
26 #include "BelosStatusTestCombo.hpp"
28 #include "BelosOutputManager.hpp"
29 #ifdef BELOS_TEUCHOS_TIME_MONITOR
30 #include "Teuchos_TimeMonitor.hpp"
31 #endif
32 
49 namespace Belos {
50 
52 
53 
61  TFQMRSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
62  {}};
63 
64  template<class ScalarType, class MV, class OP>
65  class TFQMRSolMgr : public SolverManager<ScalarType,MV,OP> {
66 
67  private:
73 
74  public:
75 
77 
78 
84  TFQMRSolMgr();
85 
104 
106  virtual ~TFQMRSolMgr() {};
107 
111  }
113 
115 
116 
117  const LinearProblem<ScalarType,MV,OP>& getProblem() const override {
118  return *problem_;
119  }
120 
124 
128 
135  return Teuchos::tuple(timerSolve_);
136  }
137 
143  MagnitudeType achievedTol() const override {
144  return achievedTol_;
145  }
146 
148  int getNumIters() const override {
149  return numIters_;
150  }
151 
159  bool isLOADetected() const override { return false; }
161 
163 
164 
166  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) override { problem_ = problem; }
167 
169  void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
170 
172 
174 
179  void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
181 
183 
184 
202  ReturnType solve() override;
203 
205 
207 
209  std::string description() const override;
211 
212  private:
213 
214  // Method for checking current status test against defined linear problem.
215  bool checkStatusTest();
216 
217  // Linear problem.
219 
220  // Output manager.
223 
224  // Status test.
230 
231  // Current parameter list.
233 
234  // Default solver values.
235  static constexpr int maxIters_default_ = 1000;
236  static constexpr bool expResTest_default_ = false;
237  static constexpr int verbosity_default_ = Belos::Errors;
238  static constexpr int outputStyle_default_ = Belos::General;
239  static constexpr int outputFreq_default_ = -1;
240  static constexpr const char * impResScale_default_ = "Norm of Preconditioned Initial Residual";
241  static constexpr const char * expResScale_default_ = "Norm of Initial Residual";
242  static constexpr const char * label_default_ = "Belos";
243 
244  // Current solver values.
251 
252  // Timers.
253  std::string label_;
255 
256  // Internal state variables.
258  };
259 
260 
261 // Empty Constructor
262 template<class ScalarType, class MV, class OP>
264  outputStream_(Teuchos::rcpFromRef(std::cout)),
265  convtol_(DefaultSolverParameters::convTol),
266  impTolScale_(DefaultSolverParameters::impTolScale),
267  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
268  maxIters_(maxIters_default_),
269  numIters_(0),
270  verbosity_(verbosity_default_),
271  outputStyle_(outputStyle_default_),
272  outputFreq_(outputFreq_default_),
273  blockSize_(1),
274  expResTest_(expResTest_default_),
275  impResScale_(impResScale_default_),
276  expResScale_(expResScale_default_),
277  label_(label_default_),
278  isSet_(false),
279  isSTSet_(false)
280 {}
281 
282 
283 // Basic Constructor
284 template<class ScalarType, class MV, class OP>
288  problem_(problem),
289  outputStream_(Teuchos::rcpFromRef(std::cout)),
290  convtol_(DefaultSolverParameters::convTol),
291  impTolScale_(DefaultSolverParameters::impTolScale),
292  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
293  maxIters_(maxIters_default_),
294  numIters_(0),
295  verbosity_(verbosity_default_),
296  outputStyle_(outputStyle_default_),
297  outputFreq_(outputFreq_default_),
298  blockSize_(1),
299  expResTest_(expResTest_default_),
300  impResScale_(impResScale_default_),
301  expResScale_(expResScale_default_),
302  label_(label_default_),
303  isSet_(false),
304  isSTSet_(false)
305 {
306  TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument, "Problem not given to solver manager.");
307 
308  // If the parameter list pointer is null, then set the current parameters to the default parameter list.
309  if ( !is_null(pl) ) {
310  setParameters( pl );
311  }
312 }
313 
314 template<class ScalarType, class MV, class OP>
316 {
317  // Create the internal parameter list if ones doesn't already exist.
318  if (params_ == Teuchos::null) {
319  params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
320  }
321  else {
322  params->validateParameters(*getValidParameters());
323  }
324 
325  // Check for maximum number of iterations
326  if (params->isParameter("Maximum Iterations")) {
327  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
328 
329  // Update parameter in our list and in status test.
330  params_->set("Maximum Iterations", maxIters_);
331  if (maxIterTest_!=Teuchos::null)
332  maxIterTest_->setMaxIters( maxIters_ );
333  }
334 
335  // Check for blocksize
336  if (params->isParameter("Block Size")) {
337  blockSize_ = params->get("Block Size",1);
338  TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ != 1, std::invalid_argument,
339  "Belos::TFQMRSolMgr: \"Block Size\" must be 1.");
340 
341  // Update parameter in our list.
342  params_->set("Block Size", blockSize_);
343  }
344 
345  // Check to see if the timer label changed.
346  if (params->isParameter("Timer Label")) {
347  std::string tempLabel = params->get("Timer Label", label_default_);
348 
349  // Update parameter in our list and solver timer
350  if (tempLabel != label_) {
351  label_ = tempLabel;
352  params_->set("Timer Label", label_);
353  std::string solveLabel = label_ + ": TFQMRSolMgr total solve time";
354 #ifdef BELOS_TEUCHOS_TIME_MONITOR
355  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
356 #endif
357  }
358  }
359 
360  // Check for a change in verbosity level
361  if (params->isParameter("Verbosity")) {
362  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
363  verbosity_ = params->get("Verbosity", verbosity_default_);
364  } else {
365  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
366  }
367 
368  // Update parameter in our list.
369  params_->set("Verbosity", verbosity_);
370  if (printer_ != Teuchos::null)
371  printer_->setVerbosity(verbosity_);
372  }
373 
374  // Check for a change in output style
375  if (params->isParameter("Output Style")) {
376  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
377  outputStyle_ = params->get("Output Style", outputStyle_default_);
378  } else {
379  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
380  }
381 
382  // Reconstruct the convergence test if the explicit residual test is not being used.
383  params_->set("Output Style", outputStyle_);
384  isSTSet_ = false;
385  }
386 
387  // output stream
388  if (params->isParameter("Output Stream")) {
389  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
390 
391  // Update parameter in our list.
392  params_->set("Output Stream", outputStream_);
393  if (printer_ != Teuchos::null)
394  printer_->setOStream( outputStream_ );
395  }
396 
397  // frequency level
398  if (verbosity_ & Belos::StatusTestDetails) {
399  if (params->isParameter("Output Frequency")) {
400  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
401  }
402 
403  // Update parameter in out list and output status test.
404  params_->set("Output Frequency", outputFreq_);
405  if (outputTest_ != Teuchos::null)
406  outputTest_->setOutputFrequency( outputFreq_ );
407  }
408 
409  // Create output manager if we need to.
410  if (printer_ == Teuchos::null) {
411  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
412  }
413 
414  // Check for convergence tolerance
415  if (params->isParameter("Convergence Tolerance")) {
416  if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
417  convtol_ = params->get ("Convergence Tolerance",
418  static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
419  }
420  else {
421  convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
422  }
423 
424  // Update parameter in our list.
425  params_->set("Convergence Tolerance", convtol_);
426  isSTSet_ = false;
427  }
428 
429  // Check for implicit residual scaling
430  if (params->isParameter("Implicit Tolerance Scale Factor")) {
431  if (params->isType<MagnitudeType> ("Implicit Tolerance Scale Factor")) {
432  impTolScale_ = params->get ("Implicit Tolerance Scale Factor",
433  static_cast<MagnitudeType> (DefaultSolverParameters::impTolScale));
434 
435  }
436  else {
437  impTolScale_ = params->get ("Implicit Tolerance Scale Factor",
439  }
440 
441  // Update parameter in our list.
442  params_->set("Implicit Tolerance Scale Factor", impTolScale_);
443  isSTSet_ = false;
444  }
445 
446  // Check for a change in scaling, if so we need to build new residual tests.
447  if (params->isParameter("Implicit Residual Scaling")) {
448  std::string tempImpResScale = Teuchos::getParameter<std::string>( *params, "Implicit Residual Scaling" );
449 
450  // Only update the scaling if it's different.
451  if (impResScale_ != tempImpResScale) {
452  impResScale_ = tempImpResScale;
453 
454  // Update parameter in our list and residual tests
455  params_->set("Implicit Residual Scaling", impResScale_);
456 
457  // Make sure the convergence test gets constructed again.
458  isSTSet_ = false;
459  }
460  }
461 
462  if (params->isParameter("Explicit Residual Scaling")) {
463  std::string tempExpResScale = Teuchos::getParameter<std::string>( *params, "Explicit Residual Scaling" );
464 
465  // Only update the scaling if it's different.
466  if (expResScale_ != tempExpResScale) {
467  expResScale_ = tempExpResScale;
468 
469  // Update parameter in our list and residual tests
470  params_->set("Explicit Residual Scaling", expResScale_);
471 
472  // Make sure the convergence test gets constructed again.
473  isSTSet_ = false;
474  }
475  }
476 
477  if (params->isParameter("Explicit Residual Test")) {
478  expResTest_ = Teuchos::getParameter<bool>( *params,"Explicit Residual Test" );
479 
480  // Reconstruct the convergence test if the explicit residual test is not being used.
481  params_->set("Explicit Residual Test", expResTest_);
482  if (expConvTest_ == Teuchos::null) {
483  isSTSet_ = false;
484  }
485  }
486 
487  // Create the timer if we need to.
488  if (timerSolve_ == Teuchos::null) {
489  std::string solveLabel = label_ + ": TFQMRSolMgr total solve time";
490 #ifdef BELOS_TEUCHOS_TIME_MONITOR
491  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
492 #endif
493  }
494 
495  // Inform the solver manager that the current parameters were set.
496  isSet_ = true;
497 }
498 
499 
500 // Check the status test versus the defined linear problem
501 template<class ScalarType, class MV, class OP>
503 
504  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
505  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestGenResNorm_t;
506 
507  // Basic test checks maximum iterations and native residual.
508  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
509 
510  if (expResTest_) {
511 
512  // Implicit residual test, using the native residual to determine if convergence was achieved.
513  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
514  Teuchos::rcp( new StatusTestGenResNorm_t( impTolScale_*convtol_ ) );
515  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
516  impConvTest_ = tmpImpConvTest;
517 
518  // Explicit residual test once the native residual is below the tolerance
519  Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
520  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
521  tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit, Belos::TwoNorm );
522  tmpExpConvTest->defineScaleForm( convertStringToScaleType(expResScale_), Belos::TwoNorm );
523  expConvTest_ = tmpExpConvTest;
524 
525  // The convergence test is a combination of the "cheap" implicit test and explicit test.
526  convTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
527  }
528  else {
529 
530  // Implicit residual test, using the native residual to determine if convergence was achieved.
531  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
532  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
533  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
534  impConvTest_ = tmpImpConvTest;
535 
536  // Set the explicit and total convergence test to this implicit test that checks for accuracy loss.
537  expConvTest_ = impConvTest_;
538  convTest_ = impConvTest_;
539  }
540  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
541 
542  // Create the status test output class.
543  // This class manages and formats the output from the status test.
544  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
545  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
546 
547  // Set the solver string for the output test
548  std::string solverDesc = " TFQMR ";
549  outputTest_->setSolverDesc( solverDesc );
550 
551 
552  // The status test is now set.
553  isSTSet_ = true;
554 
555  return false;
556 }
557 
558 
559 template<class ScalarType, class MV, class OP>
562 {
564 
565  // Set all the valid parameters and their default values.
566  if(is_null(validPL)) {
567  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
568 
569  // The static_cast is to resolve an issue with older clang versions which
570  // would cause the constexpr to link fail. With c++17 the problem is resolved.
571  pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
572  "The relative residual tolerance that needs to be achieved by the\n"
573  "iterative solver in order for the linear system to be declared converged.");
574  pl->set("Implicit Tolerance Scale Factor", static_cast<MagnitudeType>(DefaultSolverParameters::impTolScale),
575  "The scale factor used by the implicit residual test when explicit residual\n"
576  "testing is used. May enable faster convergence when TFQMR bound is too loose.");
577  pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
578  "The maximum number of block iterations allowed for each\n"
579  "set of RHS solved.");
580  pl->set("Verbosity", static_cast<int>(verbosity_default_),
581  "What type(s) of solver information should be outputted\n"
582  "to the output stream.");
583  pl->set("Output Style", static_cast<int>(outputStyle_default_),
584  "What style is used for the solver information outputted\n"
585  "to the output stream.");
586  pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
587  "How often convergence information should be outputted\n"
588  "to the output stream.");
589  pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
590  "A reference-counted pointer to the output stream where all\n"
591  "solver output is sent.");
592  pl->set("Explicit Residual Test", static_cast<bool>(expResTest_default_),
593  "Whether the explicitly computed residual should be used in the convergence test.");
594  pl->set("Implicit Residual Scaling", static_cast<const char *>(impResScale_default_),
595  "The type of scaling used in the implicit residual convergence test.");
596  pl->set("Explicit Residual Scaling", static_cast<const char *>(expResScale_default_),
597  "The type of scaling used in the explicit residual convergence test.");
598  pl->set("Timer Label", static_cast<const char *>(label_default_),
599  "The string to use as a prefix for the timer labels.");
600  validPL = pl;
601  }
602  return validPL;
603 }
604 
605 
606 // solve()
607 template<class ScalarType, class MV, class OP>
609 
610  // Set the current parameters if they were not set before.
611  // NOTE: This may occur if the user generated the solver manager with the default constructor and
612  // then didn't set any parameters using setParameters().
613  if (!isSet_) {
614  setParameters(Teuchos::parameterList(*getValidParameters()));
615  }
616 
618  "Belos::TFQMRSolMgr::solve(): Linear problem is not a valid object.");
619 
621  "Belos::TFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
622 
623  if (!isSTSet_) {
625  "Belos::TFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
626  }
627 
628  // Create indices for the linear systems to be solved.
629  int startPtr = 0;
630  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
631  int numCurrRHS = blockSize_;
632 
633  std::vector<int> currIdx, currIdx2;
634 
635  // The index set is generated that informs the linear problem that some linear systems are augmented.
636  currIdx.resize( blockSize_ );
637  currIdx2.resize( blockSize_ );
638  for (int i=0; i<numCurrRHS; ++i)
639  { currIdx[i] = startPtr+i; currIdx2[i]=i; }
640 
641  // Inform the linear problem of the current linear system to solve.
642  problem_->setLSIndex( currIdx );
643 
645  // Parameter list
647  plist.set("Block Size",blockSize_);
648 
649  // Reset the status test.
650  outputTest_->reset();
651 
652  // Assume convergence is achieved, then let any failed convergence set this to false.
653  bool isConverged = true;
654 
656  // TFQMR solver
657 
659  Teuchos::rcp( new TFQMRIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,plist) );
660 
661  // Enter solve() iterations
662  {
663 #ifdef BELOS_TEUCHOS_TIME_MONITOR
664  Teuchos::TimeMonitor slvtimer(*timerSolve_);
665 #endif
666 
667  while ( numRHS2Solve > 0 ) {
668  //
669  // Reset the active / converged vectors from this block
670  std::vector<int> convRHSIdx;
671  std::vector<int> currRHSIdx( currIdx );
672  currRHSIdx.resize(numCurrRHS);
673 
674  // Reset the number of iterations.
675  tfqmr_iter->resetNumIters();
676 
677  // Reset the number of calls that the status test output knows about.
678  outputTest_->resetNumCalls();
679 
680  // Get the current residual for this block of linear systems.
681  Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
682 
683  // Set the new state and initialize the solver.
685  newstate.R = R_0;
686  tfqmr_iter->initializeTFQMR(newstate);
687 
688  while(1) {
689 
690  // tell tfqmr_iter to iterate
691  try {
692  tfqmr_iter->iterate();
693 
695  //
696  // check convergence first
697  //
699  if ( convTest_->getStatus() == Passed ) {
700  // We have convergence of the linear system.
701  break; // break from while(1){tfqmr_iter->iterate()}
702  }
704  //
705  // check for maximum iterations
706  //
708  else if ( maxIterTest_->getStatus() == Passed ) {
709  // we don't have convergence
710  isConverged = false;
711  break; // break from while(1){tfqmr_iter->iterate()}
712  }
713 
715  //
716  // we returned from iterate(), but none of our status tests Passed.
717  // something is wrong, and it is probably our fault.
718  //
720 
721  else {
722  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
723  "Belos::TFQMRSolMgr::solve(): Invalid return from TFQMRIter::iterate().");
724  }
725  }
726  catch (const StatusTestNaNError& e) {
727  // A NaN was detected in the solver. Set the solution to zero and return unconverged.
728  achievedTol_ = MT::one();
729  Teuchos::RCP<MV> X = problem_->getLHS();
730  MVT::MvInit( *X, SCT::zero() );
731  printer_->stream(Warnings) << "Belos::TFQMRSolMgr::solve(): Warning! NaN has been detected!"
732  << std::endl;
733  return Unconverged;
734  }
735  catch (const std::exception &e) {
736  printer_->stream(Errors) << "Error! Caught std::exception in TFQMRIter::iterate() at iteration "
737  << tfqmr_iter->getNumIters() << std::endl
738  << e.what() << std::endl;
739  throw;
740  }
741  }
742 
743  // Update the current solution with the update computed by the iteration object.
744  problem_->updateSolution( tfqmr_iter->getCurrentUpdate(), true );
745 
746  // Inform the linear problem that we are finished with this block linear system.
747  problem_->setCurrLS();
748 
749  // Update indices for the linear systems to be solved.
750  startPtr += numCurrRHS;
751  numRHS2Solve -= numCurrRHS;
752  if ( numRHS2Solve > 0 ) {
753  numCurrRHS = blockSize_;
754 
755  currIdx.resize( blockSize_ );
756  currIdx2.resize( blockSize_ );
757  for (int i=0; i<numCurrRHS; ++i)
758  { currIdx[i] = startPtr+i; currIdx2[i] = i; }
759  // Set the next indices.
760  problem_->setLSIndex( currIdx );
761 
762  // Set the new blocksize for the solver.
763  tfqmr_iter->setBlockSize( blockSize_ );
764  }
765  else {
766  currIdx.resize( numRHS2Solve );
767  }
768 
769  }// while ( numRHS2Solve > 0 )
770 
771  }
772 
773  // print final summary
774  sTest_->print( printer_->stream(FinalSummary) );
775 
776  // print timing information
777 #ifdef BELOS_TEUCHOS_TIME_MONITOR
778  // Calling summarize() can be expensive, so don't call unless the
779  // user wants to print out timing details. summarize() will do all
780  // the work even if it's passed a "black hole" output stream.
781  if (verbosity_ & TimingDetails)
782  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
783 #endif
784 
785  // get iteration information for this solve
786  numIters_ = maxIterTest_->getNumIters();
787 
788  // Save the convergence test value ("achieved tolerance") for this
789  // solve. For this solver, convTest_ may either be a single
790  // (implicit) residual norm test, or a combination of two residual
791  // norm tests. In the latter case, the master convergence test
792  // convTest_ is a SEQ combo of the implicit resp. explicit tests.
793  // If the implicit test never passes, then the explicit test won't
794  // ever be executed. This manifests as
795  // expConvTest_->getTestValue()->size() < 1. We deal with this case
796  // by using the values returned by impConvTest_->getTestValue().
797  {
798  // We'll fetch the vector of residual norms one way or the other.
799  const std::vector<MagnitudeType>* pTestValues = NULL;
800  if (expResTest_) {
801  pTestValues = expConvTest_->getTestValue();
802  if (pTestValues == NULL || pTestValues->size() < 1) {
803  pTestValues = impConvTest_->getTestValue();
804  }
805  }
806  else {
807  // Only the implicit residual norm test is being used.
808  pTestValues = impConvTest_->getTestValue();
809  }
810  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
811  "Belos::TFQMRSolMgr::solve(): The implicit convergence test's "
812  "getTestValue() method returned NULL. Please report this bug to the "
813  "Belos developers.");
814  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
815  "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
816  "getTestValue() method returned a vector of length zero. Please report "
817  "this bug to the Belos developers.");
818 
819  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
820  // achieved tolerances for all vectors in the current solve(), or
821  // just for the vectors from the last deflation?
822  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
823  }
824 
825  if (!isConverged) {
826  return Unconverged; // return from TFQMRSolMgr::solve()
827  }
828  return Converged; // return from TFQMRSolMgr::solve()
829 }
830 
831 // This method requires the solver manager to return a std::string that describes itself.
832 template<class ScalarType, class MV, class OP>
834 {
835  std::ostringstream oss;
836  oss << "Belos::TFQMRSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
837  oss << "{}";
838  return oss.str();
839 }
840 
841 } // end Belos namespace
842 
843 #endif /* BELOS_TFQMR_SOLMGR_HPP */
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:74
Collection of types and exceptions used within the Belos solvers.
This class implements the preconditioned transpose-free QMR algorithm for solving non-Hermitian linea...
int getNumIters() const override
Get the iteration count for the most recent call to solve().
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which manages the output and verbosity of the Belos solvers.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
bool is_null(const boost::shared_ptr< T > &p)
static constexpr int outputStyle_default_
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > outputTest_
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > convTest_
static constexpr bool expResTest_default_
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
bool isLOADetected() const override
Whether loss of accuracy was detected during the last solve() invocation.
T & get(ParameterList &l, const std::string &name)
static RCP< Time > getNewCounter(const std::string &name)
bool is_null(const std::shared_ptr< T > &p)
static constexpr int outputFreq_default_
MultiVecTraits< ScalarType, MV > MVT
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
A factory class for generating StatusTestOutput objects.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< Teuchos::Time > timerSolve_
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
static constexpr const char * label_default_
An implementation of StatusTestResNorm using a family of residual norms.
static constexpr int maxIters_default_
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::RCP< const MV > R
The current residual basis.
static const double convTol
Default convergence tolerance.
Definition: BelosTypes.hpp:261
Belos::StatusTest class for specifying a maximum number of iterations.
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > expConvTest_
Teuchos::RCP< OutputManager< ScalarType > > printer_
std::string description() const override
Method to return description of the TFQMR solver manager.
static std::string name()
Teuchos::ScalarTraits< ScalarType > SCT
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< StatusTestGenResNorm< ScalarType, MV, OP > > impConvTest_
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver&#39;s iterate() routine unti...
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
static constexpr int verbosity_default_
bool isParameter(const std::string &name) const
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
A Belos::StatusTest class for specifying a maximum number of iterations.
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:174
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Pure virtual base class which describes the basic interface for a solver manager. ...
static const double impTolScale
&quot;Implicit Tolerance Scale Factor&quot;
Definition: BelosTypes.hpp:273
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
A linear system to solve, and its associated information.
Structure to contain pointers to TFQMRIter state variables.
Class which describes the linear problem to be solved by the iterative solver.
TFQMRSolMgr()
Empty constructor for TFQMRSolMgr. This constructor takes no arguments and sets the default values fo...
Teuchos::RCP< std::ostream > outputStream_
virtual ~TFQMRSolMgr()
Destructor.
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:123
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
The Belos::TFQMRSolMgr provides a powerful and fully-featured solver manager over the TFQMR linear so...
MagnitudeType impTolScale_
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
static constexpr const char * expResScale_default_
Teuchos::RCP< Teuchos::ParameterList > params_
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > create(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, int mod, int printStates)
Create the StatusTestOutput object specified by the outputStyle.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
bool isType(const std::string &name) const
A class for extending the status testing capabilities of Belos via logical combinations.
MagnitudeType achievedTol_
TFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
static constexpr const char * impResScale_default_
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:28
Default parameters common to most Belos solvers.
Definition: BelosTypes.hpp:251
TFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i.e.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
Belos header file which uses auto-configuration information to include necessary C++ headers...
OperatorTraits< ScalarType, MV, OP > OPT
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Teuchos::ScalarTraits< MagnitudeType > MT