Belos  Version of the Day
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:
99  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
101 
102  public:
103 
105 
106 
113 
133 
135  virtual ~FixedPointSolMgr() {};
137 
139 
140 
142  return *problem_;
143  }
144 
148 
152 
159  return Teuchos::tuple(timerSolve_);
160  }
161 
167  MagnitudeType achievedTol() const {
168  return achievedTol_;
169  }
170 
172  int getNumIters() const {
173  return numIters_;
174  }
175 
178  bool isLOADetected() const { return false; }
179 
181 
183 
184 
186  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) { problem_ = problem; }
187 
190 
193  {
194 
195  convTest_ = userConvStatusTest;
196 
197  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
198  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
199 
200  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
201  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
202 
203  std::string solverDesc = " Fixed Point ";
204  outputTest_->setSolverDesc( solverDesc );
205  }
206 
208 
210 
211 
215  void reset( const ResetType type ) { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
217 
219 
220 
238  ReturnType solve();
239 
241 
244 
246  std::string description() const;
247 
249 
250  private:
251 
254 
258  Teuchos::RCP<std::ostream> outputStream_;
259 
265 
268 
271 
274 
277 
278  //
279  // Default solver parameters.
280  //
281  static const MagnitudeType convtol_default_;
282  static const int maxIters_default_;
283  static const bool showMaxResNormOnly_default_;
284  static const int blockSize_default_;
285  static const int verbosity_default_;
286  static const int outputStyle_default_;
287  static const int outputFreq_default_;
288  static const std::string label_default_;
289  static const Teuchos::RCP<std::ostream> outputStream_default_;
290 
291  //
292  // Current solver parameters and other values.
293  //
294 
296  MagnitudeType convtol_;
297 
303  MagnitudeType achievedTol_;
304 
306  int maxIters_;
307 
309  int numIters_;
310 
311  int blockSize_, verbosity_, outputStyle_, outputFreq_;
312  bool showMaxResNormOnly_;
313 
315  std::string label_;
316 
318  Teuchos::RCP<Teuchos::Time> timerSolve_;
319 
321  bool isSet_;
322  };
323 
324 
325 // Default solver values.
326 template<class ScalarType, class MV, class OP>
327 const typename FixedPointSolMgr<ScalarType,MV,OP>::MagnitudeType FixedPointSolMgr<ScalarType,MV,OP>::convtol_default_ = 1e-8;
328 
329 template<class ScalarType, class MV, class OP>
330 const int FixedPointSolMgr<ScalarType,MV,OP>::maxIters_default_ = 1000;
331 
332 template<class ScalarType, class MV, class OP>
333 const bool FixedPointSolMgr<ScalarType,MV,OP>::showMaxResNormOnly_default_ = false;
334 
335 template<class ScalarType, class MV, class OP>
336 const int FixedPointSolMgr<ScalarType,MV,OP>::blockSize_default_ = 1;
337 
338 template<class ScalarType, class MV, class OP>
339 const int FixedPointSolMgr<ScalarType,MV,OP>::verbosity_default_ = Belos::Errors;
340 
341 template<class ScalarType, class MV, class OP>
342 const int FixedPointSolMgr<ScalarType,MV,OP>::outputStyle_default_ = Belos::General;
343 
344 template<class ScalarType, class MV, class OP>
345 const int FixedPointSolMgr<ScalarType,MV,OP>::outputFreq_default_ = -1;
346 
347 template<class ScalarType, class MV, class OP>
348 const std::string FixedPointSolMgr<ScalarType,MV,OP>::label_default_ = "Belos";
349 
350 template<class ScalarType, class MV, class OP>
351 const Teuchos::RCP<std::ostream> FixedPointSolMgr<ScalarType,MV,OP>::outputStream_default_ = Teuchos::rcp(&std::cout,false);
352 
353 
354 // Empty Constructor
355 template<class ScalarType, class MV, class OP>
357  outputStream_(outputStream_default_),
358  convtol_(convtol_default_),
359  achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
360  maxIters_(maxIters_default_),
361  numIters_(0),
362  blockSize_(blockSize_default_),
363  verbosity_(verbosity_default_),
364  outputStyle_(outputStyle_default_),
365  outputFreq_(outputFreq_default_),
366  showMaxResNormOnly_(showMaxResNormOnly_default_),
367  label_(label_default_),
368  isSet_(false)
369 {}
370 
371 
372 // Basic Constructor
373 template<class ScalarType, class MV, class OP>
377  problem_(problem),
378  outputStream_(outputStream_default_),
379  convtol_(convtol_default_),
380  achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
381  maxIters_(maxIters_default_),
382  numIters_(0),
383  blockSize_(blockSize_default_),
384  verbosity_(verbosity_default_),
385  outputStyle_(outputStyle_default_),
386  outputFreq_(outputFreq_default_),
387  showMaxResNormOnly_(showMaxResNormOnly_default_),
388  label_(label_default_),
389  isSet_(false)
390 {
391  TEUCHOS_TEST_FOR_EXCEPTION(problem_.is_null(), std::invalid_argument,
392  "FixedPointSolMgr's constructor requires a nonnull LinearProblem instance.");
393 
394  // If the user passed in a nonnull parameter list, set parameters.
395  // Otherwise, the next solve() call will use default parameters,
396  // unless the user calls setParameters() first.
397  if (! pl.is_null()) {
398  setParameters (pl);
399  }
400 }
401 
402 template<class ScalarType, class MV, class OP>
403 void
406 {
407  // Create the internal parameter list if one doesn't already exist.
408  if (params_ == Teuchos::null) {
409  params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
410  }
411  else {
412  params->validateParameters(*getValidParameters());
413  }
414 
415  // Check for maximum number of iterations
416  if (params->isParameter("Maximum Iterations")) {
417  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
418 
419  // Update parameter in our list and in status test.
420  params_->set("Maximum Iterations", maxIters_);
421  if (maxIterTest_!=Teuchos::null)
422  maxIterTest_->setMaxIters( maxIters_ );
423  }
424 
425  // Check for blocksize
426  if (params->isParameter("Block Size")) {
427  blockSize_ = params->get("Block Size",blockSize_default_);
428  TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
429  "Belos::FixedPointSolMgr: \"Block Size\" must be strictly positive.");
430 
431  // Update parameter in our list.
432  params_->set("Block Size", blockSize_);
433  }
434 
435  // Check to see if the timer label changed.
436  if (params->isParameter("Timer Label")) {
437  std::string tempLabel = params->get("Timer Label", label_default_);
438 
439  // Update parameter in our list and solver timer
440  if (tempLabel != label_) {
441  label_ = tempLabel;
442  params_->set("Timer Label", label_);
443  std::string solveLabel = label_ + ": FixedPointSolMgr total solve time";
444 #ifdef BELOS_TEUCHOS_TIME_MONITOR
445  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
446 #endif
447  }
448  }
449 
450  // Check for a change in verbosity level
451  if (params->isParameter("Verbosity")) {
452  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
453  verbosity_ = params->get("Verbosity", verbosity_default_);
454  } else {
455  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
456  }
457 
458  // Update parameter in our list.
459  params_->set("Verbosity", verbosity_);
460  if (printer_ != Teuchos::null)
461  printer_->setVerbosity(verbosity_);
462  }
463 
464  // Check for a change in output style
465  if (params->isParameter("Output Style")) {
466  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
467  outputStyle_ = params->get("Output Style", outputStyle_default_);
468  } else {
469  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
470  }
471 
472  // Update parameter in our list.
473  params_->set("Output Style", outputStyle_);
474  outputTest_ = Teuchos::null;
475  }
476 
477  // output stream
478  if (params->isParameter("Output Stream")) {
479  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
480 
481  // Update parameter in our list.
482  params_->set("Output Stream", outputStream_);
483  if (printer_ != Teuchos::null)
484  printer_->setOStream( outputStream_ );
485  }
486 
487  // frequency level
488  if (verbosity_ & Belos::StatusTestDetails) {
489  if (params->isParameter("Output Frequency")) {
490  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
491  }
492 
493  // Update parameter in out list and output status test.
494  params_->set("Output Frequency", outputFreq_);
495  if (outputTest_ != Teuchos::null)
496  outputTest_->setOutputFrequency( outputFreq_ );
497  }
498 
499  // Create output manager if we need to.
500  if (printer_ == Teuchos::null) {
501  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
502  }
503 
504  // Convergence
505  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
506  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestResNorm_t;
507 
508  // Check for convergence tolerance
509  if (params->isParameter("Convergence Tolerance")) {
510  convtol_ = params->get("Convergence Tolerance",convtol_default_);
511 
512  // Update parameter in our list and residual tests.
513  params_->set("Convergence Tolerance", convtol_);
514  if (convTest_ != Teuchos::null)
515  convTest_->setTolerance( convtol_ );
516  }
517 
518  if (params->isParameter("Show Maximum Residual Norm Only")) {
519  showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
520 
521  // Update parameter in our list and residual tests
522  params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
523  if (convTest_ != Teuchos::null)
524  convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
525  }
526 
527  // Create status tests if we need to.
528 
529  // Basic test checks maximum iterations and native residual.
530  if (maxIterTest_ == Teuchos::null)
531  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
532 
533  // Implicit residual test, using the native residual to determine if convergence was achieved.
534  if (convTest_ == Teuchos::null)
535  convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, 1 ) );
536 
537  if (sTest_ == Teuchos::null)
538  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
539 
540  if (outputTest_ == Teuchos::null) {
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 = " Fixed Point ";
549  outputTest_->setSolverDesc( solverDesc );
550 
551  }
552 
553  // Create the timer if we need to.
554  if (timerSolve_ == Teuchos::null) {
555  std::string solveLabel = label_ + ": FixedPointSolMgr total solve time";
556 #ifdef BELOS_TEUCHOS_TIME_MONITOR
557  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
558 #endif
559  }
560 
561  // Inform the solver manager that the current parameters were set.
562  isSet_ = true;
563 }
564 
565 
566 template<class ScalarType, class MV, class OP>
569 {
571 
572  // Set all the valid parameters and their default values.
573  if(is_null(validPL)) {
574  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
575  pl->set("Convergence Tolerance", convtol_default_,
576  "The relative residual tolerance that needs to be achieved by the\n"
577  "iterative solver in order for the linear system to be declared converged.");
578  pl->set("Maximum Iterations", maxIters_default_,
579  "The maximum number of block iterations allowed for each\n"
580  "set of RHS solved.");
581  pl->set("Block Size", blockSize_default_,
582  "The number of vectors in each block.");
583  pl->set("Verbosity", verbosity_default_,
584  "What type(s) of solver information should be outputted\n"
585  "to the output stream.");
586  pl->set("Output Style", outputStyle_default_,
587  "What style is used for the solver information outputted\n"
588  "to the output stream.");
589  pl->set("Output Frequency", outputFreq_default_,
590  "How often convergence information should be outputted\n"
591  "to the output stream.");
592  pl->set("Output Stream", outputStream_default_,
593  "A reference-counted pointer to the output stream where all\n"
594  "solver output is sent.");
595  pl->set("Show Maximum Residual Norm Only", showMaxResNormOnly_default_,
596  "When convergence information is printed, only show the maximum\n"
597  "relative residual norm when the block size is greater than one.");
598  pl->set("Timer Label", label_default_,
599  "The string to use as a prefix for the timer labels.");
600  // pl->set("Restart Timers", restartTimers_);
601  validPL = pl;
602  }
603  return validPL;
604 }
605 
606 
607 // solve()
608 template<class ScalarType, class MV, class OP>
610  using Teuchos::RCP;
611  using Teuchos::rcp;
612  using Teuchos::rcp_const_cast;
613  using Teuchos::rcp_dynamic_cast;
614 
615  // Set the current parameters if they were not set before. NOTE:
616  // This may occur if the user generated the solver manager with the
617  // default constructor and then didn't set any parameters using
618  // setParameters().
619  if (!isSet_) {
620  setParameters(Teuchos::parameterList(*getValidParameters()));
621  }
622 
625 
626  TEUCHOS_TEST_FOR_EXCEPTION( !problem_->isProblemSet(),
628  "Belos::FixedPointSolMgr::solve(): Linear problem is not ready, setProblem() "
629  "has not been called.");
630 
631  // Create indices for the linear systems to be solved.
632  int startPtr = 0;
633  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
634  int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
635 
636  std::vector<int> currIdx, currIdx2;
637  currIdx.resize( blockSize_ );
638  currIdx2.resize( blockSize_ );
639  for (int i=0; i<numCurrRHS; ++i)
640  { currIdx[i] = startPtr+i; currIdx2[i]=i; }
641  for (int i=numCurrRHS; i<blockSize_; ++i)
642  { currIdx[i] = -1; currIdx2[i] = i; }
643 
644  // Inform the linear problem of the current linear system to solve.
645  problem_->setLSIndex( currIdx );
646 
648  // Set up the parameter list for the Iteration subclass.
650  plist.set("Block Size",blockSize_);
651 
652  // Reset the output status test (controls all the other status tests).
653  outputTest_->reset();
654 
655  // Assume convergence is achieved, then let any failed convergence
656  // set this to false. "Innocent until proven guilty."
657  bool isConverged = true;
658 
660  // Set up the FixedPoint Iteration subclass.
661 
662  RCP<FixedPointIteration<ScalarType,MV,OP> > block_fp_iter;
663  block_fp_iter = rcp (new FixedPointIter<ScalarType,MV,OP> (problem_, printer_, outputTest_, plist));
664 
665  // Enter solve() iterations
666  {
667 #ifdef BELOS_TEUCHOS_TIME_MONITOR
668  Teuchos::TimeMonitor slvtimer(*timerSolve_);
669 #endif
670 
671  while ( numRHS2Solve > 0 ) {
672  //
673  // Reset the active / converged vectors from this block
674  std::vector<int> convRHSIdx;
675  std::vector<int> currRHSIdx( currIdx );
676  currRHSIdx.resize(numCurrRHS);
677 
678  // Reset the number of iterations.
679  block_fp_iter->resetNumIters();
680 
681  // Reset the number of calls that the status test output knows about.
682  outputTest_->resetNumCalls();
683 
684  // Get the current residual for this block of linear systems.
685  RCP<MV> R_0 = MVT::CloneViewNonConst( *(rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
686 
687  // Set the new state and initialize the solver.
689  newstate.R = R_0;
690  block_fp_iter->initializeFixedPoint(newstate);
691 
692  while(1) {
693 
694  // tell block_fp_iter to iterate
695  try {
696  block_fp_iter->iterate();
697  //
698  // Check whether any of the linear systems converged.
699  //
700  if (convTest_->getStatus() == Passed) {
701  // At least one of the linear system(s) converged.
702  //
703  // Get the column indices of the linear systems that converged.
704  std::vector<int> convIdx = convTest_->convIndices();
705 
706  // If the number of converged linear systems equals the
707  // number of linear systems currently being solved, then
708  // we are done with this block.
709  if (convIdx.size() == currRHSIdx.size())
710  break; // break from while(1){block_fp_iter->iterate()}
711 
712  // Inform the linear problem that we are finished with
713  // this current linear system.
714  problem_->setCurrLS();
715 
716  // Reset currRHSIdx to contain the right-hand sides that
717  // are left to converge for this block.
718  int have = 0;
719  std::vector<int> unconvIdx(currRHSIdx.size());
720  for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
721  bool found = false;
722  for (unsigned int j=0; j<convIdx.size(); ++j) {
723  if (currRHSIdx[i] == convIdx[j]) {
724  found = true;
725  break;
726  }
727  }
728  if (!found) {
729  currIdx2[have] = currIdx2[i];
730  currRHSIdx[have++] = currRHSIdx[i];
731  }
732  else {
733  }
734  }
735  currRHSIdx.resize(have);
736  currIdx2.resize(have);
737 
738  // Set the remaining indices after deflation.
739  problem_->setLSIndex( currRHSIdx );
740 
741  // Get the current residual vector.
742  std::vector<MagnitudeType> norms;
743  R_0 = MVT::CloneCopy( *(block_fp_iter->getNativeResiduals(&norms)),currIdx2 );
744  for (int i=0; i<have; ++i) { currIdx2[i] = i; }
745 
746  // Set the new blocksize for the solver.
747  block_fp_iter->setBlockSize( have );
748 
749  // Set the new state and initialize the solver.
751  defstate.R = R_0;
752  block_fp_iter->initializeFixedPoint(defstate);
753  }
754  //
755  // None of the linear systems converged. Check whether the
756  // maximum iteration count was reached.
757  //
758  else if (maxIterTest_->getStatus() == Passed) {
759  isConverged = false; // None of the linear systems converged.
760  break; // break from while(1){block_fp_iter->iterate()}
761  }
762  //
763  // iterate() returned, but none of our status tests Passed.
764  // This indicates a bug.
765  //
766  else {
767  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
768  "Belos::FixedPointSolMgr::solve(): Neither the convergence test nor "
769  "the maximum iteration count test passed. Please report this bug "
770  "to the Belos developers.");
771  }
772  }
773  catch (const std::exception &e) {
774  std::ostream& err = printer_->stream (Errors);
775  err << "Error! Caught std::exception in FixedPointIteration::iterate() at "
776  << "iteration " << block_fp_iter->getNumIters() << std::endl
777  << e.what() << std::endl;
778  throw;
779  }
780  }
781 
782  // Inform the linear problem that we are finished with this
783  // block linear system.
784  problem_->setCurrLS();
785 
786  // Update indices for the linear systems to be solved.
787  startPtr += numCurrRHS;
788  numRHS2Solve -= numCurrRHS;
789  if ( numRHS2Solve > 0 ) {
790  numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
791 
792 
793  currIdx.resize( blockSize_ );
794  currIdx2.resize( blockSize_ );
795  for (int i=0; i<numCurrRHS; ++i)
796  { currIdx[i] = startPtr+i; currIdx2[i] = i; }
797  for (int i=numCurrRHS; i<blockSize_; ++i)
798  { currIdx[i] = -1; currIdx2[i] = i; }
799 
800  // Set the next indices.
801  problem_->setLSIndex( currIdx );
802 
803  // Set the new blocksize for the solver.
804  block_fp_iter->setBlockSize( blockSize_ );
805  }
806  else {
807  currIdx.resize( numRHS2Solve );
808  }
809 
810  }// while ( numRHS2Solve > 0 )
811 
812  }
813 
814  // print final summary
815  sTest_->print( printer_->stream(FinalSummary) );
816 
817  // print timing information
818 #ifdef BELOS_TEUCHOS_TIME_MONITOR
819  // Calling summarize() requires communication in general, so don't
820  // call it unless the user wants to print out timing details.
821  // summarize() will do all the work even if it's passed a "black
822  // hole" output stream.
823  if (verbosity_ & TimingDetails) {
824  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
825  }
826 #endif
827 
828  // Save the iteration count for this solve.
829  numIters_ = maxIterTest_->getNumIters();
830 
831  // Save the convergence test value ("achieved tolerance") for this solve.
832  {
833  // testValues is nonnull and not persistent.
834  const std::vector<MagnitudeType>* pTestValues = convTest_->getTestValue();
835 
836  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
837  "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
838  "method returned NULL. Please report this bug to the Belos developers.");
839 
840  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
841  "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
842  "method returned a vector of length zero. Please report this bug to the "
843  "Belos developers.");
844 
845  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
846  // achieved tolerances for all vectors in the current solve(), or
847  // just for the vectors from the last deflation?
848  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
849  }
850 
851  if (!isConverged) {
852  return Unconverged; // return from FixedPointSolMgr::solve()
853  }
854  return Converged; // return from FixedPointSolMgr::solve()
855 }
856 
857 // This method requires the solver manager to return a std::string that describes itself.
858 template<class ScalarType, class MV, class OP>
860 {
861  std::ostringstream oss;
862  oss << "Belos::FixedPointSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
863  return oss.str();
864 }
865 
866 } // end Belos namespace
867 
868 #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...
const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
Class which manages the output and verbosity of the Belos solvers.
bool is_null(const boost::shared_ptr< T > &p)
Belos concrete class for performing fixed point iteration iteration.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Get a parameter list containing the current parameters for this object.
FixedPointSolMgr()
Empty constructor for FixedPointSolMgr. This constructor takes no arguments and sets the default valu...
T & get(const std::string &name, T def_value)
Belos concrete class for performing the conjugate-gradient (CG) iteration.
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)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
A factory class for generating StatusTestOutput objects.
An abstract class of StatusTest for stopping criteria using residual norms.
An implementation of StatusTestResNorm using a family of residual norms.
bool isLOADetected() const
Return whether a loss of accuracy was detected by this solver during the most current solve...
Belos::StatusTest class for specifying a maximum number of iterations.
static std::string name()
A factory class for generating StatusTestOutput objects.
bool is_null() const
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
void reset(const ResetType type)
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
A Belos::StatusTest class for specifying a maximum number of iterations.
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:205
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)
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.
ReturnType solve()
This method performs possibly repeated calls to the underlying linear solver&#39;s iterate() routine unti...
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:154
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< const MV > R
The current residual.
int getNumIters() const
Get the iteration count for the most recent call to solve().
FixedPointSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a parameter list containing the valid parameters 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)
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters the solver manager should use to solve the linear problem.
A class for extending the status testing capabilities of Belos via logical combinations.
bool isParameter(const std::string &name) const
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:60
std::string description() const
Method to return description of the block CG solver manager.
Belos header file which uses auto-configuration information to include necessary C++ headers...
This class implements the preconditioned fixed point iteration.
MagnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.

Generated for Belos by doxygen 1.8.14