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
32#ifdef BELOS_TEUCHOS_TIME_MONITOR
33#include "Teuchos_TimeMonitor.hpp"
34#endif
35
52namespace Belos {
53
55
56
66
67 template<class ScalarType, class MV, class OP, class DM = DefaultDenseMatrix<int, ScalarType>>
68 class BiCGStabSolMgr : public SolverManager<ScalarType,MV,OP,DM> {
69
70 private:
73 typedef Teuchos::ScalarTraits<ScalarType> SCT;
74 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
75 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
76
77 public:
78
80
81
88
99 const Teuchos::RCP<Teuchos::ParameterList> &pl );
100
102 virtual ~BiCGStabSolMgr() {};
103
105 Teuchos::RCP<SolverManager<ScalarType, MV, OP, DM> > clone () const override {
106 return Teuchos::rcp(new BiCGStabSolMgr<ScalarType,MV,OP,DM>);
107 }
109
111
112
114 return *problem_;
115 }
116
119 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override;
120
123 Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override { return params_; }
124
130 Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
131 return Teuchos::tuple(timerSolve_);
132 }
133
134
145 MagnitudeType achievedTol() const override {
146 return achievedTol_;
147 }
148
150 int getNumIters() const override {
151 return numIters_;
152 }
153
157 bool isLOADetected() const override { return false; }
158
160
162
163
165 void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > &problem ) override { problem_ = problem; }
166
168 void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
169
171
173
174
178 void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
180
182
183
201 ReturnType solve() override;
202
204
207
209 std::string description() const override;
210
212 private:
213
214 // Linear problem.
215 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > problem_;
216
217 // Output manager.
218 Teuchos::RCP<OutputManager<ScalarType> > printer_;
219 Teuchos::RCP<std::ostream> outputStream_;
220
221 // Status test.
222 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > sTest_;
223 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP,DM> > maxIterTest_;
224 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP,DM> > convTest_;
225 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP,DM> > outputTest_;
226
227 // Current parameter list.
228 Teuchos::RCP<Teuchos::ParameterList> params_;
229
235 mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
236
237 // Default solver values.
238 static constexpr int maxIters_default_ = 1000;
239 static constexpr bool showMaxResNormOnly_default_ = false;
240 static constexpr int verbosity_default_ = Belos::Errors;
241 static constexpr int outputStyle_default_ = Belos::General;
242 static constexpr int outputFreq_default_ = -1;
243 static constexpr int defQuorum_default_ = 1;
244 static constexpr const char * resScale_default_ = "Norm of Initial Residual";
245 static constexpr const char * label_default_ = "Belos";
246
247 // Current solver values.
248 MagnitudeType convtol_,achievedTol_;
249 int maxIters_, numIters_;
250 int verbosity_, outputStyle_, outputFreq_, defQuorum_;
251 bool showMaxResNormOnly_;
252 std::string resScale_;
253
254 // Timers.
255 std::string label_;
256 Teuchos::RCP<Teuchos::Time> timerSolve_;
257
258 // Internal state variables.
259 bool isSet_;
260 };
261
262// Empty Constructor
263template<class ScalarType, class MV, class OP, class DM>
265 outputStream_(Teuchos::rcpFromRef(std::cout)),
266 convtol_(DefaultSolverParameters::convTol),
267 maxIters_(maxIters_default_),
268 numIters_(0),
269 verbosity_(verbosity_default_),
270 outputStyle_(outputStyle_default_),
271 outputFreq_(outputFreq_default_),
272 defQuorum_(defQuorum_default_),
273 showMaxResNormOnly_(showMaxResNormOnly_default_),
274 resScale_(resScale_default_),
275 label_(label_default_),
276 isSet_(false)
277{}
278
279// Basic Constructor
280template<class ScalarType, class MV, class OP, class DM>
283 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
284 problem_(problem),
285 outputStream_(Teuchos::rcpFromRef(std::cout)),
286 convtol_(DefaultSolverParameters::convTol),
287 maxIters_(maxIters_default_),
288 numIters_(0),
289 verbosity_(verbosity_default_),
290 outputStyle_(outputStyle_default_),
291 outputFreq_(outputFreq_default_),
292 defQuorum_(defQuorum_default_),
293 showMaxResNormOnly_(showMaxResNormOnly_default_),
294 resScale_(resScale_default_),
295 label_(label_default_),
296 isSet_(false)
297{
299 problem_.is_null (), std::invalid_argument,
300 "Belos::BiCGStabSolMgr two-argument constructor: "
301 "'problem' is null. You must supply a non-null Belos::LinearProblem "
302 "instance when calling this constructor.");
303
304 if (! pl.is_null ()) {
305 // Set the parameters using the list that was passed in.
307 }
308}
309
310template<class ScalarType, class MV, class OP, class DM>
311void BiCGStabSolMgr<ScalarType,MV,OP,DM>::setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params )
312{
313 using Teuchos::ParameterList;
314 using Teuchos::parameterList;
315 using Teuchos::RCP;
316
317 RCP<const ParameterList> defaultParams = getValidParameters();
318
319 // Create the internal parameter list if one doesn't already exist.
320 if (params_.is_null()) {
321 params_ = parameterList (*defaultParams);
322 } else {
323 params->validateParameters (*defaultParams);
324 }
325
326 // Check for maximum number of iterations
327 if (params->isParameter("Maximum Iterations")) {
328 maxIters_ = params->get("Maximum Iterations",maxIters_default_);
329
330 // Update parameter in our list and in status test.
331 params_->set("Maximum Iterations", maxIters_);
332 if (maxIterTest_!=Teuchos::null)
333 maxIterTest_->setMaxIters( maxIters_ );
334 }
335
336 // Check to see if the timer label changed.
337 if (params->isParameter("Timer Label")) {
338 std::string tempLabel = params->get("Timer Label", label_default_);
339
340 // Update parameter in our list and solver timer
341 if (tempLabel != label_) {
342 label_ = tempLabel;
343 params_->set("Timer Label", label_);
344 std::string solveLabel = label_ + ": BiCGStabSolMgr total solve time";
345#ifdef BELOS_TEUCHOS_TIME_MONITOR
346 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
347#endif
348 }
349 }
350
351 // Check for a change in verbosity level
352 if (params->isParameter("Verbosity")) {
353 if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
354 verbosity_ = params->get("Verbosity", verbosity_default_);
355 } else {
356 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
357 }
358
359 // Update parameter in our list.
360 params_->set("Verbosity", verbosity_);
361 if (printer_ != Teuchos::null)
362 printer_->setVerbosity(verbosity_);
363 }
364
365 // Check for a change in output style
366 if (params->isParameter("Output Style")) {
367 if (Teuchos::isParameterType<int>(*params,"Output Style")) {
368 outputStyle_ = params->get("Output Style", outputStyle_default_);
369 } else {
370 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
371 }
372
373 // Reconstruct the convergence test if the explicit residual test is not being used.
374 params_->set("Output Style", outputStyle_);
375 outputTest_ = Teuchos::null;
376 }
377
378 // output stream
379 if (params->isParameter("Output Stream")) {
380 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
381
382 // Update parameter in our list.
383 params_->set("Output Stream", outputStream_);
384 if (printer_ != Teuchos::null)
385 printer_->setOStream( outputStream_ );
386 }
387
388 // frequency level
389 if (verbosity_ & Belos::StatusTestDetails) {
390 if (params->isParameter("Output Frequency")) {
391 outputFreq_ = params->get("Output Frequency", outputFreq_default_);
392 }
393
394 // Update parameter in out list and output status test.
395 params_->set("Output Frequency", outputFreq_);
396 if (outputTest_ != Teuchos::null)
397 outputTest_->setOutputFrequency( outputFreq_ );
398 }
399
400 // Create output manager if we need to.
401 if (printer_ == Teuchos::null) {
402 printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
403 }
404
405 // Convergence
406 typedef Belos::StatusTestCombo<ScalarType,MV,OP,DM> StatusTestCombo_t;
407 typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP,DM> StatusTestResNorm_t;
408
409 // Check for convergence tolerance
410 if (params->isParameter("Convergence Tolerance")) {
411 if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
412 convtol_ = params->get ("Convergence Tolerance",
413 static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
414 }
415 else {
416 convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
417 }
418
419 // Update parameter in our list and residual tests.
420 params_->set("Convergence Tolerance", convtol_);
421 if (convTest_ != Teuchos::null)
422 convTest_->setTolerance( convtol_ );
423 }
424
425 if (params->isParameter("Show Maximum Residual Norm Only")) {
426 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
427
428 // Update parameter in our list and residual tests
429 params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
430 if (convTest_ != Teuchos::null)
431 convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
432 }
433
434 // Check for a change in scaling, if so we need to build new residual tests.
435 bool newResTest = false;
436 {
437 // "Residual Scaling" is the old parameter name; "Implicit
438 // Residual Scaling" is the new name. We support both options for
439 // backwards compatibility.
440 std::string tempResScale = resScale_;
441 bool implicitResidualScalingName = false;
442 if (params->isParameter ("Residual Scaling")) {
443 tempResScale = params->get<std::string> ("Residual Scaling");
444 }
445 else if (params->isParameter ("Implicit Residual Scaling")) {
446 tempResScale = params->get<std::string> ("Implicit Residual Scaling");
448 }
449
450 // Only update the scaling if it's different.
451 if (resScale_ != tempResScale) {
453 resScale_ = tempResScale;
454
455 // Update parameter in our list and residual tests, using the
456 // given parameter name.
458 params_->set ("Implicit Residual Scaling", resScale_);
459 }
460 else {
461 params_->set ("Residual Scaling", resScale_);
462 }
463
464 if (! convTest_.is_null()) {
465 try {
466 convTest_->defineScaleForm( resScaleType, Belos::TwoNorm );
467 }
468 catch (std::exception& e) {
469 // Make sure the convergence test gets constructed again.
470 newResTest = true;
471 }
472 }
473 }
474 }
475
476 // Get the deflation quorum, or number of converged systems before deflation is allowed
477 if (params->isParameter("Deflation Quorum")) {
478 defQuorum_ = params->get("Deflation Quorum", defQuorum_);
479 params_->set("Deflation Quorum", defQuorum_);
480 if (convTest_ != Teuchos::null)
481 convTest_->setQuorum( defQuorum_ );
482 }
483
484 // Create status tests if we need to.
485
486 // Basic test checks maximum iterations and native residual.
487 if (maxIterTest_ == Teuchos::null)
488 maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP,DM>( maxIters_ ) );
489
490 // Implicit residual test, using the native residual to determine if convergence was achieved.
491 if (convTest_ == Teuchos::null || newResTest) {
492 convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, defQuorum_, showMaxResNormOnly_ ) );
493 convTest_->defineScaleForm( convertStringToScaleType( resScale_ ), Belos::TwoNorm );
494 }
495
496 if (sTest_ == Teuchos::null || newResTest)
497 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
498
499 if (outputTest_ == Teuchos::null || newResTest) {
500
501 // Create the status test output class.
502 // This class manages and formats the output from the status test.
504 outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
505
506 // Set the solver string for the output test
507 std::string solverDesc = " Pseudo Block BiCGStab ";
508 outputTest_->setSolverDesc( solverDesc );
509
510 }
511
512 // Create the timer if we need to.
513 if (timerSolve_ == Teuchos::null) {
514 std::string solveLabel = label_ + ": BiCGStabSolMgr total solve time";
515#ifdef BELOS_TEUCHOS_TIME_MONITOR
516 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
517#endif
518 }
519
520 // Inform the solver manager that the current parameters were set.
521 isSet_ = true;
522}
523
524
525template<class ScalarType, class MV, class OP, class DM>
526Teuchos::RCP<const Teuchos::ParameterList>
528{
529 using Teuchos::ParameterList;
530 using Teuchos::parameterList;
531 using Teuchos::RCP;
532
533 if (validParams_.is_null()) {
534 // Set all the valid parameters and their default values.
536
537 // The static_cast is to resolve an issue with older clang versions which
538 // would cause the constexpr to link fail. With c++17 the problem is resolved.
539 pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
540 "The relative residual tolerance that needs to be achieved by the\n"
541 "iterative solver in order for the linera system to be declared converged.");
542 pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
543 "The maximum number of block iterations allowed for each\n"
544 "set of RHS solved.");
545 pl->set("Verbosity", static_cast<int>(verbosity_default_),
546 "What type(s) of solver information should be outputted\n"
547 "to the output stream.");
548 pl->set("Output Style", static_cast<int>(outputStyle_default_),
549 "What style is used for the solver information outputted\n"
550 "to the output stream.");
551 pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
552 "How often convergence information should be outputted\n"
553 "to the output stream.");
554 pl->set("Deflation Quorum", static_cast<int>(defQuorum_default_),
555 "The number of linear systems that need to converge before\n"
556 "they are deflated. This number should be <= block size.");
557 pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
558 "A reference-counted pointer to the output stream where all\n"
559 "solver output is sent.");
560 pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
561 "When convergence information is printed, only show the maximum\n"
562 "relative residual norm when the block size is greater than one.");
563 pl->set("Implicit Residual Scaling", static_cast<const char *>(resScale_default_),
564 "The type of scaling used in the residual convergence test.");
565 // We leave the old name as a valid parameter for backwards
566 // compatibility (so that validateParametersAndSetDefaults()
567 // doesn't raise an exception if it encounters "Residual
568 // Scaling"). The new name was added for compatibility with other
569 // solvers, none of which use "Residual Scaling".
570 pl->set("Residual Scaling", static_cast<const char *>(resScale_default_),
571 "The type of scaling used in the residual convergence test. This "
572 "name is deprecated; the new name is \"Implicit Residual Scaling\".");
573 pl->set("Timer Label", static_cast<const char *>(label_default_),
574 "The string to use as a prefix for the timer labels.");
575 validParams_ = pl;
576 }
577 return validParams_;
578}
579
580
581template<class ScalarType, class MV, class OP, class DM>
583{
585
586 // Set the current parameters if they were not set before.
587 // NOTE: This may occur if the user generated the solver manager with the default constructor and
588 // then didn't set any parameters using setParameters().
589 if (! isSet_) {
590 setParameters (params_);
591 }
592
594 (! problem_->isProblemSet (), BiCGStabSolMgrLinearProblemFailure,
595 "Belos::BiCGStabSolMgr::solve: Linear problem is not ready. "
596 "You must call setProblem() on the LinearProblem before you may solve it.");
598 (problem_->isLeftPrec (), std::logic_error, "Belos::BiCGStabSolMgr::solve: "
599 "The left-preconditioned case has not yet been implemented. Please use "
600 "right preconditioning for now. If you need to use left preconditioning, "
601 "please contact the Belos developers. Left preconditioning is more "
602 "interesting in BiCGStab because whether it works depends on the initial "
603 "guess (e.g., an initial guess of all zeros might NOT work).");
604
605 // Create indices for the linear systems to be solved.
606 int startPtr = 0;
607 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
609
610 std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
611 for (int i=0; i<numRHS2Solve; ++i) {
612 currIdx[i] = startPtr+i;
613 currIdx2[i]=i;
614 }
615
616 // Inform the linear problem of the current linear system to solve.
617 problem_->setLSIndex( currIdx );
618
620 // Parameter list (iteration)
621 Teuchos::ParameterList plist;
622
623 // Reset the status test.
624 outputTest_->reset();
625
626 // Assume convergence is achieved, then let any failed convergence set this to false.
627 bool isConverged = true;
628
630 // Pseudo-Block BiCGStab solver
631
632 Teuchos::RCP<BiCGStabIter<ScalarType,MV,OP,DM> > bicgstab_iter
633 = Teuchos::rcp( new BiCGStabIter<ScalarType,MV,OP,DM>(problem_,printer_,outputTest_,plist) );
634
635 // Enter solve() iterations
636 {
637#ifdef BELOS_TEUCHOS_TIME_MONITOR
638 Teuchos::TimeMonitor slvtimer(*timerSolve_);
639#endif
640
641 //bool first_time=true;
642 while ( numRHS2Solve > 0 ) {
643 // Reset the active / converged vectors from this block
644 std::vector<int> convRHSIdx;
645 std::vector<int> currRHSIdx( currIdx );
646 currRHSIdx.resize(numCurrRHS);
647
648 // Reset the number of iterations.
649 bicgstab_iter->resetNumIters();
650
651 // Reset the number of calls that the status test output knows about.
652 outputTest_->resetNumCalls();
653
654 // Get the current residual for this block of linear systems.
655 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
656
657 // Get a new state struct and initialize the solver.
659 newState.R = R_0;
660 bicgstab_iter->initializeBiCGStab(newState);
661
662 while(1) {
663
664 // tell block_gmres_iter to iterate
665 try {
666
667 bicgstab_iter->iterate();
668
670 //
671 // check convergence first
672 //
674 if ( convTest_->getStatus() == Passed ) {
675
676 // Figure out which linear systems converged.
677 std::vector<int> convIdx = Teuchos::rcp_dynamic_cast<StatusTestGenResNorm<ScalarType,MV,OP,DM> >(convTest_)->convIndices();
678
679 // If the number of converged linear systems is equal to the
680 // number of current linear systems, then we are done with this block.
681 if (convIdx.size() == currRHSIdx.size())
682 break; // break from while(1){bicgstab_iter->iterate()}
683
684 // Inform the linear problem that we are finished with this current linear system.
685 problem_->setCurrLS();
686
687 // Reset currRHSIdx to have the right-hand sides that are left to converge for this block.
688 int have = 0;
689 std::vector<int> unconvIdx(currRHSIdx.size());
690 for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
691 bool found = false;
692 for (unsigned int j=0; j<convIdx.size(); ++j) {
693 if (currRHSIdx[i] == convIdx[j]) {
694 found = true;
695 break;
696 }
697 }
698 if (!found) {
701 }
702 }
703 currRHSIdx.resize(have);
704 currIdx2.resize(have);
705
706 // Set the remaining indices after deflation.
707 problem_->setLSIndex( currRHSIdx );
708
709 // Get the current residual vector.
710 std::vector<MagnitudeType> norms;
711 R_0 = MVT::CloneCopy( *(bicgstab_iter->getNativeResiduals(&norms)),currIdx2 );
712 for (int i=0; i<have; ++i) { currIdx2[i] = i; }
713
714 // Set the new state and initialize the solver.
716 defstate.R = R_0;
717 bicgstab_iter->initializeBiCGStab(defstate);
718 }
719
721 //
722 // check for maximum iterations
723 //
725 else if ( maxIterTest_->getStatus() == Passed ) {
726 // we don't have convergence
727 isConverged = false;
729 break; // break from while(1){bicgstab_iter->iterate()}
730 }
731
733 //
734 // we returned from iterate(), but none of our status tests Passed.
735 // breakdown was detected within the solver iteration.
736 //
738
739 else if ( bicgstab_iter->breakdownDetected() ) {
740 // we don't have convergence
741 isConverged = false;
743 printer_->stream(Warnings) <<
744 "Belos::BiCGStabSolMgr::solve(): Warning! Solver has experienced a breakdown!" << std::endl;
745 break; // break from while(1){bicgstab_iter->iterate()}
746 }
747
749 //
750 // we returned from iterate(), but none of our status tests Passed.
751 // something is wrong, and it is probably our fault.
752 //
754
755 else {
757 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
758 "Belos::BiCGStabSolMgr::solve(): Invalid return from BiCGStabIter::iterate().");
759 }
760 }
761 catch (const StatusTestNaNError& e) {
762 // A NaN was detected in the solver. Set the solution to zero and return unconverged.
764 achievedTol_ = MT::one();
765 Teuchos::RCP<MV> X = problem_->getLHS();
766 MVT::MvInit( *X, SCT::zero() );
767 printer_->stream(Warnings) << "Belos::BiCGStabSolMgr::solve(): Warning! NaN has been detected!"
768 << std::endl;
769 return retType;
770 }
771 catch (const std::exception &e) {
773 printer_->stream(Errors) << "Error! Caught std::exception in BiCGStabIter::iterate() at iteration "
774 << bicgstab_iter->getNumIters() << std::endl
775 << e.what() << std::endl;
776 throw;
777 }
778 }
779
780 // Inform the linear problem that we are finished with this block linear system.
781 problem_->setCurrLS();
782
783 // Update indices for the linear systems to be solved.
786
787 if ( numRHS2Solve > 0 ) {
788
790 currIdx.resize( numCurrRHS );
791 currIdx2.resize( numCurrRHS );
792 for (int i=0; i<numCurrRHS; ++i)
793 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
794
795 // Set the next indices.
796 problem_->setLSIndex( currIdx );
797 }
798 else {
799 currIdx.resize( numRHS2Solve );
800 }
801
802 //first_time=false;
803 }// while ( numRHS2Solve > 0 )
804
805 }
806
807 // print final summary
808 sTest_->print( printer_->stream(FinalSummary) );
809
810 // print timing information
811#ifdef BELOS_TEUCHOS_TIME_MONITOR
812 // Calling summarize() can be expensive, so don't call unless the
813 // user wants to print out timing details. summarize() will do all
814 // the work even if it's passed a "black hole" output stream.
815 if (verbosity_ & TimingDetails)
816 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
817#endif
818
819 // get iteration information for this solve
820 numIters_ = maxIterTest_->getNumIters();
821
822
823 // Save the convergence test value ("achieved tolerance") for this
824 // solve.
825 const std::vector<MagnitudeType>* pTestValues = convTest_->getTestValue();
826 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
827
828
829 if (!isConverged ) {
830 return retType; // return from BiCGStabSolMgr::solve()
831 }
832 return Converged; // return from BiCGStabSolMgr::solve()
833}
834
835// This method requires the solver manager to return a std::string that describes itself.
836template<class ScalarType, class MV, class OP, class DM>
838{
839 std::ostringstream oss;
840 oss << "Belos::BiCGStabSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
841 oss << "{";
842 oss << "}";
843 return oss.str();
844}
845
846
847
848} // end Belos namespace
849
850#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.
Full specialization of Belos::DenseMatTraits for Kokkos::DualView with arbitrary scalarType....
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.
Full specialization of Belos::DenseMatTraits for Teuchos::SerialDenseMatrix with ordinal type int and...
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...
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem) override
Set the linear problem that needs to be solved.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Teuchos::RCP< SolverManager< ScalarType, MV, OP, DM > > clone() const override
clone for Inverted Injection (DII)
void reset(const ResetType type) override
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.
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve.
int getNumIters() const override
Get the iteration count for the most recent call to solve().
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
std::string description() const override
Method to return description of the block BiCGStab solver manager.
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
virtual ~BiCGStabSolMgr()
Destructor.
BiCGStabSolMgr()
Empty constructor for BiCGStabSolMgr. This constructor takes no arguments and sets the default values...
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