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

Generated on Thu Jul 21 2016 14:43:57 for Belos by doxygen 1.8.11