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:
98  typedef Teuchos::ScalarTraits<ScalarType> SCT;
99  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
100  typedef Teuchos::ScalarTraits<MagnitudeType> MT;
101 
102  public:
103 
105 
106 
113 
131  FixedPointSolMgr( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem,
132  const Teuchos::RCP<Teuchos::ParameterList> &pl );
133 
135  virtual ~FixedPointSolMgr() {};
137 
139 
140 
142  return *problem_;
143  }
144 
147  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
148 
151  Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const { return params_; }
152 
158  Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
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 
189  void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params );
190 
192  void replaceUserConvStatusTest( const Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > &userConvStatusTest )
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 
253  Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
254 
256  Teuchos::RCP<OutputManager<ScalarType> > printer_;
258  Teuchos::RCP<std::ostream> outputStream_;
259 
264  Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
265 
267  Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
268 
270  Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > convTest_;
271 
273  Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
274 
276  Teuchos::RCP<Teuchos::ParameterList> params_;
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>
331 
332 template<class ScalarType, class MV, class OP>
334 
335 template<class ScalarType, class MV, class OP>
337 
338 template<class ScalarType, class MV, class OP>
340 
341 template<class ScalarType, class MV, class OP>
343 
344 template<class ScalarType, class MV, class OP>
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>
375 FixedPointSolMgr(const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem,
376  const Teuchos::RCP<Teuchos::ParameterList> &pl) :
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
405 setParameters (const Teuchos::RCP<Teuchos::ParameterList> &params)
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>
567 Teuchos::RCP<const Teuchos::ParameterList>
569 {
570  static Teuchos::RCP<const Teuchos::ParameterList> validPL;
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  validPL = pl;
601  }
602  return validPL;
603 }
604 
605 
606 // solve()
607 template<class ScalarType, class MV, class OP>
609  using Teuchos::RCP;
610  using Teuchos::rcp;
611  using Teuchos::rcp_const_cast;
612  using Teuchos::rcp_dynamic_cast;
613 
614  // Set the current parameters if they were not set before. NOTE:
615  // This may occur if the user generated the solver manager with the
616  // default constructor and then didn't set any parameters using
617  // setParameters().
618  if (!isSet_) {
619  setParameters(Teuchos::parameterList(*getValidParameters()));
620  }
621 
622  Teuchos::BLAS<int,ScalarType> blas;
623  Teuchos::LAPACK<int,ScalarType> lapack;
624 
625  TEUCHOS_TEST_FOR_EXCEPTION( !problem_->isProblemSet(),
627  "Belos::FixedPointSolMgr::solve(): Linear problem is not ready, setProblem() "
628  "has not been called.");
629 
630  // Create indices for the linear systems to be solved.
631  int startPtr = 0;
632  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
633  int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
634 
635  std::vector<int> currIdx, currIdx2;
636  currIdx.resize( blockSize_ );
637  currIdx2.resize( blockSize_ );
638  for (int i=0; i<numCurrRHS; ++i)
639  { currIdx[i] = startPtr+i; currIdx2[i]=i; }
640  for (int i=numCurrRHS; i<blockSize_; ++i)
641  { currIdx[i] = -1; currIdx2[i] = i; }
642 
643  // Inform the linear problem of the current linear system to solve.
644  problem_->setLSIndex( currIdx );
645 
647  // Set up the parameter list for the Iteration subclass.
648  Teuchos::ParameterList plist;
649  plist.set("Block Size",blockSize_);
650 
651  // Reset the output status test (controls all the other status tests).
652  outputTest_->reset();
653 
654  // Assume convergence is achieved, then let any failed convergence
655  // set this to false. "Innocent until proven guilty."
656  bool isConverged = true;
657 
659  // Set up the FixedPoint Iteration subclass.
660 
661  RCP<FixedPointIteration<ScalarType,MV,OP> > block_fp_iter;
662  block_fp_iter = rcp (new FixedPointIter<ScalarType,MV,OP> (problem_, printer_, outputTest_, plist));
663 
664  // Enter solve() iterations
665  {
666 #ifdef BELOS_TEUCHOS_TIME_MONITOR
667  Teuchos::TimeMonitor slvtimer(*timerSolve_);
668 #endif
669 
670  while ( numRHS2Solve > 0 ) {
671  //
672  // Reset the active / converged vectors from this block
673  std::vector<int> convRHSIdx;
674  std::vector<int> currRHSIdx( currIdx );
675  currRHSIdx.resize(numCurrRHS);
676 
677  // Reset the number of iterations.
678  block_fp_iter->resetNumIters();
679 
680  // Reset the number of calls that the status test output knows about.
681  outputTest_->resetNumCalls();
682 
683  // Get the current residual for this block of linear systems.
684  RCP<MV> R_0 = MVT::CloneViewNonConst( *(rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
685 
686  // Set the new state and initialize the solver.
688  newstate.R = R_0;
689  block_fp_iter->initializeFixedPoint(newstate);
690 
691  while(1) {
692 
693  // tell block_fp_iter to iterate
694  try {
695  block_fp_iter->iterate();
696  //
697  // Check whether any of the linear systems converged.
698  //
699  if (convTest_->getStatus() == Passed) {
700  // At least one of the linear system(s) converged.
701  //
702  // Get the column indices of the linear systems that converged.
703  std::vector<int> convIdx = convTest_->convIndices();
704 
705  // If the number of converged linear systems equals the
706  // number of linear systems currently being solved, then
707  // we are done with this block.
708  if (convIdx.size() == currRHSIdx.size())
709  break; // break from while(1){block_fp_iter->iterate()}
710 
711  // Inform the linear problem that we are finished with
712  // this current linear system.
713  problem_->setCurrLS();
714 
715  // Reset currRHSIdx to contain the right-hand sides that
716  // are left to converge for this block.
717  int have = 0;
718  std::vector<int> unconvIdx(currRHSIdx.size());
719  for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
720  bool found = false;
721  for (unsigned int j=0; j<convIdx.size(); ++j) {
722  if (currRHSIdx[i] == convIdx[j]) {
723  found = true;
724  break;
725  }
726  }
727  if (!found) {
728  currIdx2[have] = currIdx2[i];
729  currRHSIdx[have++] = currRHSIdx[i];
730  }
731  else {
732  }
733  }
734  currRHSIdx.resize(have);
735  currIdx2.resize(have);
736 
737  // Set the remaining indices after deflation.
738  problem_->setLSIndex( currRHSIdx );
739 
740  // Get the current residual vector.
741  std::vector<MagnitudeType> norms;
742  R_0 = MVT::CloneCopy( *(block_fp_iter->getNativeResiduals(&norms)),currIdx2 );
743  for (int i=0; i<have; ++i) { currIdx2[i] = i; }
744 
745  // Set the new blocksize for the solver.
746  block_fp_iter->setBlockSize( have );
747 
748  // Set the new state and initialize the solver.
750  defstate.R = R_0;
751  block_fp_iter->initializeFixedPoint(defstate);
752  }
753  //
754  // None of the linear systems converged. Check whether the
755  // maximum iteration count was reached.
756  //
757  else if (maxIterTest_->getStatus() == Passed) {
758  isConverged = false; // None of the linear systems converged.
759  break; // break from while(1){block_fp_iter->iterate()}
760  }
761  //
762  // iterate() returned, but none of our status tests Passed.
763  // This indicates a bug.
764  //
765  else {
766  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
767  "Belos::FixedPointSolMgr::solve(): Neither the convergence test nor "
768  "the maximum iteration count test passed. Please report this bug "
769  "to the Belos developers.");
770  }
771  }
772  catch (const std::exception &e) {
773  std::ostream& err = printer_->stream (Errors);
774  err << "Error! Caught std::exception in FixedPointIteration::iterate() at "
775  << "iteration " << block_fp_iter->getNumIters() << std::endl
776  << e.what() << std::endl;
777  throw;
778  }
779  }
780 
781  // Inform the linear problem that we are finished with this
782  // block linear system.
783  problem_->setCurrLS();
784 
785  // Update indices for the linear systems to be solved.
786  startPtr += numCurrRHS;
787  numRHS2Solve -= numCurrRHS;
788  if ( numRHS2Solve > 0 ) {
789  numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
790 
791 
792  currIdx.resize( blockSize_ );
793  currIdx2.resize( blockSize_ );
794  for (int i=0; i<numCurrRHS; ++i)
795  { currIdx[i] = startPtr+i; currIdx2[i] = i; }
796  for (int i=numCurrRHS; i<blockSize_; ++i)
797  { currIdx[i] = -1; currIdx2[i] = i; }
798 
799  // Set the next indices.
800  problem_->setLSIndex( currIdx );
801 
802  // Set the new blocksize for the solver.
803  block_fp_iter->setBlockSize( blockSize_ );
804  }
805  else {
806  currIdx.resize( numRHS2Solve );
807  }
808 
809  }// while ( numRHS2Solve > 0 )
810 
811  }
812 
813  // print final summary
814  sTest_->print( printer_->stream(FinalSummary) );
815 
816  // print timing information
817 #ifdef BELOS_TEUCHOS_TIME_MONITOR
818  // Calling summarize() requires communication in general, so don't
819  // call it unless the user wants to print out timing details.
820  // summarize() will do all the work even if it's passed a "black
821  // hole" output stream.
822  if (verbosity_ & TimingDetails) {
823  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
824  }
825 #endif
826 
827  // Save the iteration count for this solve.
828  numIters_ = maxIterTest_->getNumIters();
829 
830  // Save the convergence test value ("achieved tolerance") for this solve.
831  {
832  // testValues is nonnull and not persistent.
833  const std::vector<MagnitudeType>* pTestValues = convTest_->getTestValue();
834 
835  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
836  "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
837  "method returned NULL. Please report this bug to the Belos developers.");
838 
839  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
840  "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
841  "method returned a vector of length zero. Please report this bug to the "
842  "Belos developers.");
843 
844  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
845  // achieved tolerances for all vectors in the current solve(), or
846  // just for the vectors from the last deflation?
847  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
848  }
849 
850  if (!isConverged) {
851  return Unconverged; // return from FixedPointSolMgr::solve()
852  }
853  return Converged; // return from FixedPointSolMgr::solve()
854 }
855 
856 // This method requires the solver manager to return a std::string that describes itself.
857 template<class ScalarType, class MV, class OP>
859 {
860  std::ostringstream oss;
861  oss << "Belos::FixedPointSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
862  return oss.str();
863 }
864 
865 } // end Belos namespace
866 
867 #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.
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...
Belos concrete class for performing the conjugate-gradient (CG) iteration.
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 int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
A factory class for generating StatusTestOutput objects.
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...
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.
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:205
Pure virtual base class which describes the basic interface for a solver manager. ...
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...
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
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.
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 on Mon Feb 5 2018 15:01:51 for Belos by doxygen 1.8.13