Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosBiCGStabSolMgr.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Belos: Block Linear Solvers Package
4 //
5 // Copyright 2004-2016 NTESS and the Belos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef BELOS_BICGSTAB_SOLMGR_HPP
11 #define BELOS_BICGSTAB_SOLMGR_HPP
12 
17 #include "BelosConfigDefs.hpp"
18 #include "BelosTypes.hpp"
19 
20 #include "BelosLinearProblem.hpp"
21 #include "BelosSolverManager.hpp"
22 
23 #include "BelosBiCGStabIter.hpp"
26 #include "BelosStatusTestCombo.hpp"
28 #include "BelosOutputManager.hpp"
29 #ifdef BELOS_TEUCHOS_TIME_MONITOR
30 #include "Teuchos_TimeMonitor.hpp"
31 #endif
32 
49 namespace Belos {
50 
52 
53 
61  BiCGStabSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
62  {}};
63 
64  template<class ScalarType, class MV, class OP>
65  class BiCGStabSolMgr : public SolverManager<ScalarType,MV,OP> {
66 
67  private:
71  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
73 
74  public:
75 
77 
78 
85 
97 
99  virtual ~BiCGStabSolMgr() {};
100 
104  }
106 
108 
109 
110  const LinearProblem<ScalarType,MV,OP>& getProblem() const override {
111  return *problem_;
112  }
113 
117 
121 
128  return Teuchos::tuple(timerSolve_);
129  }
130 
131 
142  MagnitudeType achievedTol() const override {
143  return achievedTol_;
144  }
145 
147  int getNumIters() const override {
148  return numIters_;
149  }
150 
154  bool isLOADetected() const override { return false; }
155 
157 
159 
160 
162  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) override { problem_ = problem; }
163 
165  void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
166 
168 
170 
171 
175  void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
177 
179 
180 
198  ReturnType solve() override;
199 
201 
204 
206  std::string description() const override;
207 
209  private:
210 
211  // Linear problem.
213 
214  // Output manager.
216  Teuchos::RCP<std::ostream> outputStream_;
217 
218  // Status test.
223 
224  // Current parameter list.
226 
232  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
233 
234  // Default solver values.
235  static constexpr int maxIters_default_ = 1000;
236  static constexpr bool showMaxResNormOnly_default_ = false;
237  static constexpr int verbosity_default_ = Belos::Errors;
238  static constexpr int outputStyle_default_ = Belos::General;
239  static constexpr int outputFreq_default_ = -1;
240  static constexpr int defQuorum_default_ = 1;
241  static constexpr const char * resScale_default_ = "Norm of Initial Residual";
242  static constexpr const char * label_default_ = "Belos";
243 
244  // Current solver values.
245  MagnitudeType convtol_,achievedTol_;
246  int maxIters_, numIters_;
247  int verbosity_, outputStyle_, outputFreq_, defQuorum_;
248  bool showMaxResNormOnly_;
249  std::string resScale_;
250 
251  // Timers.
252  std::string label_;
253  Teuchos::RCP<Teuchos::Time> timerSolve_;
254 
255  // Internal state variables.
256  bool isSet_;
257  };
258 
259 // Empty Constructor
260 template<class ScalarType, class MV, class OP>
262  outputStream_(Teuchos::rcpFromRef(std::cout)),
263  convtol_(DefaultSolverParameters::convTol),
264  maxIters_(maxIters_default_),
265  numIters_(0),
266  verbosity_(verbosity_default_),
267  outputStyle_(outputStyle_default_),
268  outputFreq_(outputFreq_default_),
269  defQuorum_(defQuorum_default_),
270  showMaxResNormOnly_(showMaxResNormOnly_default_),
271  resScale_(resScale_default_),
272  label_(label_default_),
273  isSet_(false)
274 {}
275 
276 // Basic Constructor
277 template<class ScalarType, class MV, class OP>
281  problem_(problem),
282  outputStream_(Teuchos::rcpFromRef(std::cout)),
283  convtol_(DefaultSolverParameters::convTol),
284  maxIters_(maxIters_default_),
285  numIters_(0),
286  verbosity_(verbosity_default_),
287  outputStyle_(outputStyle_default_),
288  outputFreq_(outputFreq_default_),
289  defQuorum_(defQuorum_default_),
290  showMaxResNormOnly_(showMaxResNormOnly_default_),
291  resScale_(resScale_default_),
292  label_(label_default_),
293  isSet_(false)
294 {
296  problem_.is_null (), std::invalid_argument,
297  "Belos::BiCGStabSolMgr two-argument constructor: "
298  "'problem' is null. You must supply a non-null Belos::LinearProblem "
299  "instance when calling this constructor.");
300 
301  if (! pl.is_null ()) {
302  // Set the parameters using the list that was passed in.
303  setParameters (pl);
304  }
305 }
306 
307 template<class ScalarType, class MV, class OP>
309 {
311  using Teuchos::parameterList;
312  using Teuchos::RCP;
313 
314  RCP<const ParameterList> defaultParams = getValidParameters();
315 
316  // Create the internal parameter list if one doesn't already exist.
317  if (params_.is_null()) {
318  params_ = parameterList (*defaultParams);
319  } else {
320  params->validateParameters (*defaultParams);
321  }
322 
323  // Check for maximum number of iterations
324  if (params->isParameter("Maximum Iterations")) {
325  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
326 
327  // Update parameter in our list and in status test.
328  params_->set("Maximum Iterations", maxIters_);
329  if (maxIterTest_!=Teuchos::null)
330  maxIterTest_->setMaxIters( maxIters_ );
331  }
332 
333  // Check to see if the timer label changed.
334  if (params->isParameter("Timer Label")) {
335  std::string tempLabel = params->get("Timer Label", label_default_);
336 
337  // Update parameter in our list and solver timer
338  if (tempLabel != label_) {
339  label_ = tempLabel;
340  params_->set("Timer Label", label_);
341  std::string solveLabel = label_ + ": BiCGStabSolMgr total solve time";
342 #ifdef BELOS_TEUCHOS_TIME_MONITOR
343  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
344 #endif
345  }
346  }
347 
348  // Check for a change in verbosity level
349  if (params->isParameter("Verbosity")) {
350  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
351  verbosity_ = params->get("Verbosity", verbosity_default_);
352  } else {
353  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
354  }
355 
356  // Update parameter in our list.
357  params_->set("Verbosity", verbosity_);
358  if (printer_ != Teuchos::null)
359  printer_->setVerbosity(verbosity_);
360  }
361 
362  // Check for a change in output style
363  if (params->isParameter("Output Style")) {
364  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
365  outputStyle_ = params->get("Output Style", outputStyle_default_);
366  } else {
367  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
368  }
369 
370  // Reconstruct the convergence test if the explicit residual test is not being used.
371  params_->set("Output Style", outputStyle_);
372  outputTest_ = Teuchos::null;
373  }
374 
375  // output stream
376  if (params->isParameter("Output Stream")) {
377  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
378 
379  // Update parameter in our list.
380  params_->set("Output Stream", outputStream_);
381  if (printer_ != Teuchos::null)
382  printer_->setOStream( outputStream_ );
383  }
384 
385  // frequency level
386  if (verbosity_ & Belos::StatusTestDetails) {
387  if (params->isParameter("Output Frequency")) {
388  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
389  }
390 
391  // Update parameter in out list and output status test.
392  params_->set("Output Frequency", outputFreq_);
393  if (outputTest_ != Teuchos::null)
394  outputTest_->setOutputFrequency( outputFreq_ );
395  }
396 
397  // Create output manager if we need to.
398  if (printer_ == Teuchos::null) {
399  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
400  }
401 
402  // Convergence
403  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
404  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestResNorm_t;
405 
406  // Check for convergence tolerance
407  if (params->isParameter("Convergence Tolerance")) {
408  if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
409  convtol_ = params->get ("Convergence Tolerance",
410  static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
411  }
412  else {
413  convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
414  }
415 
416  // Update parameter in our list and residual tests.
417  params_->set("Convergence Tolerance", convtol_);
418  if (convTest_ != Teuchos::null)
419  convTest_->setTolerance( convtol_ );
420  }
421 
422  if (params->isParameter("Show Maximum Residual Norm Only")) {
423  showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
424 
425  // Update parameter in our list and residual tests
426  params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
427  if (convTest_ != Teuchos::null)
428  convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
429  }
430 
431  // Check for a change in scaling, if so we need to build new residual tests.
432  bool newResTest = false;
433  {
434  // "Residual Scaling" is the old parameter name; "Implicit
435  // Residual Scaling" is the new name. We support both options for
436  // backwards compatibility.
437  std::string tempResScale = resScale_;
438  bool implicitResidualScalingName = false;
439  if (params->isParameter ("Residual Scaling")) {
440  tempResScale = params->get<std::string> ("Residual Scaling");
441  }
442  else if (params->isParameter ("Implicit Residual Scaling")) {
443  tempResScale = params->get<std::string> ("Implicit Residual Scaling");
444  implicitResidualScalingName = true;
445  }
446 
447  // Only update the scaling if it's different.
448  if (resScale_ != tempResScale) {
449  Belos::ScaleType resScaleType = convertStringToScaleType( tempResScale );
450  resScale_ = tempResScale;
451 
452  // Update parameter in our list and residual tests, using the
453  // given parameter name.
454  if (implicitResidualScalingName) {
455  params_->set ("Implicit Residual Scaling", resScale_);
456  }
457  else {
458  params_->set ("Residual Scaling", resScale_);
459  }
460 
461  if (! convTest_.is_null()) {
462  try {
463  convTest_->defineScaleForm( resScaleType, Belos::TwoNorm );
464  }
465  catch (std::exception& e) {
466  // Make sure the convergence test gets constructed again.
467  newResTest = true;
468  }
469  }
470  }
471  }
472 
473  // Get the deflation quorum, or number of converged systems before deflation is allowed
474  if (params->isParameter("Deflation Quorum")) {
475  defQuorum_ = params->get("Deflation Quorum", defQuorum_);
476  params_->set("Deflation Quorum", defQuorum_);
477  if (convTest_ != Teuchos::null)
478  convTest_->setQuorum( defQuorum_ );
479  }
480 
481  // Create status tests if we need to.
482 
483  // Basic test checks maximum iterations and native residual.
484  if (maxIterTest_ == Teuchos::null)
485  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
486 
487  // Implicit residual test, using the native residual to determine if convergence was achieved.
488  if (convTest_ == Teuchos::null || newResTest) {
489  convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, defQuorum_, showMaxResNormOnly_ ) );
490  convTest_->defineScaleForm( convertStringToScaleType( resScale_ ), Belos::TwoNorm );
491  }
492 
493  if (sTest_ == Teuchos::null || newResTest)
494  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
495 
496  if (outputTest_ == Teuchos::null || newResTest) {
497 
498  // Create the status test output class.
499  // This class manages and formats the output from the status test.
500  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
501  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
502 
503  // Set the solver string for the output test
504  std::string solverDesc = " Pseudo Block BiCGStab ";
505  outputTest_->setSolverDesc( solverDesc );
506 
507  }
508 
509  // Create the timer if we need to.
510  if (timerSolve_ == Teuchos::null) {
511  std::string solveLabel = label_ + ": BiCGStabSolMgr total solve time";
512 #ifdef BELOS_TEUCHOS_TIME_MONITOR
513  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
514 #endif
515  }
516 
517  // Inform the solver manager that the current parameters were set.
518  isSet_ = true;
519 }
520 
521 
522 template<class ScalarType, class MV, class OP>
525 {
527  using Teuchos::parameterList;
528  using Teuchos::RCP;
529 
530  if (validParams_.is_null()) {
531  // Set all the valid parameters and their default values.
532  RCP<ParameterList> pl = parameterList ();
533 
534  // The static_cast is to resolve an issue with older clang versions which
535  // would cause the constexpr to link fail. With c++17 the problem is resolved.
536  pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
537  "The relative residual tolerance that needs to be achieved by the\n"
538  "iterative solver in order for the linera system to be declared converged.");
539  pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
540  "The maximum number of block iterations allowed for each\n"
541  "set of RHS solved.");
542  pl->set("Verbosity", static_cast<int>(verbosity_default_),
543  "What type(s) of solver information should be outputted\n"
544  "to the output stream.");
545  pl->set("Output Style", static_cast<int>(outputStyle_default_),
546  "What style is used for the solver information outputted\n"
547  "to the output stream.");
548  pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
549  "How often convergence information should be outputted\n"
550  "to the output stream.");
551  pl->set("Deflation Quorum", static_cast<int>(defQuorum_default_),
552  "The number of linear systems that need to converge before\n"
553  "they are deflated. This number should be <= block size.");
554  pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
555  "A reference-counted pointer to the output stream where all\n"
556  "solver output is sent.");
557  pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
558  "When convergence information is printed, only show the maximum\n"
559  "relative residual norm when the block size is greater than one.");
560  pl->set("Implicit Residual Scaling", static_cast<const char *>(resScale_default_),
561  "The type of scaling used in the residual convergence test.");
562  // We leave the old name as a valid parameter for backwards
563  // compatibility (so that validateParametersAndSetDefaults()
564  // doesn't raise an exception if it encounters "Residual
565  // Scaling"). The new name was added for compatibility with other
566  // solvers, none of which use "Residual Scaling".
567  pl->set("Residual Scaling", static_cast<const char *>(resScale_default_),
568  "The type of scaling used in the residual convergence test. This "
569  "name is deprecated; the new name is \"Implicit Residual Scaling\".");
570  pl->set("Timer Label", static_cast<const char *>(label_default_),
571  "The string to use as a prefix for the timer labels.");
572  validParams_ = pl;
573  }
574  return validParams_;
575 }
576 
577 
578 template<class ScalarType, class MV, class OP>
580 {
581  // Set the current parameters if they were not set before.
582  // NOTE: This may occur if the user generated the solver manager with the default constructor and
583  // then didn't set any parameters using setParameters().
584  if (! isSet_) {
585  setParameters (params_);
586  }
587 
589  (! problem_->isProblemSet (), BiCGStabSolMgrLinearProblemFailure,
590  "Belos::BiCGStabSolMgr::solve: Linear problem is not ready. "
591  "You must call setProblem() on the LinearProblem before you may solve it.");
593  (problem_->isLeftPrec (), std::logic_error, "Belos::BiCGStabSolMgr::solve: "
594  "The left-preconditioned case has not yet been implemented. Please use "
595  "right preconditioning for now. If you need to use left preconditioning, "
596  "please contact the Belos developers. Left preconditioning is more "
597  "interesting in BiCGStab because whether it works depends on the initial "
598  "guess (e.g., an initial guess of all zeros might NOT work).");
599 
600  // Create indices for the linear systems to be solved.
601  int startPtr = 0;
602  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
603  int numCurrRHS = numRHS2Solve;
604 
605  std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
606  for (int i=0; i<numRHS2Solve; ++i) {
607  currIdx[i] = startPtr+i;
608  currIdx2[i]=i;
609  }
610 
611  // Inform the linear problem of the current linear system to solve.
612  problem_->setLSIndex( currIdx );
613 
615  // Parameter list (iteration)
617 
618  // Reset the status test.
619  outputTest_->reset();
620 
621  // Assume convergence is achieved, then let any failed convergence set this to false.
622  bool isConverged = true;
623 
625  // Pseudo-Block BiCGStab solver
626 
628  = Teuchos::rcp( new BiCGStabIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,plist) );
629 
630  // Enter solve() iterations
631  {
632 #ifdef BELOS_TEUCHOS_TIME_MONITOR
633  Teuchos::TimeMonitor slvtimer(*timerSolve_);
634 #endif
635 
636  //bool first_time=true;
637  while ( numRHS2Solve > 0 ) {
638  // Reset the active / converged vectors from this block
639  std::vector<int> convRHSIdx;
640  std::vector<int> currRHSIdx( currIdx );
641  currRHSIdx.resize(numCurrRHS);
642 
643  // Reset the number of iterations.
644  bicgstab_iter->resetNumIters();
645 
646  // Reset the number of calls that the status test output knows about.
647  outputTest_->resetNumCalls();
648 
649  // Get the current residual for this block of linear systems.
650  Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
651 
652  // Get a new state struct and initialize the solver.
654  newState.R = R_0;
655  bicgstab_iter->initializeBiCGStab(newState);
656 
657  while(1) {
658 
659  // tell block_gmres_iter to iterate
660  try {
661 
662  bicgstab_iter->iterate();
663 
665  //
666  // check convergence first
667  //
669  if ( convTest_->getStatus() == Passed ) {
670 
671  // Figure out which linear systems converged.
672  std::vector<int> convIdx = Teuchos::rcp_dynamic_cast<StatusTestGenResNorm<ScalarType,MV,OP> >(convTest_)->convIndices();
673 
674  // If the number of converged linear systems is equal to the
675  // number of current linear systems, then we are done with this block.
676  if (convIdx.size() == currRHSIdx.size())
677  break; // break from while(1){bicgstab_iter->iterate()}
678 
679  // Inform the linear problem that we are finished with this current linear system.
680  problem_->setCurrLS();
681 
682  // Reset currRHSIdx to have the right-hand sides that are left to converge for this block.
683  int have = 0;
684  std::vector<int> unconvIdx(currRHSIdx.size());
685  for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
686  bool found = false;
687  for (unsigned int j=0; j<convIdx.size(); ++j) {
688  if (currRHSIdx[i] == convIdx[j]) {
689  found = true;
690  break;
691  }
692  }
693  if (!found) {
694  currIdx2[have] = currIdx2[i];
695  currRHSIdx[have++] = currRHSIdx[i];
696  }
697  }
698  currRHSIdx.resize(have);
699  currIdx2.resize(have);
700 
701  // Set the remaining indices after deflation.
702  problem_->setLSIndex( currRHSIdx );
703 
704  // Get the current residual vector.
705  std::vector<MagnitudeType> norms;
706  R_0 = MVT::CloneCopy( *(bicgstab_iter->getNativeResiduals(&norms)),currIdx2 );
707  for (int i=0; i<have; ++i) { currIdx2[i] = i; }
708 
709  // Set the new state and initialize the solver.
711  defstate.R = R_0;
712  bicgstab_iter->initializeBiCGStab(defstate);
713  }
714 
716  //
717  // check for maximum iterations
718  //
720  else if ( maxIterTest_->getStatus() == Passed ) {
721  // we don't have convergence
722  isConverged = false;
723  break; // break from while(1){bicgstab_iter->iterate()}
724  }
725 
727  //
728  // we returned from iterate(), but none of our status tests Passed.
729  // breakdown was detected within the solver iteration.
730  //
732 
733  else if ( bicgstab_iter->breakdownDetected() ) {
734  // we don't have convergence
735  isConverged = false;
736  printer_->stream(Warnings) <<
737  "Belos::BiCGStabSolMgr::solve(): Warning! Solver has experienced a breakdown!" << std::endl;
738  break; // break from while(1){bicgstab_iter->iterate()}
739  }
740 
742  //
743  // we returned from iterate(), but none of our status tests Passed.
744  // something is wrong, and it is probably our fault.
745  //
747 
748  else {
749  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
750  "Belos::BiCGStabSolMgr::solve(): Invalid return from BiCGStabIter::iterate().");
751  }
752  }
753  catch (const StatusTestNaNError& e) {
754  // A NaN was detected in the solver. Set the solution to zero and return unconverged.
755  achievedTol_ = MT::one();
756  Teuchos::RCP<MV> X = problem_->getLHS();
757  MVT::MvInit( *X, SCT::zero() );
758  printer_->stream(Warnings) << "Belos::BiCGStabSolMgr::solve(): Warning! NaN has been detected!"
759  << std::endl;
760  return Unconverged;
761  }
762  catch (const std::exception &e) {
763  printer_->stream(Errors) << "Error! Caught std::exception in BiCGStabIter::iterate() at iteration "
764  << bicgstab_iter->getNumIters() << std::endl
765  << e.what() << std::endl;
766  throw;
767  }
768  }
769 
770  // Inform the linear problem that we are finished with this block linear system.
771  problem_->setCurrLS();
772 
773  // Update indices for the linear systems to be solved.
774  startPtr += numCurrRHS;
775  numRHS2Solve -= numCurrRHS;
776 
777  if ( numRHS2Solve > 0 ) {
778 
779  numCurrRHS = numRHS2Solve;
780  currIdx.resize( numCurrRHS );
781  currIdx2.resize( numCurrRHS );
782  for (int i=0; i<numCurrRHS; ++i)
783  { currIdx[i] = startPtr+i; currIdx2[i] = i; }
784 
785  // Set the next indices.
786  problem_->setLSIndex( currIdx );
787  }
788  else {
789  currIdx.resize( numRHS2Solve );
790  }
791 
792  //first_time=false;
793  }// while ( numRHS2Solve > 0 )
794 
795  }
796 
797  // print final summary
798  sTest_->print( printer_->stream(FinalSummary) );
799 
800  // print timing information
801 #ifdef BELOS_TEUCHOS_TIME_MONITOR
802  // Calling summarize() can be expensive, so don't call unless the
803  // user wants to print out timing details. summarize() will do all
804  // the work even if it's passed a "black hole" output stream.
805  if (verbosity_ & TimingDetails)
806  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
807 #endif
808 
809  // get iteration information for this solve
810  numIters_ = maxIterTest_->getNumIters();
811 
812 
813  // Save the convergence test value ("achieved tolerance") for this
814  // solve.
815  const std::vector<MagnitudeType>* pTestValues = convTest_->getTestValue();
816  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
817 
818 
819  if (!isConverged ) {
820  return Unconverged; // return from BiCGStabSolMgr::solve()
821  }
822  return Converged; // return from BiCGStabSolMgr::solve()
823 }
824 
825 // This method requires the solver manager to return a std::string that describes itself.
826 template<class ScalarType, class MV, class OP>
828 {
829  std::ostringstream oss;
830  oss << "Belos::BiCGStabSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
831  oss << "{";
832  oss << "}";
833  return oss.str();
834 }
835 
836 
837 
838 } // end Belos namespace
839 
840 #endif /* BELOS_BICGSTAB_SOLMGR_HPP */
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:74
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...
This class implements the pseudo-block BiCGStab iteration, where the basic BiCGStab algorithm is perf...
Class which manages the output and verbosity of the Belos solvers.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
Teuchos::RCP< const MV > R
The current residual.
ScaleType
The type of scaling to use on the residual norm value.
Definition: BelosTypes.hpp:88
T & get(const std::string &name, T def_value)
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.
Structure to contain pointers to BiCGStabIteration state variables.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
An implementation of StatusTestResNorm using a family of residual norms.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
static const double convTol
Default convergence tolerance.
Definition: BelosTypes.hpp:261
Belos::StatusTest class for specifying a maximum number of iterations.
static std::string name()
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
A factory class for generating StatusTestOutput objects.
Traits class which defines basic operations on multivectors.
Belos::StatusTest for logically combining several status tests.
BiCGStabSolMgrLinearProblemFailure(const std::string &what_arg)
bool isParameter(const std::string &name) const
A Belos::StatusTest class for specifying a maximum number of iterations.
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:174
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)
BiCGStabSolMgr()
Empty constructor for BiCGStabSolMgr. This constructor takes no arguments and sets the default values...
virtual ~BiCGStabSolMgr()
Destructor.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
BiCGStabSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i...
ReturnType solve() override
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:123
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
The Belos::BiCGStabSolMgr provides a powerful and fully-featured solver manager over the pseudo-block...
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.
std::string description() const override
Method to return description of the block BiCGStab solver manager.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
bool isType(const std::string &name) const
A class for extending the status testing capabilities of Belos via logical combinations.
Class which defines basic traits for the operator type.
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:28
int getNumIters() const override
Get the iteration count for the most recent call to solve().
Default parameters common to most Belos solvers.
Definition: BelosTypes.hpp:251
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve...
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
Belos concrete class for performing the pseudo-block BiCGStab iteration.
bool is_null() const

Generated on Fri Nov 22 2024 09:23:06 for Belos by doxygen 1.8.5