Belos Version of the Day
Loading...
Searching...
No Matches
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
22
23#include "BelosBiCGStabIter.hpp"
29#ifdef BELOS_TEUCHOS_TIME_MONITOR
30#include "Teuchos_TimeMonitor.hpp"
31#endif
32
49namespace Belos {
50
52
53
63
64 template<class ScalarType, class MV, class OP>
65 class BiCGStabSolMgr : public SolverManager<ScalarType,MV,OP> {
66
67 private:
70 typedef Teuchos::ScalarTraits<ScalarType> SCT;
71 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
72 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
73
74 public:
75
77
78
85
96 const Teuchos::RCP<Teuchos::ParameterList> &pl );
97
99 virtual ~BiCGStabSolMgr() {};
100
102 Teuchos::RCP<SolverManager<ScalarType, MV, OP> > clone () const override {
103 return Teuchos::rcp(new BiCGStabSolMgr<ScalarType,MV,OP>);
104 }
106
108
109
111 return *problem_;
112 }
113
116 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override;
117
120 Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override { return params_; }
121
127 Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
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.
212 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
213
214 // Output manager.
215 Teuchos::RCP<OutputManager<ScalarType> > printer_;
216 Teuchos::RCP<std::ostream> outputStream_;
217
218 // Status test.
219 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
220 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
221 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > convTest_;
222 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
223
224 // Current parameter list.
225 Teuchos::RCP<Teuchos::ParameterList> params_;
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
260template<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
277template<class ScalarType, class MV, class OP>
280 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
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.
304 }
305}
306
307template<class ScalarType, class MV, class OP>
308void BiCGStabSolMgr<ScalarType,MV,OP>::setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params )
309{
310 using Teuchos::ParameterList;
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");
445 }
446
447 // Only update the scaling if it's different.
448 if (resScale_ != tempResScale) {
450 resScale_ = tempResScale;
451
452 // Update parameter in our list and residual tests, using the
453 // given parameter name.
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.
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
522template<class ScalarType, class MV, class OP>
523Teuchos::RCP<const Teuchos::ParameterList>
525{
526 using Teuchos::ParameterList;
527 using Teuchos::parameterList;
528 using Teuchos::RCP;
529
530 if (validParams_.is_null()) {
531 // Set all the valid parameters and their default values.
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
578template<class ScalarType, class MV, class OP>
580{
582
583 // Set the current parameters if they were not set before.
584 // NOTE: This may occur if the user generated the solver manager with the default constructor and
585 // then didn't set any parameters using setParameters().
586 if (! isSet_) {
587 setParameters (params_);
588 }
589
591 (! problem_->isProblemSet (), BiCGStabSolMgrLinearProblemFailure,
592 "Belos::BiCGStabSolMgr::solve: Linear problem is not ready. "
593 "You must call setProblem() on the LinearProblem before you may solve it.");
595 (problem_->isLeftPrec (), std::logic_error, "Belos::BiCGStabSolMgr::solve: "
596 "The left-preconditioned case has not yet been implemented. Please use "
597 "right preconditioning for now. If you need to use left preconditioning, "
598 "please contact the Belos developers. Left preconditioning is more "
599 "interesting in BiCGStab because whether it works depends on the initial "
600 "guess (e.g., an initial guess of all zeros might NOT work).");
601
602 // Create indices for the linear systems to be solved.
603 int startPtr = 0;
604 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
606
607 std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
608 for (int i=0; i<numRHS2Solve; ++i) {
609 currIdx[i] = startPtr+i;
610 currIdx2[i]=i;
611 }
612
613 // Inform the linear problem of the current linear system to solve.
614 problem_->setLSIndex( currIdx );
615
617 // Parameter list (iteration)
618 Teuchos::ParameterList plist;
619
620 // Reset the status test.
621 outputTest_->reset();
622
623 // Assume convergence is achieved, then let any failed convergence set this to false.
624 bool isConverged = true;
625
627 // Pseudo-Block BiCGStab solver
628
629 Teuchos::RCP<BiCGStabIter<ScalarType,MV,OP> > bicgstab_iter
630 = Teuchos::rcp( new BiCGStabIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,plist) );
631
632 // Enter solve() iterations
633 {
634#ifdef BELOS_TEUCHOS_TIME_MONITOR
635 Teuchos::TimeMonitor slvtimer(*timerSolve_);
636#endif
637
638 //bool first_time=true;
639 while ( numRHS2Solve > 0 ) {
640 // Reset the active / converged vectors from this block
641 std::vector<int> convRHSIdx;
642 std::vector<int> currRHSIdx( currIdx );
643 currRHSIdx.resize(numCurrRHS);
644
645 // Reset the number of iterations.
646 bicgstab_iter->resetNumIters();
647
648 // Reset the number of calls that the status test output knows about.
649 outputTest_->resetNumCalls();
650
651 // Get the current residual for this block of linear systems.
652 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
653
654 // Get a new state struct and initialize the solver.
656 newState.R = R_0;
657 bicgstab_iter->initializeBiCGStab(newState);
658
659 while(1) {
660
661 // tell block_gmres_iter to iterate
662 try {
663
664 bicgstab_iter->iterate();
665
667 //
668 // check convergence first
669 //
671 if ( convTest_->getStatus() == Passed ) {
672
673 // Figure out which linear systems converged.
674 std::vector<int> convIdx = Teuchos::rcp_dynamic_cast<StatusTestGenResNorm<ScalarType,MV,OP> >(convTest_)->convIndices();
675
676 // If the number of converged linear systems is equal to the
677 // number of current linear systems, then we are done with this block.
678 if (convIdx.size() == currRHSIdx.size())
679 break; // break from while(1){bicgstab_iter->iterate()}
680
681 // Inform the linear problem that we are finished with this current linear system.
682 problem_->setCurrLS();
683
684 // Reset currRHSIdx to have the right-hand sides that are left to converge for this block.
685 int have = 0;
686 std::vector<int> unconvIdx(currRHSIdx.size());
687 for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
688 bool found = false;
689 for (unsigned int j=0; j<convIdx.size(); ++j) {
690 if (currRHSIdx[i] == convIdx[j]) {
691 found = true;
692 break;
693 }
694 }
695 if (!found) {
698 }
699 }
700 currRHSIdx.resize(have);
701 currIdx2.resize(have);
702
703 // Set the remaining indices after deflation.
704 problem_->setLSIndex( currRHSIdx );
705
706 // Get the current residual vector.
707 std::vector<MagnitudeType> norms;
708 R_0 = MVT::CloneCopy( *(bicgstab_iter->getNativeResiduals(&norms)),currIdx2 );
709 for (int i=0; i<have; ++i) { currIdx2[i] = i; }
710
711 // Set the new state and initialize the solver.
713 defstate.R = R_0;
714 bicgstab_iter->initializeBiCGStab(defstate);
715 }
716
718 //
719 // check for maximum iterations
720 //
722 else if ( maxIterTest_->getStatus() == Passed ) {
723 // we don't have convergence
724 isConverged = false;
726 break; // break from while(1){bicgstab_iter->iterate()}
727 }
728
730 //
731 // we returned from iterate(), but none of our status tests Passed.
732 // breakdown was detected within the solver iteration.
733 //
735
736 else if ( bicgstab_iter->breakdownDetected() ) {
737 // we don't have convergence
738 isConverged = false;
740 printer_->stream(Warnings) <<
741 "Belos::BiCGStabSolMgr::solve(): Warning! Solver has experienced a breakdown!" << std::endl;
742 break; // break from while(1){bicgstab_iter->iterate()}
743 }
744
746 //
747 // we returned from iterate(), but none of our status tests Passed.
748 // something is wrong, and it is probably our fault.
749 //
751
752 else {
754 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
755 "Belos::BiCGStabSolMgr::solve(): Invalid return from BiCGStabIter::iterate().");
756 }
757 }
758 catch (const StatusTestNaNError& e) {
759 // A NaN was detected in the solver. Set the solution to zero and return unconverged.
761 achievedTol_ = MT::one();
762 Teuchos::RCP<MV> X = problem_->getLHS();
763 MVT::MvInit( *X, SCT::zero() );
764 printer_->stream(Warnings) << "Belos::BiCGStabSolMgr::solve(): Warning! NaN has been detected!"
765 << std::endl;
766 return retType;
767 }
768 catch (const std::exception &e) {
770 printer_->stream(Errors) << "Error! Caught std::exception in BiCGStabIter::iterate() at iteration "
771 << bicgstab_iter->getNumIters() << std::endl
772 << e.what() << std::endl;
773 throw;
774 }
775 }
776
777 // Inform the linear problem that we are finished with this block linear system.
778 problem_->setCurrLS();
779
780 // Update indices for the linear systems to be solved.
783
784 if ( numRHS2Solve > 0 ) {
785
787 currIdx.resize( numCurrRHS );
788 currIdx2.resize( numCurrRHS );
789 for (int i=0; i<numCurrRHS; ++i)
790 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
791
792 // Set the next indices.
793 problem_->setLSIndex( currIdx );
794 }
795 else {
796 currIdx.resize( numRHS2Solve );
797 }
798
799 //first_time=false;
800 }// while ( numRHS2Solve > 0 )
801
802 }
803
804 // print final summary
805 sTest_->print( printer_->stream(FinalSummary) );
806
807 // print timing information
808#ifdef BELOS_TEUCHOS_TIME_MONITOR
809 // Calling summarize() can be expensive, so don't call unless the
810 // user wants to print out timing details. summarize() will do all
811 // the work even if it's passed a "black hole" output stream.
812 if (verbosity_ & TimingDetails)
813 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
814#endif
815
816 // get iteration information for this solve
817 numIters_ = maxIterTest_->getNumIters();
818
819
820 // Save the convergence test value ("achieved tolerance") for this
821 // solve.
822 const std::vector<MagnitudeType>* pTestValues = convTest_->getTestValue();
823 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
824
825
826 if (!isConverged ) {
827 return retType; // return from BiCGStabSolMgr::solve()
828 }
829 return Converged; // return from BiCGStabSolMgr::solve()
830}
831
832// This method requires the solver manager to return a std::string that describes itself.
833template<class ScalarType, class MV, class OP>
835{
836 std::ostringstream oss;
837 oss << "Belos::BiCGStabSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
838 oss << "{";
839 oss << "}";
840 return oss.str();
841}
842
843
844
845} // end Belos namespace
846
847#endif /* BELOS_BICGSTAB_SOLMGR_HPP */
Belos concrete class for performing the pseudo-block BiCGStab iteration.
Belos header file which uses auto-configuration information to include necessary C++ headers.
Class which describes the linear problem to be solved by the iterative solver.
Class which manages the output and verbosity of the Belos solvers.
Pure virtual base class which describes the basic interface for a solver manager.
Belos::StatusTest for logically combining several status tests.
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Collection of types and exceptions used within the Belos solvers.
Parent class to all Belos exceptions.
The Belos::BiCGStabSolMgr provides a powerful and fully-featured solver manager over the pseudo-block...
int getNumIters() const override
Get the iteration count for the most recent call to solve().
virtual ~BiCGStabSolMgr()
Destructor.
BiCGStabSolMgr()
Empty constructor for BiCGStabSolMgr. This constructor takes no arguments and sets the default values...
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
std::string description() const override
Method to return description of the block BiCGStab solver manager.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
BiCGStabSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
BiCGStabSolMgrLinearProblemFailure(const std::string &what_arg)
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
@ StatusTestDetails
@ FinalSummary
@ TimingDetails
ReturnType
Whether the Belos solve converged for all linear systems.
@ NaNDetected
@ MaxItersReached
@ NonspecificException
@ InconsistentState
@ BreakdownDetected
@ Undetermined
ScaleType
The type of scaling to use on the residual norm value.
ResetType
How to reset the solver.
Default parameters common to most Belos solvers.
static const double convTol
Default convergence tolerance.

Generated for Belos by doxygen 1.9.8