Belos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosFixedPointSolMgr.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_FIXEDPOINT_SOLMGR_HPP
43 #define BELOS_FIXEDPOINT_SOLMGR_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 
52 #include "BelosLinearProblem.hpp"
53 #include "BelosSolverManager.hpp"
54 
55 #include "BelosCGIter.hpp"
56 #include "BelosFixedPointIter.hpp"
59 #include "BelosStatusTestCombo.hpp"
61 #include "BelosOutputManager.hpp"
62 #include "Teuchos_BLAS.hpp"
63 #include "Teuchos_LAPACK.hpp"
64 #ifdef BELOS_TEUCHOS_TIME_MONITOR
65 # include "Teuchos_TimeMonitor.hpp"
66 #endif
67 #include <algorithm>
68 
77 namespace Belos {
78 
80 
81 
89  FixedPointSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
90  {}};
91 
92  template<class ScalarType, class MV, class OP>
93  class FixedPointSolMgr : public SolverManager<ScalarType,MV,OP> {
94 
95  private:
101 
102  public:
103 
105 
106 
113 
133 
135  virtual ~FixedPointSolMgr() {};
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 
183  bool isLOADetected() const override { return false; }
185 
187 
188 
190  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) override { problem_ = problem; }
191 
193  void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
194 
197  {
198 
199  convTest_ = userConvStatusTest;
200 
201  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
202  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
203 
206 
207  std::string solverDesc = " Fixed Point ";
208  outputTest_->setSolverDesc( solverDesc );
209  }
210 
212 
214 
215 
219  void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
221 
223 
224 
242  ReturnType solve() override;
244 
247 
249  std::string description() const override;
251 
252  private:
253 
256 
261 
267 
270 
273 
276 
279 
280  //
281  // Default solver parameters.
282  //
283  static constexpr int maxIters_default_ = 1000;
284  static constexpr bool showMaxResNormOnly_default_ = false;
285  static constexpr int blockSize_default_ = 1;
286  static constexpr int verbosity_default_ = Belos::Errors;
287  static constexpr int outputStyle_default_ = Belos::General;
288  static constexpr int outputFreq_default_ = -1;
289  static constexpr const char * label_default_ = "Belos";
290  static constexpr std::ostream * outputStream_default_ = &std::cout;
291 
292  //
293  // Current solver parameters and other values.
294  //
295 
298 
305 
308 
311 
314 
316  std::string label_;
317 
320 
322  bool isSet_;
323  };
324 
325 
326 // Empty Constructor
327 template<class ScalarType, class MV, class OP>
329  outputStream_(Teuchos::rcp(outputStream_default_,false)),
330  convtol_(DefaultSolverParameters::convTol),
331  achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
332  maxIters_(maxIters_default_),
333  numIters_(0),
334  blockSize_(blockSize_default_),
335  verbosity_(verbosity_default_),
336  outputStyle_(outputStyle_default_),
337  outputFreq_(outputFreq_default_),
338  showMaxResNormOnly_(showMaxResNormOnly_default_),
339  label_(label_default_),
340  isSet_(false)
341 {}
342 
343 
344 // Basic Constructor
345 template<class ScalarType, class MV, class OP>
349  problem_(problem),
350  outputStream_(Teuchos::rcp(outputStream_default_,false)),
351  convtol_(DefaultSolverParameters::convTol),
352  achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
353  maxIters_(maxIters_default_),
354  numIters_(0),
355  blockSize_(blockSize_default_),
356  verbosity_(verbosity_default_),
357  outputStyle_(outputStyle_default_),
358  outputFreq_(outputFreq_default_),
359  showMaxResNormOnly_(showMaxResNormOnly_default_),
360  label_(label_default_),
361  isSet_(false)
362 {
363  TEUCHOS_TEST_FOR_EXCEPTION(problem_.is_null(), std::invalid_argument,
364  "FixedPointSolMgr's constructor requires a nonnull LinearProblem instance.");
365 
366  // If the user passed in a nonnull parameter list, set parameters.
367  // Otherwise, the next solve() call will use default parameters,
368  // unless the user calls setParameters() first.
369  if (! pl.is_null()) {
370  setParameters (pl);
371  }
372 }
373 
374 template<class ScalarType, class MV, class OP>
375 void
378 {
379  // Create the internal parameter list if one doesn't already exist.
380  if (params_ == Teuchos::null) {
381  params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
382  }
383  else {
384  params->validateParameters(*getValidParameters());
385  }
386 
387  // Check for maximum number of iterations
388  if (params->isParameter("Maximum Iterations")) {
389  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
390 
391  // Update parameter in our list and in status test.
392  params_->set("Maximum Iterations", maxIters_);
393  if (maxIterTest_!=Teuchos::null)
394  maxIterTest_->setMaxIters( maxIters_ );
395  }
396 
397  // Check for blocksize
398  if (params->isParameter("Block Size")) {
399  blockSize_ = params->get("Block Size",blockSize_default_);
400  TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
401  "Belos::FixedPointSolMgr: \"Block Size\" must be strictly positive.");
402 
403  // Update parameter in our list.
404  params_->set("Block Size", blockSize_);
405  }
406 
407  // Check to see if the timer label changed.
408  if (params->isParameter("Timer Label")) {
409  std::string tempLabel = params->get("Timer Label", label_default_);
410 
411  // Update parameter in our list and solver timer
412  if (tempLabel != label_) {
413  label_ = tempLabel;
414  params_->set("Timer Label", label_);
415  std::string solveLabel = label_ + ": FixedPointSolMgr total solve time";
416 #ifdef BELOS_TEUCHOS_TIME_MONITOR
417  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
418 #endif
419  }
420  }
421 
422  // Check for a change in verbosity level
423  if (params->isParameter("Verbosity")) {
424  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
425  verbosity_ = params->get("Verbosity", verbosity_default_);
426  } else {
427  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
428  }
429 
430  // Update parameter in our list.
431  params_->set("Verbosity", verbosity_);
432  if (printer_ != Teuchos::null)
433  printer_->setVerbosity(verbosity_);
434  }
435 
436  // Check for a change in output style
437  if (params->isParameter("Output Style")) {
438  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
439  outputStyle_ = params->get("Output Style", outputStyle_default_);
440  } else {
441  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
442  }
443 
444  // Update parameter in our list.
445  params_->set("Output Style", outputStyle_);
446  outputTest_ = Teuchos::null;
447  }
448 
449  // output stream
450  if (params->isParameter("Output Stream")) {
451  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
452 
453  // Update parameter in our list.
454  params_->set("Output Stream", outputStream_);
455  if (printer_ != Teuchos::null)
456  printer_->setOStream( outputStream_ );
457  }
458 
459  // frequency level
460  if (verbosity_ & Belos::StatusTestDetails) {
461  if (params->isParameter("Output Frequency")) {
462  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
463  }
464 
465  // Update parameter in out list and output status test.
466  params_->set("Output Frequency", outputFreq_);
467  if (outputTest_ != Teuchos::null)
468  outputTest_->setOutputFrequency( outputFreq_ );
469  }
470 
471  // Create output manager if we need to.
472  if (printer_ == Teuchos::null) {
473  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
474  }
475 
476  // Convergence
477  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
478  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestResNorm_t;
479 
480  // Check for convergence tolerance
481  if (params->isParameter("Convergence Tolerance")) {
482  if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
483  convtol_ = params->get ("Convergence Tolerance",
484  static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
485  }
486  else {
487  convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
488  }
489 
490  // Update parameter in our list and residual tests.
491  params_->set("Convergence Tolerance", convtol_);
492  if (convTest_ != Teuchos::null)
493  convTest_->setTolerance( convtol_ );
494  }
495 
496  if (params->isParameter("Show Maximum Residual Norm Only")) {
497  showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
498 
499  // Update parameter in our list and residual tests
500  params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
501  if (convTest_ != Teuchos::null)
502  convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
503  }
504 
505  // Create status tests if we need to.
506 
507  // Basic test checks maximum iterations and native residual.
508  if (maxIterTest_ == Teuchos::null)
509  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
510 
511  // Implicit residual test, using the native residual to determine if convergence was achieved.
512  if (convTest_ == Teuchos::null)
513  convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, 1 ) );
514 
515  if (sTest_ == Teuchos::null)
516  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
517 
518  if (outputTest_ == Teuchos::null) {
519 
520  // Create the status test output class.
521  // This class manages and formats the output from the status test.
522  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
523  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
524 
525  // Set the solver string for the output test
526  std::string solverDesc = " Fixed Point ";
527  outputTest_->setSolverDesc( solverDesc );
528 
529  }
530 
531  // Create the timer if we need to.
532  if (timerSolve_ == Teuchos::null) {
533  std::string solveLabel = label_ + ": FixedPointSolMgr total solve time";
534 #ifdef BELOS_TEUCHOS_TIME_MONITOR
535  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
536 #endif
537  }
538 
539  // Inform the solver manager that the current parameters were set.
540  isSet_ = true;
541 }
542 
543 
544 template<class ScalarType, class MV, class OP>
547 {
549 
550  // Set all the valid parameters and their default values.
551  if(is_null(validPL)) {
552  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
553 
554  // The static_cast is to resolve an issue with older clang versions which
555  // would cause the constexpr to link fail. With c++17 the problem is resolved.
556  pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
557  "The relative residual tolerance that needs to be achieved by the\n"
558  "iterative solver in order for the linear system to be declared converged.");
559  pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
560  "The maximum number of block iterations allowed for each\n"
561  "set of RHS solved.");
562  pl->set("Block Size", static_cast<int>(blockSize_default_),
563  "The number of vectors in each block.");
564  pl->set("Verbosity", static_cast<int>(verbosity_default_),
565  "What type(s) of solver information should be outputted\n"
566  "to the output stream.");
567  pl->set("Output Style", static_cast<int>(outputStyle_default_),
568  "What style is used for the solver information outputted\n"
569  "to the output stream.");
570  pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
571  "How often convergence information should be outputted\n"
572  "to the output stream.");
573  pl->set("Output Stream", Teuchos::rcp(outputStream_default_,false),
574  "A reference-counted pointer to the output stream where all\n"
575  "solver output is sent.");
576  pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
577  "When convergence information is printed, only show the maximum\n"
578  "relative residual norm when the block size is greater than one.");
579  pl->set("Timer Label", static_cast<const char *>(label_default_),
580  "The string to use as a prefix for the timer labels.");
581  validPL = pl;
582  }
583  return validPL;
584 }
585 
586 
587 // solve()
588 template<class ScalarType, class MV, class OP>
590  using Teuchos::RCP;
591  using Teuchos::rcp;
592  using Teuchos::rcp_const_cast;
593  using Teuchos::rcp_dynamic_cast;
594 
595  // Set the current parameters if they were not set before. NOTE:
596  // This may occur if the user generated the solver manager with the
597  // default constructor and then didn't set any parameters using
598  // setParameters().
599  if (!isSet_) {
600  setParameters(Teuchos::parameterList(*getValidParameters()));
601  }
602 
605 
606  TEUCHOS_TEST_FOR_EXCEPTION( !problem_->isProblemSet(),
608  "Belos::FixedPointSolMgr::solve(): Linear problem is not ready, setProblem() "
609  "has not been called.");
610 
611  // Create indices for the linear systems to be solved.
612  int startPtr = 0;
613  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
614  int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
615 
616  std::vector<int> currIdx, currIdx2;
617  currIdx.resize( blockSize_ );
618  currIdx2.resize( blockSize_ );
619  for (int i=0; i<numCurrRHS; ++i)
620  { currIdx[i] = startPtr+i; currIdx2[i]=i; }
621  for (int i=numCurrRHS; i<blockSize_; ++i)
622  { currIdx[i] = -1; currIdx2[i] = i; }
623 
624  // Inform the linear problem of the current linear system to solve.
625  problem_->setLSIndex( currIdx );
626 
628  // Set up the parameter list for the Iteration subclass.
630  plist.set("Block Size",blockSize_);
631 
632  // Reset the output status test (controls all the other status tests).
633  outputTest_->reset();
634 
635  // Assume convergence is achieved, then let any failed convergence
636  // set this to false. "Innocent until proven guilty."
637  bool isConverged = true;
638 
640  // Set up the FixedPoint Iteration subclass.
641 
642  RCP<FixedPointIteration<ScalarType,MV,OP> > block_fp_iter;
643  block_fp_iter = rcp (new FixedPointIter<ScalarType,MV,OP> (problem_, printer_, outputTest_, plist));
644 
645  // Enter solve() iterations
646  {
647 #ifdef BELOS_TEUCHOS_TIME_MONITOR
648  Teuchos::TimeMonitor slvtimer(*timerSolve_);
649 #endif
650 
651  while ( numRHS2Solve > 0 ) {
652  //
653  // Reset the active / converged vectors from this block
654  std::vector<int> convRHSIdx;
655  std::vector<int> currRHSIdx( currIdx );
656  currRHSIdx.resize(numCurrRHS);
657 
658  // Reset the number of iterations.
659  block_fp_iter->resetNumIters();
660 
661  // Reset the number of calls that the status test output knows about.
662  outputTest_->resetNumCalls();
663 
664  // Get the current residual for this block of linear systems.
665  RCP<MV> R_0 = MVT::CloneViewNonConst( *(rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
666 
667  // Set the new state and initialize the solver.
669  newstate.R = R_0;
670  block_fp_iter->initializeFixedPoint(newstate);
671 
672  while(1) {
673 
674  // tell block_fp_iter to iterate
675  try {
676  block_fp_iter->iterate();
677  //
678  // Check whether any of the linear systems converged.
679  //
680  if (convTest_->getStatus() == Passed) {
681  // At least one of the linear system(s) converged.
682  //
683  // Get the column indices of the linear systems that converged.
684  std::vector<int> convIdx = convTest_->convIndices();
685 
686  // If the number of converged linear systems equals the
687  // number of linear systems currently being solved, then
688  // we are done with this block.
689  if (convIdx.size() == currRHSIdx.size())
690  break; // break from while(1){block_fp_iter->iterate()}
691 
692  // Inform the linear problem that we are finished with
693  // this current linear system.
694  problem_->setCurrLS();
695 
696  // Reset currRHSIdx to contain the right-hand sides that
697  // are left to converge for this block.
698  int have = 0;
699  std::vector<int> unconvIdx(currRHSIdx.size());
700  for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
701  bool found = false;
702  for (unsigned int j=0; j<convIdx.size(); ++j) {
703  if (currRHSIdx[i] == convIdx[j]) {
704  found = true;
705  break;
706  }
707  }
708  if (!found) {
709  currIdx2[have] = currIdx2[i];
710  currRHSIdx[have++] = currRHSIdx[i];
711  }
712  else {
713  }
714  }
715  currRHSIdx.resize(have);
716  currIdx2.resize(have);
717 
718  // Set the remaining indices after deflation.
719  problem_->setLSIndex( currRHSIdx );
720 
721  // Get the current residual vector.
722  std::vector<MagnitudeType> norms;
723  R_0 = MVT::CloneCopy( *(block_fp_iter->getNativeResiduals(&norms)),currIdx2 );
724  for (int i=0; i<have; ++i) { currIdx2[i] = i; }
725 
726  // Set the new blocksize for the solver.
727  block_fp_iter->setBlockSize( have );
728 
729  // Set the new state and initialize the solver.
731  defstate.R = R_0;
732  block_fp_iter->initializeFixedPoint(defstate);
733  }
734  //
735  // None of the linear systems converged. Check whether the
736  // maximum iteration count was reached.
737  //
738  else if (maxIterTest_->getStatus() == Passed) {
739  isConverged = false; // None of the linear systems converged.
740  break; // break from while(1){block_fp_iter->iterate()}
741  }
742  //
743  // iterate() returned, but none of our status tests Passed.
744  // This indicates a bug.
745  //
746  else {
747  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
748  "Belos::FixedPointSolMgr::solve(): Neither the convergence test nor "
749  "the maximum iteration count test passed. Please report this bug "
750  "to the Belos developers.");
751  }
752  }
753  catch (const std::exception &e) {
754  std::ostream& err = printer_->stream (Errors);
755  err << "Error! Caught std::exception in FixedPointIteration::iterate() at "
756  << "iteration " << block_fp_iter->getNumIters() << std::endl
757  << e.what() << std::endl;
758  throw;
759  }
760  }
761 
762  // Inform the linear problem that we are finished with this
763  // block linear system.
764  problem_->setCurrLS();
765 
766  // Update indices for the linear systems to be solved.
767  startPtr += numCurrRHS;
768  numRHS2Solve -= numCurrRHS;
769  if ( numRHS2Solve > 0 ) {
770  numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
771 
772 
773  currIdx.resize( blockSize_ );
774  currIdx2.resize( blockSize_ );
775  for (int i=0; i<numCurrRHS; ++i)
776  { currIdx[i] = startPtr+i; currIdx2[i] = i; }
777  for (int i=numCurrRHS; i<blockSize_; ++i)
778  { currIdx[i] = -1; currIdx2[i] = i; }
779 
780  // Set the next indices.
781  problem_->setLSIndex( currIdx );
782 
783  // Set the new blocksize for the solver.
784  block_fp_iter->setBlockSize( blockSize_ );
785  }
786  else {
787  currIdx.resize( numRHS2Solve );
788  }
789 
790  }// while ( numRHS2Solve > 0 )
791 
792  }
793 
794  // print final summary
795  sTest_->print( printer_->stream(FinalSummary) );
796 
797  // print timing information
798 #ifdef BELOS_TEUCHOS_TIME_MONITOR
799  // Calling summarize() requires communication in general, so don't
800  // call it unless the user wants to print out timing details.
801  // summarize() will do all the work even if it's passed a "black
802  // hole" output stream.
803  if (verbosity_ & TimingDetails) {
804  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
805  }
806 #endif
807 
808  // Save the iteration count for this solve.
809  numIters_ = maxIterTest_->getNumIters();
810 
811  // Save the convergence test value ("achieved tolerance") for this solve.
812  {
813  // testValues is nonnull and not persistent.
814  const std::vector<MagnitudeType>* pTestValues = convTest_->getTestValue();
815 
816  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
817  "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
818  "method returned NULL. Please report this bug to the Belos developers.");
819 
820  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
821  "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
822  "method returned a vector of length zero. Please report this bug to the "
823  "Belos developers.");
824 
825  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
826  // achieved tolerances for all vectors in the current solve(), or
827  // just for the vectors from the last deflation?
828  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
829  }
830 
831  if (!isConverged) {
832  return Unconverged; // return from FixedPointSolMgr::solve()
833  }
834  return Converged; // return from FixedPointSolMgr::solve()
835 }
836 
837 // This method requires the solver manager to return a std::string that describes itself.
838 template<class ScalarType, class MV, class OP>
840 {
841  std::ostringstream oss;
842  oss << "Belos::FixedPointSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
843  return oss.str();
844 }
845 
846 } // end Belos namespace
847 
848 #endif /* BELOS_FIXEDPOINT_SOLMGR_HPP */
Collection of types and exceptions used within the Belos solvers.
Belos&#39;s basic output manager for sending information of select verbosity levels to the appropriate ou...
The Belos::FixedPointSolMgr provides a powerful and fully-featured solver manager over the FixedPoint...
Class which manages the output and verbosity of the Belos solvers.
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
bool is_null(const boost::shared_ptr< T > &p)
Teuchos::RCP< Teuchos::ParameterList > params_
Current parameter list.
Belos concrete class for performing fixed point iteration iteration.
OperatorTraits< ScalarType, MV, OP > OPT
FixedPointSolMgr()
Empty constructor for FixedPointSolMgr. This constructor takes no arguments and sets the default valu...
static constexpr int outputStyle_default_
T & get(ParameterList &l, const std::string &name)
static constexpr int maxIters_default_
Belos concrete class for performing the conjugate-gradient (CG) iteration.
static constexpr std::ostream * outputStream_default_
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)
Teuchos::ScalarTraits< MagnitudeType > MT
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
A factory class for generating StatusTestOutput objects.
static constexpr int outputFreq_default_
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
An abstract class of StatusTest for stopping criteria using residual norms.
static constexpr int verbosity_default_
An implementation of StatusTestResNorm using a family of residual norms.
static constexpr bool showMaxResNormOnly_default_
static const double convTol
Default convergence tolerance.
Definition: BelosTypes.hpp:293
Belos::StatusTest class for specifying a maximum number of iterations.
MultiVecTraits< ScalarType, MV > MVT
static std::string name()
static constexpr int blockSize_default_
A factory class for generating StatusTestOutput objects.
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
bool isParameter(const std::string &name) const
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
Teuchos::RCP< std::ostream > outputStream_
Output stream to which the output manager prints.
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 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)
bool is_null(const RCP< T > &p)
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
virtual ~FixedPointSolMgr()
Destructor.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
int numIters_
Number of iterations taken by the last solve() invocation.
std::string description() const override
Method to return description of the block CG solver manager.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver&#39;s iterate() routine unti...
bool isSet_
Whether or not the parameters have been set (via setParameters()).
int maxIters_
Maximum iteration count (read from parameter list).
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_
Maximum iteration count stopping criterion.
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:155
Teuchos::RCP< Teuchos::Time > timerSolve_
Solve timer.
void replaceUserConvStatusTest(const Teuchos::RCP< StatusTestResNorm< ScalarType, MV, OP > > &userConvStatusTest)
Set user-defined convergence status test.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Teuchos::RCP< OutputManager< ScalarType > > printer_
Output manager, that handles printing of different kinds of messages.
Teuchos::RCP< const MV > R
The current residual.
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 * label_default_
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
FixedPointSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
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.
Structure to contain pointers to FixedPointIteration state variables.
FixedPointSolMgrLinearProblemFailure(const std::string &what_arg)
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > outputTest_
Output &quot;status test&quot; that controls all the other status tests.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
bool isType(const std::string &name) const
A class for extending the status testing capabilities of Belos via logical combinations.
int getNumIters() const override
Get the iteration count for the most recent call to solve().
Teuchos::RCP< StatusTestResNorm< ScalarType, MV, OP > > convTest_
Convergence stopping criterion.
Class which defines basic traits for the operator type.
MagnitudeType achievedTol_
Tolerance achieved by the last solve() invocation.
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:60
Default parameters common to most Belos solvers.
Definition: BelosTypes.hpp:283
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
The linear problem to solve.
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
Teuchos::ScalarTraits< ScalarType > SCT
Belos header file which uses auto-configuration information to include necessary C++ headers...
This class implements the preconditioned fixed point iteration.
std::string label_
Prefix label for all the timers.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
Aggregate stopping criterion.
MagnitudeType convtol_
Convergence tolerance (read from parameter list).