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
172 debugStatusTest_ = debugStatusTest;
173 // This manager has no dedicated status-test-set flag; the status-test tree
174 // is cached behind a null check. Drop the cached tree (and its output
175 // wrapper) and clear isSet_ so the next solve() rebuilds them and
176 // OR-combines the debug test.
177 sTest_ = Teuchos::null;
178 outputTest_ = Teuchos::null;
179 isSet_ = false;
180 }
181
183
185
186
190 void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
192
194
195
213 ReturnType solve() override;
214
216
219
221 std::string description() const override;
222
224 private:
225
226 // Linear problem.
227 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > problem_;
228
229 // Output manager.
230 Teuchos::RCP<OutputManager<ScalarType> > printer_;
231 Teuchos::RCP<std::ostream> outputStream_;
232
233 // Status test.
234 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > sTest_;
235 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP,DM> > maxIterTest_;
236 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP,DM> > convTest_;
237 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP,DM> > outputTest_;
238 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > debugStatusTest_;
239
240 // Current parameter list.
241 Teuchos::RCP<Teuchos::ParameterList> params_;
242
248 mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
249
250 // Default solver values.
251 static constexpr int maxIters_default_ = 1000;
252 static constexpr bool showMaxResNormOnly_default_ = false;
253 static constexpr int verbosity_default_ = Belos::Errors;
254 static constexpr int outputStyle_default_ = Belos::General;
255 static constexpr int outputFreq_default_ = -1;
256 static constexpr int defQuorum_default_ = 1;
257 static constexpr const char * resScale_default_ = "Norm of Initial Residual";
258 static constexpr const char * label_default_ = "Belos";
259
260 // Current solver values.
261 MagnitudeType convtol_,achievedTol_;
262 int maxIters_, numIters_;
263 int verbosity_, outputStyle_, outputFreq_, defQuorum_;
264 bool showMaxResNormOnly_;
265 std::string resScale_;
266
267 // Timers.
268 std::string label_;
269 Teuchos::RCP<Teuchos::Time> timerSolve_;
270
271 // Internal state variables.
272 bool isSet_;
273 };
274
275// Empty Constructor
276template<class ScalarType, class MV, class OP, class DM>
278 outputStream_(Teuchos::rcpFromRef(std::cout)),
279 convtol_(DefaultSolverParameters::convTol),
280 maxIters_(maxIters_default_),
281 numIters_(0),
282 verbosity_(verbosity_default_),
283 outputStyle_(outputStyle_default_),
284 outputFreq_(outputFreq_default_),
285 defQuorum_(defQuorum_default_),
286 showMaxResNormOnly_(showMaxResNormOnly_default_),
287 resScale_(resScale_default_),
288 label_(label_default_),
289 isSet_(false)
290{}
291
292// Basic Constructor
293template<class ScalarType, class MV, class OP, class DM>
296 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
297 problem_(problem),
298 outputStream_(Teuchos::rcpFromRef(std::cout)),
299 convtol_(DefaultSolverParameters::convTol),
300 maxIters_(maxIters_default_),
301 numIters_(0),
302 verbosity_(verbosity_default_),
303 outputStyle_(outputStyle_default_),
304 outputFreq_(outputFreq_default_),
305 defQuorum_(defQuorum_default_),
306 showMaxResNormOnly_(showMaxResNormOnly_default_),
307 resScale_(resScale_default_),
308 label_(label_default_),
309 isSet_(false)
310{
312 problem_.is_null (), std::invalid_argument,
313 "Belos::BiCGStabSolMgr two-argument constructor: "
314 "'problem' is null. You must supply a non-null Belos::LinearProblem "
315 "instance when calling this constructor.");
316
317 if (! pl.is_null ()) {
318 // Set the parameters using the list that was passed in.
320 }
321}
322
323template<class ScalarType, class MV, class OP, class DM>
324void BiCGStabSolMgr<ScalarType,MV,OP,DM>::setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params )
325{
326 using Teuchos::ParameterList;
327 using Teuchos::parameterList;
328 using Teuchos::RCP;
329
330 RCP<const ParameterList> defaultParams = getValidParameters();
331
332 // Create the internal parameter list if one doesn't already exist.
333 if (params_.is_null()) {
334 params_ = parameterList (*defaultParams);
335 } else {
336 params->validateParameters (*defaultParams);
337 }
338
339 // Check for maximum number of iterations
340 if (params->isParameter("Maximum Iterations")) {
341 maxIters_ = params->get("Maximum Iterations",maxIters_default_);
342
343 // Update parameter in our list and in status test.
344 params_->set("Maximum Iterations", maxIters_);
345 if (maxIterTest_!=Teuchos::null)
346 maxIterTest_->setMaxIters( maxIters_ );
347 }
348
349 // Check to see if the timer label changed.
350 if (params->isParameter("Timer Label")) {
351 std::string tempLabel = params->get("Timer Label", label_default_);
352
353 // Update parameter in our list and solver timer
354 if (tempLabel != label_) {
355 label_ = tempLabel;
356 params_->set("Timer Label", label_);
357 std::string solveLabel = label_ + ": BiCGStabSolMgr total solve time";
358#ifdef BELOS_TEUCHOS_TIME_MONITOR
359 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
360#endif
361 }
362 }
363
364 // Check for a change in verbosity level
365 if (params->isParameter("Verbosity")) {
366 if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
367 verbosity_ = params->get("Verbosity", verbosity_default_);
368 } else {
369 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
370 }
371
372 // Update parameter in our list.
373 params_->set("Verbosity", verbosity_);
374 if (printer_ != Teuchos::null)
375 printer_->setVerbosity(verbosity_);
376 }
377
378 // Check for a change in output style
379 if (params->isParameter("Output Style")) {
380 if (Teuchos::isParameterType<int>(*params,"Output Style")) {
381 outputStyle_ = params->get("Output Style", outputStyle_default_);
382 } else {
383 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
384 }
385
386 // Reconstruct the convergence test if the explicit residual test is not being used.
387 params_->set("Output Style", outputStyle_);
388 outputTest_ = Teuchos::null;
389 }
390
391 // output stream
392 if (params->isParameter("Output Stream")) {
393 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
394
395 // Update parameter in our list.
396 params_->set("Output Stream", outputStream_);
397 if (printer_ != Teuchos::null)
398 printer_->setOStream( outputStream_ );
399 }
400
401 // frequency level
402 if (verbosity_ & Belos::StatusTestDetails) {
403 if (params->isParameter("Output Frequency")) {
404 outputFreq_ = params->get("Output Frequency", outputFreq_default_);
405 }
406
407 // Update parameter in out list and output status test.
408 params_->set("Output Frequency", outputFreq_);
409 if (outputTest_ != Teuchos::null)
410 outputTest_->setOutputFrequency( outputFreq_ );
411 }
412
413 // Create output manager if we need to.
414 if (printer_ == Teuchos::null) {
415 printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
416 }
417
418 // Convergence
419 typedef Belos::StatusTestCombo<ScalarType,MV,OP,DM> StatusTestCombo_t;
420 typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP,DM> StatusTestResNorm_t;
421
422 // Check for convergence tolerance
423 if (params->isParameter("Convergence Tolerance")) {
424 if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
425 convtol_ = params->get ("Convergence Tolerance",
426 static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
427 }
428 else {
429 convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
430 }
431
432 // Update parameter in our list and residual tests.
433 params_->set("Convergence Tolerance", convtol_);
434 if (convTest_ != Teuchos::null)
435 convTest_->setTolerance( convtol_ );
436 }
437
438 if (params->isParameter("Show Maximum Residual Norm Only")) {
439 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
440
441 // Update parameter in our list and residual tests
442 params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
443 if (convTest_ != Teuchos::null)
444 convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
445 }
446
447 // Check for a change in scaling, if so we need to build new residual tests.
448 bool newResTest = false;
449 {
450 // "Residual Scaling" is the old parameter name; "Implicit
451 // Residual Scaling" is the new name. We support both options for
452 // backwards compatibility.
453 std::string tempResScale = resScale_;
454 bool implicitResidualScalingName = false;
455 if (params->isParameter ("Residual Scaling")) {
456 tempResScale = params->get<std::string> ("Residual Scaling");
457 }
458 else if (params->isParameter ("Implicit Residual Scaling")) {
459 tempResScale = params->get<std::string> ("Implicit Residual Scaling");
461 }
462
463 // Only update the scaling if it's different.
464 if (resScale_ != tempResScale) {
466 resScale_ = tempResScale;
467
468 // Update parameter in our list and residual tests, using the
469 // given parameter name.
471 params_->set ("Implicit Residual Scaling", resScale_);
472 }
473 else {
474 params_->set ("Residual Scaling", resScale_);
475 }
476
477 if (! convTest_.is_null()) {
478 try {
479 convTest_->defineScaleForm( resScaleType, Belos::TwoNorm );
480 }
481 catch (std::exception& e) {
482 // Make sure the convergence test gets constructed again.
483 newResTest = true;
484 }
485 }
486 }
487 }
488
489 // Get the deflation quorum, or number of converged systems before deflation is allowed
490 if (params->isParameter("Deflation Quorum")) {
491 defQuorum_ = params->get("Deflation Quorum", defQuorum_);
492 params_->set("Deflation Quorum", defQuorum_);
493 if (convTest_ != Teuchos::null)
494 convTest_->setQuorum( defQuorum_ );
495 }
496
497 // Create status tests if we need to.
498
499 // Basic test checks maximum iterations and native residual.
500 if (maxIterTest_ == Teuchos::null)
501 maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP,DM>( maxIters_ ) );
502
503 // Implicit residual test, using the native residual to determine if convergence was achieved.
504 if (convTest_ == Teuchos::null || newResTest) {
505 convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, defQuorum_, showMaxResNormOnly_ ) );
506 convTest_->defineScaleForm( convertStringToScaleType( resScale_ ), Belos::TwoNorm );
507 }
508
509 if (sTest_ == Teuchos::null || newResTest) {
510 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
511
512 // Add a debug status test if one was provided (e.g. a wall-clock time
513 // limit). OR-combining it into the top-level test lets it stop the solve;
514 // the dispatch in solve() treats such a stop as an unconverged
515 // (recoverable) termination.
516 if (Teuchos::nonnull(debugStatusTest_)) {
517 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, sTest_, debugStatusTest_ ) );
518 }
519 }
520
521 if (outputTest_ == Teuchos::null || newResTest) {
522
523 // Create the status test output class.
524 // This class manages and formats the output from the status test.
526 outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
527
528 // Set the solver string for the output test
529 std::string solverDesc = " Pseudo Block BiCGStab ";
530 outputTest_->setSolverDesc( solverDesc );
531
532 }
533
534 // Create the timer if we need to.
535 if (timerSolve_ == Teuchos::null) {
536 std::string solveLabel = label_ + ": BiCGStabSolMgr total solve time";
537#ifdef BELOS_TEUCHOS_TIME_MONITOR
538 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
539#endif
540 }
541
542 // Inform the solver manager that the current parameters were set.
543 isSet_ = true;
544}
545
546
547template<class ScalarType, class MV, class OP, class DM>
548Teuchos::RCP<const Teuchos::ParameterList>
550{
551 using Teuchos::ParameterList;
552 using Teuchos::parameterList;
553 using Teuchos::RCP;
554
555 if (validParams_.is_null()) {
556 // Set all the valid parameters and their default values.
558
559 // The static_cast is to resolve an issue with older clang versions which
560 // would cause the constexpr to link fail. With c++17 the problem is resolved.
561 pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
562 "The relative residual tolerance that needs to be achieved by the\n"
563 "iterative solver in order for the linera system to be declared converged.");
564 pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
565 "The maximum number of block iterations allowed for each\n"
566 "set of RHS solved.");
567 pl->set("Verbosity", static_cast<int>(verbosity_default_),
568 "What type(s) of solver information should be outputted\n"
569 "to the output stream.");
570 pl->set("Output Style", static_cast<int>(outputStyle_default_),
571 "What style is used for the solver information outputted\n"
572 "to the output stream.");
573 pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
574 "How often convergence information should be outputted\n"
575 "to the output stream.");
576 pl->set("Deflation Quorum", static_cast<int>(defQuorum_default_),
577 "The number of linear systems that need to converge before\n"
578 "they are deflated. This number should be <= block size.");
579 pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
580 "A reference-counted pointer to the output stream where all\n"
581 "solver output is sent.");
582 pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
583 "When convergence information is printed, only show the maximum\n"
584 "relative residual norm when the block size is greater than one.");
585 pl->set("Implicit Residual Scaling", static_cast<const char *>(resScale_default_),
586 "The type of scaling used in the residual convergence test.");
587 // We leave the old name as a valid parameter for backwards
588 // compatibility (so that validateParametersAndSetDefaults()
589 // doesn't raise an exception if it encounters "Residual
590 // Scaling"). The new name was added for compatibility with other
591 // solvers, none of which use "Residual Scaling".
592 pl->set("Residual Scaling", static_cast<const char *>(resScale_default_),
593 "The type of scaling used in the residual convergence test. This "
594 "name is deprecated; the new name is \"Implicit Residual Scaling\".");
595 pl->set("Timer Label", static_cast<const char *>(label_default_),
596 "The string to use as a prefix for the timer labels.");
597 validParams_ = pl;
598 }
599 return validParams_;
600}
601
602
603template<class ScalarType, class MV, class OP, class DM>
605{
607
608 // Set the current parameters if they were not set before.
609 // NOTE: This may occur if the user generated the solver manager with the default constructor and
610 // then didn't set any parameters using setParameters().
611 if (! isSet_) {
612 setParameters (params_);
613 }
614
616 (! problem_->isProblemSet (), BiCGStabSolMgrLinearProblemFailure,
617 "Belos::BiCGStabSolMgr::solve: Linear problem is not ready. "
618 "You must call setProblem() on the LinearProblem before you may solve it.");
620 (problem_->isLeftPrec (), std::logic_error, "Belos::BiCGStabSolMgr::solve: "
621 "The left-preconditioned case has not yet been implemented. Please use "
622 "right preconditioning for now. If you need to use left preconditioning, "
623 "please contact the Belos developers. Left preconditioning is more "
624 "interesting in BiCGStab because whether it works depends on the initial "
625 "guess (e.g., an initial guess of all zeros might NOT work).");
626
627 // Create indices for the linear systems to be solved.
628 int startPtr = 0;
629 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
631
632 std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
633 for (int i=0; i<numRHS2Solve; ++i) {
634 currIdx[i] = startPtr+i;
635 currIdx2[i]=i;
636 }
637
638 // Inform the linear problem of the current linear system to solve.
639 problem_->setLSIndex( currIdx );
640
642 // Parameter list (iteration)
643 Teuchos::ParameterList plist;
644
645 // Reset the status test.
646 outputTest_->reset();
647
648 // Assume convergence is achieved, then let any failed convergence set this to false.
649 bool isConverged = true;
650
652 // Pseudo-Block BiCGStab solver
653
654 Teuchos::RCP<BiCGStabIter<ScalarType,MV,OP,DM> > bicgstab_iter
655 = Teuchos::rcp( new BiCGStabIter<ScalarType,MV,OP,DM>(problem_,printer_,outputTest_,plist) );
656
657 // Enter solve() iterations
658 {
659#ifdef BELOS_TEUCHOS_TIME_MONITOR
660 Teuchos::TimeMonitor slvtimer(*timerSolve_);
661#endif
662
663 //bool first_time=true;
664 while ( numRHS2Solve > 0 ) {
665 // Reset the active / converged vectors from this block
666 std::vector<int> convRHSIdx;
667 std::vector<int> currRHSIdx( currIdx );
668 currRHSIdx.resize(numCurrRHS);
669
670 // Reset the number of iterations.
671 bicgstab_iter->resetNumIters();
672
673 // Reset the number of calls that the status test output knows about.
674 outputTest_->resetNumCalls();
675
676 // Get the current residual for this block of linear systems.
677 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
678
679 // Get a new state struct and initialize the solver.
681 newState.R = R_0;
682 bicgstab_iter->initializeBiCGStab(newState);
683
684 while(1) {
685
686 // tell block_gmres_iter to iterate
687 try {
688
689 bicgstab_iter->iterate();
690
692 //
693 // check convergence first
694 //
696 if ( convTest_->getStatus() == Passed ) {
697
698 // Figure out which linear systems converged.
699 std::vector<int> convIdx = Teuchos::rcp_dynamic_cast<StatusTestGenResNorm<ScalarType,MV,OP,DM> >(convTest_)->convIndices();
700
701 // If the number of converged linear systems is equal to the
702 // number of current linear systems, then we are done with this block.
703 if (convIdx.size() == currRHSIdx.size())
704 break; // break from while(1){bicgstab_iter->iterate()}
705
706 // Inform the linear problem that we are finished with this current linear system.
707 problem_->setCurrLS();
708
709 // Reset currRHSIdx to have the right-hand sides that are left to converge for this block.
710 int have = 0;
711 std::vector<int> unconvIdx(currRHSIdx.size());
712 for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
713 bool found = false;
714 for (unsigned int j=0; j<convIdx.size(); ++j) {
715 if (currRHSIdx[i] == convIdx[j]) {
716 found = true;
717 break;
718 }
719 }
720 if (!found) {
723 }
724 }
725 currRHSIdx.resize(have);
726 currIdx2.resize(have);
727
728 // Set the remaining indices after deflation.
729 problem_->setLSIndex( currRHSIdx );
730
731 // Get the current residual vector.
732 std::vector<MagnitudeType> norms;
733 R_0 = MVT::CloneCopy( *(bicgstab_iter->getNativeResiduals(&norms)),currIdx2 );
734 for (int i=0; i<have; ++i) { currIdx2[i] = i; }
735
736 // Set the new state and initialize the solver.
738 defstate.R = R_0;
739 bicgstab_iter->initializeBiCGStab(defstate);
740 }
741
743 //
744 // check for maximum iterations
745 //
747 else if ( maxIterTest_->getStatus() == Passed ) {
748 // we don't have convergence
749 isConverged = false;
751 break; // break from while(1){bicgstab_iter->iterate()}
752 }
753
755 //
756 // we returned from iterate(), but none of our status tests Passed.
757 // breakdown was detected within the solver iteration.
758 //
760
761 else if ( bicgstab_iter->breakdownDetected() ) {
762 // we don't have convergence
763 isConverged = false;
765 printer_->stream(Warnings) <<
766 "Belos::BiCGStabSolMgr::solve(): Warning! Solver has experienced a breakdown!" << std::endl;
767 break; // break from while(1){bicgstab_iter->iterate()}
768 }
769
771 //
772 // check for a debug status test requesting termination
773 //
774 // A status test installed via setDebugStatusTest() is OR-combined
775 // into sTest_, so it can legitimately stop iterate() (e.g. a
776 // wall-clock time limit). Treat that as an unconverged termination
777 // rather than an inconsistent internal state.
778 //
780 else if (Teuchos::nonnull(debugStatusTest_) &&
781 debugStatusTest_->getStatus() == Passed) {
782 isConverged = false;
784 break; // break from while(1){bicgstab_iter->iterate()}
785 }
786
788 //
789 // we returned from iterate(), but none of our status tests Passed.
790 // something is wrong, and it is probably our fault.
791 //
793
794 else {
796 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
797 "Belos::BiCGStabSolMgr::solve(): Invalid return from BiCGStabIter::iterate().");
798 }
799 }
800 catch (const StatusTestNaNError& e) {
801 // A NaN was detected in the solver. Set the solution to zero and return unconverged.
803 achievedTol_ = MT::one();
804 Teuchos::RCP<MV> X = problem_->getLHS();
805 MVT::MvInit( *X, SCT::zero() );
806 printer_->stream(Warnings) << "Belos::BiCGStabSolMgr::solve(): Warning! NaN has been detected!"
807 << std::endl;
808 return retType;
809 }
810 catch (const std::exception &e) {
812 printer_->stream(Errors) << "Error! Caught std::exception in BiCGStabIter::iterate() at iteration "
813 << bicgstab_iter->getNumIters() << std::endl
814 << e.what() << std::endl;
815 throw;
816 }
817 }
818
819 // Inform the linear problem that we are finished with this block linear system.
820 problem_->setCurrLS();
821
822 // Update indices for the linear systems to be solved.
825
826 if ( numRHS2Solve > 0 ) {
827
829 currIdx.resize( numCurrRHS );
830 currIdx2.resize( numCurrRHS );
831 for (int i=0; i<numCurrRHS; ++i)
832 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
833
834 // Set the next indices.
835 problem_->setLSIndex( currIdx );
836 }
837 else {
838 currIdx.resize( numRHS2Solve );
839 }
840
841 //first_time=false;
842 }// while ( numRHS2Solve > 0 )
843
844 }
845
846 // print final summary
847 sTest_->print( printer_->stream(FinalSummary) );
848
849 // print timing information
850#ifdef BELOS_TEUCHOS_TIME_MONITOR
851 // Calling summarize() can be expensive, so don't call unless the
852 // user wants to print out timing details. summarize() will do all
853 // the work even if it's passed a "black hole" output stream.
854 if (verbosity_ & TimingDetails)
855 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
856#endif
857
858 // get iteration information for this solve
859 numIters_ = maxIterTest_->getNumIters();
860
861
862 // Save the convergence test value ("achieved tolerance") for this
863 // solve.
864 const std::vector<MagnitudeType>* pTestValues = convTest_->getTestValue();
865 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
866
867
868 if (!isConverged ) {
869 return retType; // return from BiCGStabSolMgr::solve()
870 }
871 return Converged; // return from BiCGStabSolMgr::solve()
872}
873
874// This method requires the solver manager to return a std::string that describes itself.
875template<class ScalarType, class MV, class OP, class DM>
877{
878 std::ostringstream oss;
879 oss << "Belos::BiCGStabSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
880 oss << "{";
881 oss << "}";
882 return oss.str();
883}
884
885
886
887} // end Belos namespace
888
889#ifdef HAVE_BELOS_TPETRA
891
892#define BELOS_TPETRA_BICGSTABSOLMGR_NOEXTERN_CALL(SC, LO, GO, NT) \
893 BELOS_TPETRA_CALL(Belos::BiCGStabSolMgr, SC, LO, GO, NT)
894
895#define BELOS_TPETRA_BICGSTABSOLMGR_EXTERN_CALL(SC, LO, GO, NT) \
896 BELOS_TPETRA_EXTERN_CALL(Belos::BiCGStabSolMgr, SC, LO, GO, NT)
897
898TPETRA_INSTANTIATE_SLGN_NO_ORDINAL_SCALAR(BELOS_TPETRA_BICGSTABSOLMGR_EXTERN_CALL)
899#endif
900
901
902#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...
void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > &debugStatusTest) override
Set a debug status test, OR-combined into the top-level status test.
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
@ Unconverged
@ 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