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 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the 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 BELOS_TFQMR_SOLMGR_HPP
43 #define BELOS_TFQMR_SOLMGR_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 
52 #include "BelosLinearProblem.hpp"
53 #include "BelosSolverManager.hpp"
54 
55 #include "BelosTFQMRIter.hpp"
58 #include "BelosStatusTestCombo.hpp"
60 #include "BelosOutputManager.hpp"
61 #ifdef BELOS_TEUCHOS_TIME_MONITOR
62 #include "Teuchos_TimeMonitor.hpp"
63 #endif
64 
78 namespace Belos {
79 
81 
82 
90  TFQMRSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
91  {}};
92 
93  template<class ScalarType, class MV, class OP>
94  class TFQMRSolMgr : public SolverManager<ScalarType,MV,OP> {
95 
96  private:
102 
103  public:
104 
106 
107 
113  TFQMRSolMgr();
114 
133 
135  virtual ~TFQMRSolMgr() {};
136 
140  }
142 
144 
145 
146  const LinearProblem<ScalarType,MV,OP>& getProblem() const override {
147  return *problem_;
148  }
149 
153 
157 
164  return Teuchos::tuple(timerSolve_);
165  }
166 
172  MagnitudeType achievedTol() const override {
173  return achievedTol_;
174  }
175 
177  int getNumIters() const override {
178  return numIters_;
179  }
180 
188  bool isLOADetected() const override { return false; }
190 
192 
193 
195  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) override { problem_ = problem; }
196 
198  void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
199 
201 
203 
208  void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
210 
212 
213 
231  ReturnType solve() override;
232 
234 
236 
238  std::string description() const override;
240 
241  private:
242 
243  // Method for checking current status test against defined linear problem.
244  bool checkStatusTest();
245 
246  // Linear problem.
248 
249  // Output manager.
252 
253  // Status test.
259 
260  // Current parameter list.
262 
263  // Default solver values.
264  static constexpr int maxIters_default_ = 1000;
265  static constexpr bool expResTest_default_ = false;
266  static constexpr int verbosity_default_ = Belos::Errors;
267  static constexpr int outputStyle_default_ = Belos::General;
268  static constexpr int outputFreq_default_ = -1;
269  static constexpr const char * impResScale_default_ = "Norm of Preconditioned Initial Residual";
270  static constexpr const char * expResScale_default_ = "Norm of Initial Residual";
271  static constexpr const char * label_default_ = "Belos";
272 
273  // Current solver values.
280 
281  // Timers.
282  std::string label_;
284 
285  // Internal state variables.
287  };
288 
289 
290 // Empty Constructor
291 template<class ScalarType, class MV, class OP>
293  outputStream_(Teuchos::rcpFromRef(std::cout)),
294  convtol_(DefaultSolverParameters::convTol),
295  impTolScale_(DefaultSolverParameters::impTolScale),
296  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
297  maxIters_(maxIters_default_),
298  numIters_(0),
299  verbosity_(verbosity_default_),
300  outputStyle_(outputStyle_default_),
301  outputFreq_(outputFreq_default_),
302  blockSize_(1),
303  expResTest_(expResTest_default_),
304  impResScale_(impResScale_default_),
305  expResScale_(expResScale_default_),
306  label_(label_default_),
307  isSet_(false),
308  isSTSet_(false)
309 {}
310 
311 
312 // Basic Constructor
313 template<class ScalarType, class MV, class OP>
317  problem_(problem),
318  outputStream_(Teuchos::rcpFromRef(std::cout)),
319  convtol_(DefaultSolverParameters::convTol),
320  impTolScale_(DefaultSolverParameters::impTolScale),
321  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
322  maxIters_(maxIters_default_),
323  numIters_(0),
324  verbosity_(verbosity_default_),
325  outputStyle_(outputStyle_default_),
326  outputFreq_(outputFreq_default_),
327  blockSize_(1),
328  expResTest_(expResTest_default_),
329  impResScale_(impResScale_default_),
330  expResScale_(expResScale_default_),
331  label_(label_default_),
332  isSet_(false),
333  isSTSet_(false)
334 {
335  TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument, "Problem not given to solver manager.");
336 
337  // If the parameter list pointer is null, then set the current parameters to the default parameter list.
338  if ( !is_null(pl) ) {
339  setParameters( pl );
340  }
341 }
342 
343 template<class ScalarType, class MV, class OP>
345 {
346  // Create the internal parameter list if ones doesn't already exist.
347  if (params_ == Teuchos::null) {
348  params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
349  }
350  else {
351  params->validateParameters(*getValidParameters());
352  }
353 
354  // Check for maximum number of iterations
355  if (params->isParameter("Maximum Iterations")) {
356  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
357 
358  // Update parameter in our list and in status test.
359  params_->set("Maximum Iterations", maxIters_);
360  if (maxIterTest_!=Teuchos::null)
361  maxIterTest_->setMaxIters( maxIters_ );
362  }
363 
364  // Check for blocksize
365  if (params->isParameter("Block Size")) {
366  blockSize_ = params->get("Block Size",1);
367  TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ != 1, std::invalid_argument,
368  "Belos::TFQMRSolMgr: \"Block Size\" must be 1.");
369 
370  // Update parameter in our list.
371  params_->set("Block Size", blockSize_);
372  }
373 
374  // Check to see if the timer label changed.
375  if (params->isParameter("Timer Label")) {
376  std::string tempLabel = params->get("Timer Label", label_default_);
377 
378  // Update parameter in our list and solver timer
379  if (tempLabel != label_) {
380  label_ = tempLabel;
381  params_->set("Timer Label", label_);
382  std::string solveLabel = label_ + ": TFQMRSolMgr total solve time";
383 #ifdef BELOS_TEUCHOS_TIME_MONITOR
384  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
385 #endif
386  }
387  }
388 
389  // Check for a change in verbosity level
390  if (params->isParameter("Verbosity")) {
391  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
392  verbosity_ = params->get("Verbosity", verbosity_default_);
393  } else {
394  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
395  }
396 
397  // Update parameter in our list.
398  params_->set("Verbosity", verbosity_);
399  if (printer_ != Teuchos::null)
400  printer_->setVerbosity(verbosity_);
401  }
402 
403  // Check for a change in output style
404  if (params->isParameter("Output Style")) {
405  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
406  outputStyle_ = params->get("Output Style", outputStyle_default_);
407  } else {
408  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
409  }
410 
411  // Reconstruct the convergence test if the explicit residual test is not being used.
412  params_->set("Output Style", outputStyle_);
413  isSTSet_ = false;
414  }
415 
416  // output stream
417  if (params->isParameter("Output Stream")) {
418  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
419 
420  // Update parameter in our list.
421  params_->set("Output Stream", outputStream_);
422  if (printer_ != Teuchos::null)
423  printer_->setOStream( outputStream_ );
424  }
425 
426  // frequency level
427  if (verbosity_ & Belos::StatusTestDetails) {
428  if (params->isParameter("Output Frequency")) {
429  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
430  }
431 
432  // Update parameter in out list and output status test.
433  params_->set("Output Frequency", outputFreq_);
434  if (outputTest_ != Teuchos::null)
435  outputTest_->setOutputFrequency( outputFreq_ );
436  }
437 
438  // Create output manager if we need to.
439  if (printer_ == Teuchos::null) {
440  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
441  }
442 
443  // Check for convergence tolerance
444  if (params->isParameter("Convergence Tolerance")) {
445  if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
446  convtol_ = params->get ("Convergence Tolerance",
447  static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
448  }
449  else {
450  convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
451  }
452 
453  // Update parameter in our list.
454  params_->set("Convergence Tolerance", convtol_);
455  isSTSet_ = false;
456  }
457 
458  // Check for implicit residual scaling
459  if (params->isParameter("Implicit Tolerance Scale Factor")) {
460  if (params->isType<MagnitudeType> ("Implicit Tolerance Scale Factor")) {
461  impTolScale_ = params->get ("Implicit Tolerance Scale Factor",
462  static_cast<MagnitudeType> (DefaultSolverParameters::impTolScale));
463 
464  }
465  else {
466  impTolScale_ = params->get ("Implicit Tolerance Scale Factor",
468  }
469 
470  // Update parameter in our list.
471  params_->set("Implicit Tolerance Scale Factor", impTolScale_);
472  isSTSet_ = false;
473  }
474 
475  // Check for a change in scaling, if so we need to build new residual tests.
476  if (params->isParameter("Implicit Residual Scaling")) {
477  std::string tempImpResScale = Teuchos::getParameter<std::string>( *params, "Implicit Residual Scaling" );
478 
479  // Only update the scaling if it's different.
480  if (impResScale_ != tempImpResScale) {
481  impResScale_ = tempImpResScale;
482 
483  // Update parameter in our list and residual tests
484  params_->set("Implicit Residual Scaling", impResScale_);
485 
486  // Make sure the convergence test gets constructed again.
487  isSTSet_ = false;
488  }
489  }
490 
491  if (params->isParameter("Explicit Residual Scaling")) {
492  std::string tempExpResScale = Teuchos::getParameter<std::string>( *params, "Explicit Residual Scaling" );
493 
494  // Only update the scaling if it's different.
495  if (expResScale_ != tempExpResScale) {
496  expResScale_ = tempExpResScale;
497 
498  // Update parameter in our list and residual tests
499  params_->set("Explicit Residual Scaling", expResScale_);
500 
501  // Make sure the convergence test gets constructed again.
502  isSTSet_ = false;
503  }
504  }
505 
506  if (params->isParameter("Explicit Residual Test")) {
507  expResTest_ = Teuchos::getParameter<bool>( *params,"Explicit Residual Test" );
508 
509  // Reconstruct the convergence test if the explicit residual test is not being used.
510  params_->set("Explicit Residual Test", expResTest_);
511  if (expConvTest_ == Teuchos::null) {
512  isSTSet_ = false;
513  }
514  }
515 
516  // Create the timer if we need to.
517  if (timerSolve_ == Teuchos::null) {
518  std::string solveLabel = label_ + ": TFQMRSolMgr total solve time";
519 #ifdef BELOS_TEUCHOS_TIME_MONITOR
520  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
521 #endif
522  }
523 
524  // Inform the solver manager that the current parameters were set.
525  isSet_ = true;
526 }
527 
528 
529 // Check the status test versus the defined linear problem
530 template<class ScalarType, class MV, class OP>
532 
533  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
534  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestGenResNorm_t;
535 
536  // Basic test checks maximum iterations and native residual.
537  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
538 
539  if (expResTest_) {
540 
541  // Implicit residual test, using the native residual to determine if convergence was achieved.
542  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
543  Teuchos::rcp( new StatusTestGenResNorm_t( impTolScale_*convtol_ ) );
544  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
545  impConvTest_ = tmpImpConvTest;
546 
547  // Explicit residual test once the native residual is below the tolerance
548  Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
549  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
550  tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit, Belos::TwoNorm );
551  tmpExpConvTest->defineScaleForm( convertStringToScaleType(expResScale_), Belos::TwoNorm );
552  expConvTest_ = tmpExpConvTest;
553 
554  // The convergence test is a combination of the "cheap" implicit test and explicit test.
555  convTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
556  }
557  else {
558 
559  // Implicit residual test, using the native residual to determine if convergence was achieved.
560  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
561  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
562  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
563  impConvTest_ = tmpImpConvTest;
564 
565  // Set the explicit and total convergence test to this implicit test that checks for accuracy loss.
566  expConvTest_ = impConvTest_;
567  convTest_ = impConvTest_;
568  }
569  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
570 
571  // Create the status test output class.
572  // This class manages and formats the output from the status test.
573  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
574  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
575 
576  // Set the solver string for the output test
577  std::string solverDesc = " TFQMR ";
578  outputTest_->setSolverDesc( solverDesc );
579 
580 
581  // The status test is now set.
582  isSTSet_ = true;
583 
584  return false;
585 }
586 
587 
588 template<class ScalarType, class MV, class OP>
591 {
593 
594  // Set all the valid parameters and their default values.
595  if(is_null(validPL)) {
596  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
597 
598  // The static_cast is to resolve an issue with older clang versions which
599  // would cause the constexpr to link fail. With c++17 the problem is resolved.
600  pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
601  "The relative residual tolerance that needs to be achieved by the\n"
602  "iterative solver in order for the linear system to be declared converged.");
603  pl->set("Implicit Tolerance Scale Factor", static_cast<MagnitudeType>(DefaultSolverParameters::impTolScale),
604  "The scale factor used by the implicit residual test when explicit residual\n"
605  "testing is used. May enable faster convergence when TFQMR bound is too loose.");
606  pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
607  "The maximum number of block iterations allowed for each\n"
608  "set of RHS solved.");
609  pl->set("Verbosity", static_cast<int>(verbosity_default_),
610  "What type(s) of solver information should be outputted\n"
611  "to the output stream.");
612  pl->set("Output Style", static_cast<int>(outputStyle_default_),
613  "What style is used for the solver information outputted\n"
614  "to the output stream.");
615  pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
616  "How often convergence information should be outputted\n"
617  "to the output stream.");
618  pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
619  "A reference-counted pointer to the output stream where all\n"
620  "solver output is sent.");
621  pl->set("Explicit Residual Test", static_cast<bool>(expResTest_default_),
622  "Whether the explicitly computed residual should be used in the convergence test.");
623  pl->set("Implicit Residual Scaling", static_cast<const char *>(impResScale_default_),
624  "The type of scaling used in the implicit residual convergence test.");
625  pl->set("Explicit Residual Scaling", static_cast<const char *>(expResScale_default_),
626  "The type of scaling used in the explicit residual convergence test.");
627  pl->set("Timer Label", static_cast<const char *>(label_default_),
628  "The string to use as a prefix for the timer labels.");
629  validPL = pl;
630  }
631  return validPL;
632 }
633 
634 
635 // solve()
636 template<class ScalarType, class MV, class OP>
638 
639  // Set the current parameters if they were not set before.
640  // NOTE: This may occur if the user generated the solver manager with the default constructor and
641  // then didn't set any parameters using setParameters().
642  if (!isSet_) {
643  setParameters(Teuchos::parameterList(*getValidParameters()));
644  }
645 
647  "Belos::TFQMRSolMgr::solve(): Linear problem is not a valid object.");
648 
650  "Belos::TFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
651 
652  if (!isSTSet_) {
654  "Belos::TFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
655  }
656 
657  // Create indices for the linear systems to be solved.
658  int startPtr = 0;
659  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
660  int numCurrRHS = blockSize_;
661 
662  std::vector<int> currIdx, currIdx2;
663 
664  // The index set is generated that informs the linear problem that some linear systems are augmented.
665  currIdx.resize( blockSize_ );
666  currIdx2.resize( blockSize_ );
667  for (int i=0; i<numCurrRHS; ++i)
668  { currIdx[i] = startPtr+i; currIdx2[i]=i; }
669 
670  // Inform the linear problem of the current linear system to solve.
671  problem_->setLSIndex( currIdx );
672 
674  // Parameter list
676  plist.set("Block Size",blockSize_);
677 
678  // Reset the status test.
679  outputTest_->reset();
680 
681  // Assume convergence is achieved, then let any failed convergence set this to false.
682  bool isConverged = true;
683 
685  // TFQMR solver
686 
688  Teuchos::rcp( new TFQMRIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,plist) );
689 
690  // Enter solve() iterations
691  {
692 #ifdef BELOS_TEUCHOS_TIME_MONITOR
693  Teuchos::TimeMonitor slvtimer(*timerSolve_);
694 #endif
695 
696  while ( numRHS2Solve > 0 ) {
697  //
698  // Reset the active / converged vectors from this block
699  std::vector<int> convRHSIdx;
700  std::vector<int> currRHSIdx( currIdx );
701  currRHSIdx.resize(numCurrRHS);
702 
703  // Reset the number of iterations.
704  tfqmr_iter->resetNumIters();
705 
706  // Reset the number of calls that the status test output knows about.
707  outputTest_->resetNumCalls();
708 
709  // Get the current residual for this block of linear systems.
710  Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
711 
712  // Set the new state and initialize the solver.
714  newstate.R = R_0;
715  tfqmr_iter->initializeTFQMR(newstate);
716 
717  while(1) {
718 
719  // tell tfqmr_iter to iterate
720  try {
721  tfqmr_iter->iterate();
722 
724  //
725  // check convergence first
726  //
728  if ( convTest_->getStatus() == Passed ) {
729  // We have convergence of the linear system.
730  break; // break from while(1){tfqmr_iter->iterate()}
731  }
733  //
734  // check for maximum iterations
735  //
737  else if ( maxIterTest_->getStatus() == Passed ) {
738  // we don't have convergence
739  isConverged = false;
740  break; // break from while(1){tfqmr_iter->iterate()}
741  }
742 
744  //
745  // we returned from iterate(), but none of our status tests Passed.
746  // something is wrong, and it is probably our fault.
747  //
749 
750  else {
751  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
752  "Belos::TFQMRSolMgr::solve(): Invalid return from TFQMRIter::iterate().");
753  }
754  }
755  catch (const StatusTestNaNError& e) {
756  // A NaN was detected in the solver. Set the solution to zero and return unconverged.
757  achievedTol_ = MT::one();
758  Teuchos::RCP<MV> X = problem_->getLHS();
759  MVT::MvInit( *X, SCT::zero() );
760  printer_->stream(Warnings) << "Belos::TFQMRSolMgr::solve(): Warning! NaN has been detected!"
761  << std::endl;
762  return Unconverged;
763  }
764  catch (const std::exception &e) {
765  printer_->stream(Errors) << "Error! Caught std::exception in TFQMRIter::iterate() at iteration "
766  << tfqmr_iter->getNumIters() << std::endl
767  << e.what() << std::endl;
768  throw;
769  }
770  }
771 
772  // Update the current solution with the update computed by the iteration object.
773  problem_->updateSolution( tfqmr_iter->getCurrentUpdate(), true );
774 
775  // Inform the linear problem that we are finished with this block linear system.
776  problem_->setCurrLS();
777 
778  // Update indices for the linear systems to be solved.
779  startPtr += numCurrRHS;
780  numRHS2Solve -= numCurrRHS;
781  if ( numRHS2Solve > 0 ) {
782  numCurrRHS = blockSize_;
783 
784  currIdx.resize( blockSize_ );
785  currIdx2.resize( blockSize_ );
786  for (int i=0; i<numCurrRHS; ++i)
787  { currIdx[i] = startPtr+i; currIdx2[i] = i; }
788  // Set the next indices.
789  problem_->setLSIndex( currIdx );
790 
791  // Set the new blocksize for the solver.
792  tfqmr_iter->setBlockSize( blockSize_ );
793  }
794  else {
795  currIdx.resize( numRHS2Solve );
796  }
797 
798  }// while ( numRHS2Solve > 0 )
799 
800  }
801 
802  // print final summary
803  sTest_->print( printer_->stream(FinalSummary) );
804 
805  // print timing information
806 #ifdef BELOS_TEUCHOS_TIME_MONITOR
807  // Calling summarize() can be expensive, so don't call unless the
808  // user wants to print out timing details. summarize() will do all
809  // the work even if it's passed a "black hole" output stream.
810  if (verbosity_ & TimingDetails)
811  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
812 #endif
813 
814  // get iteration information for this solve
815  numIters_ = maxIterTest_->getNumIters();
816 
817  // Save the convergence test value ("achieved tolerance") for this
818  // solve. For this solver, convTest_ may either be a single
819  // (implicit) residual norm test, or a combination of two residual
820  // norm tests. In the latter case, the master convergence test
821  // convTest_ is a SEQ combo of the implicit resp. explicit tests.
822  // If the implicit test never passes, then the explicit test won't
823  // ever be executed. This manifests as
824  // expConvTest_->getTestValue()->size() < 1. We deal with this case
825  // by using the values returned by impConvTest_->getTestValue().
826  {
827  // We'll fetch the vector of residual norms one way or the other.
828  const std::vector<MagnitudeType>* pTestValues = NULL;
829  if (expResTest_) {
830  pTestValues = expConvTest_->getTestValue();
831  if (pTestValues == NULL || pTestValues->size() < 1) {
832  pTestValues = impConvTest_->getTestValue();
833  }
834  }
835  else {
836  // Only the implicit residual norm test is being used.
837  pTestValues = impConvTest_->getTestValue();
838  }
839  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
840  "Belos::TFQMRSolMgr::solve(): The implicit convergence test's "
841  "getTestValue() method returned NULL. Please report this bug to the "
842  "Belos developers.");
843  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
844  "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
845  "getTestValue() method returned a vector of length zero. Please report "
846  "this bug to the Belos developers.");
847 
848  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
849  // achieved tolerances for all vectors in the current solve(), or
850  // just for the vectors from the last deflation?
851  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
852  }
853 
854  if (!isConverged) {
855  return Unconverged; // return from TFQMRSolMgr::solve()
856  }
857  return Converged; // return from TFQMRSolMgr::solve()
858 }
859 
860 // This method requires the solver manager to return a std::string that describes itself.
861 template<class ScalarType, class MV, class OP>
863 {
864  std::ostringstream oss;
865  oss << "Belos::TFQMRSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
866  oss << "{}";
867  return oss.str();
868 }
869 
870 } // end Belos namespace
871 
872 #endif /* BELOS_TFQMR_SOLMGR_HPP */
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:106
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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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...
Teuchos::RCP< const MV > R
The current residual basis.
static const double convTol
Default convergence tolerance.
Definition: BelosTypes.hpp:293
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:206
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:305
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:155
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:60
Default parameters common to most Belos solvers.
Definition: BelosTypes.hpp:283
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