Belos Version of the Day
Loading...
Searching...
No Matches
BelosFixedPointSolMgr.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_FIXEDPOINT_SOLMGR_HPP
11#define BELOS_FIXEDPOINT_SOLMGR_HPP
12
17#include "BelosConfigDefs.hpp"
18#include "BelosTypes.hpp"
19
22
23#include "BelosCGIter.hpp"
32#ifdef BELOS_TEUCHOS_TIME_MONITOR
33# include "Teuchos_TimeMonitor.hpp"
34#endif
35#include <algorithm>
36
45namespace Belos {
46
48
49
59
60 template<class ScalarType, class MV, class OP, class DM = DefaultDenseMatrix<int, ScalarType>>
61 class FixedPointSolMgr : public SolverManager<ScalarType,MV,OP,DM> {
62
63 private:
66 typedef Teuchos::ScalarTraits<ScalarType> SCT;
67 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
68 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
69
70 public:
71
73
74
81
100 const Teuchos::RCP<Teuchos::ParameterList> &pl );
101
103 virtual ~FixedPointSolMgr() {};
104
106 Teuchos::RCP<SolverManager<ScalarType, MV, OP, DM> > clone () const override {
107 return Teuchos::rcp(new FixedPointSolMgr<ScalarType,MV,OP,DM>);
108 }
110
112
113
115 return *problem_;
116 }
117
120 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override;
121
124 Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override { return params_; }
125
131 Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
132 return Teuchos::tuple(timerSolve_);
133 }
134
140 MagnitudeType achievedTol() const override {
141 return achievedTol_;
142 }
143
145 int getNumIters() const override {
146 return numIters_;
147 }
148
151 bool isLOADetected() const override { return false; }
153
155
156
158 void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > &problem ) override { problem_ = problem; }
159
161 void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
162
165 {
166 debugStatusTest_ = debugStatusTest;
167 // Force the full status-test tree (including this debug test) to be
168 // rebuilt on the next solve(). FixedPoint builds sTest_/outputTest_ lazily
169 // (guarded by null checks), so we drop them and clear isSet_ to trigger it.
170 sTest_ = Teuchos::null;
171 outputTest_ = Teuchos::null;
172 isSet_ = false;
173 }
174
177 {
178
179 convTest_ = userConvStatusTest;
180
181 typedef Belos::StatusTestCombo<ScalarType,MV,OP,DM> StatusTestCombo_t;
182 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
183
185 outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
186
187 std::string solverDesc = " Fixed Point ";
188 outputTest_->setSolverDesc( solverDesc );
189 }
190
192
194
195
199 void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
201
203
204
222 ReturnType solve() override;
224
227
229 std::string description() const override;
231
232 private:
233
235 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > problem_;
236
238 Teuchos::RCP<OutputManager<ScalarType> > printer_;
240 Teuchos::RCP<std::ostream> outputStream_;
241
246 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > sTest_;
247
249 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP,DM> > maxIterTest_;
250
252 Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP,DM> > convTest_;
253
255 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP,DM> > outputTest_;
256
258 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > debugStatusTest_;
259
261 Teuchos::RCP<Teuchos::ParameterList> params_;
262
263 //
264 // Default solver parameters.
265 //
266 static constexpr int maxIters_default_ = 1000;
267 static constexpr bool showMaxResNormOnly_default_ = false;
268 static constexpr int blockSize_default_ = 1;
269 static constexpr int verbosity_default_ = Belos::Errors;
270 static constexpr int outputStyle_default_ = Belos::General;
271 static constexpr int outputFreq_default_ = -1;
272 static constexpr const char * label_default_ = "Belos";
273
274 //
275 // Current solver parameters and other values.
276 //
277
279 MagnitudeType convtol_;
280
286 MagnitudeType achievedTol_;
287
289 int maxIters_;
290
292 int numIters_;
293
294 int blockSize_, verbosity_, outputStyle_, outputFreq_;
295 bool showMaxResNormOnly_;
296
298 std::string label_;
299
301 Teuchos::RCP<Teuchos::Time> timerSolve_;
302
304 bool isSet_;
305 };
306
307
308// Empty Constructor
309template<class ScalarType, class MV, class OP, class DM>
311 outputStream_(Teuchos::rcpFromRef(std::cout)),
312 convtol_(DefaultSolverParameters::convTol),
313 achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
314 maxIters_(maxIters_default_),
315 numIters_(0),
316 blockSize_(blockSize_default_),
317 verbosity_(verbosity_default_),
318 outputStyle_(outputStyle_default_),
319 outputFreq_(outputFreq_default_),
320 showMaxResNormOnly_(showMaxResNormOnly_default_),
321 label_(label_default_),
322 isSet_(false)
323{}
324
325
326// Basic Constructor
327template<class ScalarType, class MV, class OP, class DM>
330 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
331 problem_(problem),
332 outputStream_(Teuchos::rcpFromRef(std::cout)),
333 convtol_(DefaultSolverParameters::convTol),
334 achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
335 maxIters_(maxIters_default_),
336 numIters_(0),
337 blockSize_(blockSize_default_),
338 verbosity_(verbosity_default_),
339 outputStyle_(outputStyle_default_),
340 outputFreq_(outputFreq_default_),
341 showMaxResNormOnly_(showMaxResNormOnly_default_),
342 label_(label_default_),
343 isSet_(false)
344{
345 TEUCHOS_TEST_FOR_EXCEPTION(problem_.is_null(), std::invalid_argument,
346 "FixedPointSolMgr's constructor requires a nonnull LinearProblem instance.");
347
348 // If the user passed in a nonnull parameter list, set parameters.
349 // Otherwise, the next solve() call will use default parameters,
350 // unless the user calls setParameters() first.
351 if (! pl.is_null()) {
353 }
354}
355
356template<class ScalarType, class MV, class OP, class DM>
357void
359setParameters (const Teuchos::RCP<Teuchos::ParameterList> &params)
360{
361 // Create the internal parameter list if one doesn't already exist.
362 if (params_ == Teuchos::null) {
363 params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
364 }
365 else {
366 params->validateParameters(*getValidParameters());
367 }
368
369 // Check for maximum number of iterations
370 if (params->isParameter("Maximum Iterations")) {
371 maxIters_ = params->get("Maximum Iterations",maxIters_default_);
372
373 // Update parameter in our list and in status test.
374 params_->set("Maximum Iterations", maxIters_);
375 if (maxIterTest_!=Teuchos::null)
376 maxIterTest_->setMaxIters( maxIters_ );
377 }
378
379 // Check for blocksize
380 if (params->isParameter("Block Size")) {
381 blockSize_ = params->get("Block Size",blockSize_default_);
382 TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
383 "Belos::FixedPointSolMgr: \"Block Size\" must be strictly positive.");
384
385 // Update parameter in our list.
386 params_->set("Block Size", blockSize_);
387 }
388
389 // Check to see if the timer label changed.
390 if (params->isParameter("Timer Label")) {
391 std::string tempLabel = params->get("Timer Label", label_default_);
392
393 // Update parameter in our list and solver timer
394 if (tempLabel != label_) {
395 label_ = tempLabel;
396 params_->set("Timer Label", label_);
397 std::string solveLabel = label_ + ": FixedPointSolMgr total solve time";
398#ifdef BELOS_TEUCHOS_TIME_MONITOR
399 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
400#endif
401 }
402 }
403
404 // Check for a change in verbosity level
405 if (params->isParameter("Verbosity")) {
406 if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
407 verbosity_ = params->get("Verbosity", verbosity_default_);
408 } else {
409 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
410 }
411
412 // Update parameter in our list.
413 params_->set("Verbosity", verbosity_);
414 if (printer_ != Teuchos::null)
415 printer_->setVerbosity(verbosity_);
416 }
417
418 // Check for a change in output style
419 if (params->isParameter("Output Style")) {
420 if (Teuchos::isParameterType<int>(*params,"Output Style")) {
421 outputStyle_ = params->get("Output Style", outputStyle_default_);
422 } else {
423 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
424 }
425
426 // Update parameter in our list.
427 params_->set("Output Style", outputStyle_);
428 outputTest_ = Teuchos::null;
429 }
430
431 // output stream
432 if (params->isParameter("Output Stream")) {
433 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
434
435 // Update parameter in our list.
436 params_->set("Output Stream", outputStream_);
437 if (printer_ != Teuchos::null)
438 printer_->setOStream( outputStream_ );
439 }
440
441 // frequency level
442 if (verbosity_ & Belos::StatusTestDetails) {
443 if (params->isParameter("Output Frequency")) {
444 outputFreq_ = params->get("Output Frequency", outputFreq_default_);
445 }
446
447 // Update parameter in out list and output status test.
448 params_->set("Output Frequency", outputFreq_);
449 if (outputTest_ != Teuchos::null)
450 outputTest_->setOutputFrequency( outputFreq_ );
451 }
452
453 // Create output manager if we need to.
454 if (printer_ == Teuchos::null) {
455 printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
456 }
457
458 // Convergence
459 typedef Belos::StatusTestCombo<ScalarType,MV,OP,DM> StatusTestCombo_t;
460 typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP,DM> StatusTestResNorm_t;
461
462 // Check for convergence tolerance
463 if (params->isParameter("Convergence Tolerance")) {
464 if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
465 convtol_ = params->get ("Convergence Tolerance",
466 static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
467 }
468 else {
469 convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
470 }
471
472 // Update parameter in our list and residual tests.
473 params_->set("Convergence Tolerance", convtol_);
474 if (convTest_ != Teuchos::null)
475 convTest_->setTolerance( convtol_ );
476 }
477
478 if (params->isParameter("Show Maximum Residual Norm Only")) {
479 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
480
481 // Update parameter in our list and residual tests
482 params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
483 if (convTest_ != Teuchos::null)
484 convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
485 }
486
487 // Create status tests if we need to.
488
489 // Basic test checks maximum iterations and native residual.
490 if (maxIterTest_ == Teuchos::null)
491 maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP,DM>( maxIters_ ) );
492
493 // Implicit residual test, using the native residual to determine if convergence was achieved.
494 if (convTest_ == Teuchos::null)
495 convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, 1 ) );
496
497 if (sTest_ == Teuchos::null) {
498 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
499
500 // Add a debug status test if one was provided (e.g. a wall-clock time
501 // limit). OR-combining it into the top-level test lets it stop the solve;
502 // the dispatch in solve() treats such a stop as an unconverged
503 // (recoverable) termination.
504 if (Teuchos::nonnull(debugStatusTest_)) {
505 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, sTest_, debugStatusTest_ ) );
506 }
507 }
508
509 if (outputTest_ == Teuchos::null) {
510
511 // Create the status test output class.
512 // This class manages and formats the output from the status test.
514 outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
515
516 // Set the solver string for the output test
517 std::string solverDesc = " Fixed Point ";
518 outputTest_->setSolverDesc( solverDesc );
519
520 }
521
522 // Create the timer if we need to.
523 if (timerSolve_ == Teuchos::null) {
524 std::string solveLabel = label_ + ": FixedPointSolMgr total solve time";
525#ifdef BELOS_TEUCHOS_TIME_MONITOR
526 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
527#endif
528 }
529
530 // Inform the solver manager that the current parameters were set.
531 isSet_ = true;
532}
533
534
535template<class ScalarType, class MV, class OP, class DM>
536Teuchos::RCP<const Teuchos::ParameterList>
538{
539 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
540
541 // Set all the valid parameters and their default values.
542 if(is_null(validPL)) {
543 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
544
545 // The static_cast is to resolve an issue with older clang versions which
546 // would cause the constexpr to link fail. With c++17 the problem is resolved.
547 pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
548 "The relative residual tolerance that needs to be achieved by the\n"
549 "iterative solver in order for the linear system to be declared converged.");
550 pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
551 "The maximum number of block iterations allowed for each\n"
552 "set of RHS solved.");
553 pl->set("Block Size", static_cast<int>(blockSize_default_),
554 "The number of vectors in each block.");
555 pl->set("Verbosity", static_cast<int>(verbosity_default_),
556 "What type(s) of solver information should be outputted\n"
557 "to the output stream.");
558 pl->set("Output Style", static_cast<int>(outputStyle_default_),
559 "What style is used for the solver information outputted\n"
560 "to the output stream.");
561 pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
562 "How often convergence information should be outputted\n"
563 "to the output stream.");
564 pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
565 "A reference-counted pointer to the output stream where all\n"
566 "solver output is sent.");
567 pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
568 "When convergence information is printed, only show the maximum\n"
569 "relative residual norm when the block size is greater than one.");
570 pl->set("Timer Label", static_cast<const char *>(label_default_),
571 "The string to use as a prefix for the timer labels.");
572 validPL = pl;
573 }
574 return validPL;
575}
576
577
578// solve()
579template<class ScalarType, class MV, class OP, class DM>
581 using Teuchos::RCP;
582 using Teuchos::rcp;
583 using Teuchos::rcp_const_cast;
584 using Teuchos::rcp_dynamic_cast;
585
587
588 // Set the current parameters if they were not set before. NOTE:
589 // This may occur if the user generated the solver manager with the
590 // default constructor and then didn't set any parameters using
591 // setParameters().
592 if (!isSet_) {
593 setParameters(Teuchos::parameterList(*getValidParameters()));
594 }
595
596 TEUCHOS_TEST_FOR_EXCEPTION( !problem_->isProblemSet(),
598 "Belos::FixedPointSolMgr::solve(): Linear problem is not ready, setProblem() "
599 "has not been called.");
600
601 // Create indices for the linear systems to be solved.
602 int startPtr = 0;
603 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
604 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
605
606 std::vector<int> currIdx, currIdx2;
607 currIdx.resize( blockSize_ );
608 currIdx2.resize( blockSize_ );
609 for (int i=0; i<numCurrRHS; ++i)
610 { currIdx[i] = startPtr+i; currIdx2[i]=i; }
611 for (int i=numCurrRHS; i<blockSize_; ++i)
612 { currIdx[i] = -1; currIdx2[i] = i; }
613
614 // Inform the linear problem of the current linear system to solve.
615 problem_->setLSIndex( currIdx );
616
618 // Set up the parameter list for the Iteration subclass.
619 Teuchos::ParameterList plist;
620 plist.set("Block Size",blockSize_);
621
622 // Reset the output status test (controls all the other status tests).
623 outputTest_->reset();
624
625 // Assume convergence is achieved, then let any failed convergence
626 // set this to false. "Innocent until proven guilty."
627 bool isConverged = true;
628
630 // Set up the FixedPoint Iteration subclass.
631
633 block_fp_iter = rcp (new FixedPointIter<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 while ( numRHS2Solve > 0 ) {
642 //
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 block_fp_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 RCP<MV> R_0 = MVT::CloneViewNonConst( *(rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
656
657 // Set the new state and initialize the solver.
659 newstate.R = R_0;
660 block_fp_iter->initializeFixedPoint(newstate);
661
662 while(1) {
663
664 // tell block_fp_iter to iterate
665 try {
666 block_fp_iter->iterate();
667 //
668 // Check whether any of the linear systems converged.
669 //
670 if (convTest_->getStatus() == Passed) {
671 // At least one of the linear system(s) converged.
672 //
673 // Get the column indices of the linear systems that converged.
674 std::vector<int> convIdx = convTest_->convIndices();
675
676 // If the number of converged linear systems equals the
677 // number of linear systems currently being solved, then
678 // we are done with this block.
679 if (convIdx.size() == currRHSIdx.size())
680 break; // break from while(1){block_fp_iter->iterate()}
681
682 // Inform the linear problem that we are finished with
683 // this current linear system.
684 problem_->setCurrLS();
685
686 // Reset currRHSIdx to contain the right-hand sides that
687 // 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 else {
703 }
704 }
705 currRHSIdx.resize(have);
706 currIdx2.resize(have);
707
708 // Set the remaining indices after deflation.
709 problem_->setLSIndex( currRHSIdx );
710
711 // Get the current residual vector.
712 std::vector<MagnitudeType> norms;
713 R_0 = MVT::CloneCopy( *(block_fp_iter->getNativeResiduals(&norms)),currIdx2 );
714 for (int i=0; i<have; ++i) { currIdx2[i] = i; }
715
716 // Set the new blocksize for the solver.
717 block_fp_iter->setBlockSize( have );
718
719 // Set the new state and initialize the solver.
721 defstate.R = R_0;
722 block_fp_iter->initializeFixedPoint(defstate);
723 }
724 //
725 // None of the linear systems converged. Check whether the
726 // maximum iteration count was reached.
727 //
728 else if (maxIterTest_->getStatus() == Passed) {
730 isConverged = false; // None of the linear systems converged.
731 break; // break from while(1){block_fp_iter->iterate()}
732 }
733 //
734 // iterate() returned, but none of our status tests Passed.
735 // This indicates a bug.
736 //
737 //
738 // A debug status test (e.g. a wall-clock time limit) stopped the
739 // iteration. Treat as an unconverged termination rather than an
740 // inconsistent state.
741 //
742 else if (Teuchos::nonnull(debugStatusTest_) &&
743 debugStatusTest_->getStatus() == Passed) {
745 isConverged = false;
746 break; // break from while(1){block_fp_iter->iterate()}
747 }
748 else {
750 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
751 "Belos::FixedPointSolMgr::solve(): Neither the convergence test nor "
752 "the maximum iteration count test passed. Please report this bug "
753 "to the Belos developers.");
754 }
755 }
756 catch (const StatusTestNaNError& e) {
757 // A NaN was detected in the solver. Set the solution to zero and return unconverged.
759 achievedTol_ = MT::one();
760 Teuchos::RCP<MV> X = problem_->getLHS();
761 MVT::MvInit( *X, SCT::zero() );
762 printer_->stream(Warnings) << "Belos::FixedPointSolMgr::solve(): Warning! NaN has been detected!"
763 << std::endl;
764 return retType;
765 }
766 catch (const std::exception &e) {
768 std::ostream& err = printer_->stream (Errors);
769 err << "Error! Caught std::exception in FixedPointIteration::iterate() at "
770 << "iteration " << block_fp_iter->getNumIters() << std::endl
771 << e.what() << std::endl;
772 throw;
773 }
774 }
775
776 // Inform the linear problem that we are finished with this
777 // block linear system.
778 problem_->setCurrLS();
779
780 // Update indices for the linear systems to be solved.
783 if ( numRHS2Solve > 0 ) {
784 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
785
786
787 currIdx.resize( blockSize_ );
788 currIdx2.resize( blockSize_ );
789 for (int i=0; i<numCurrRHS; ++i)
790 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
791 for (int i=numCurrRHS; i<blockSize_; ++i)
792 { currIdx[i] = -1; currIdx2[i] = i; }
793
794 // Set the next indices.
795 problem_->setLSIndex( currIdx );
796
797 // Set the new blocksize for the solver.
798 block_fp_iter->setBlockSize( blockSize_ );
799 }
800 else {
801 currIdx.resize( numRHS2Solve );
802 }
803
804 }// while ( numRHS2Solve > 0 )
805
806 }
807
808 // print final summary
809 sTest_->print( printer_->stream(FinalSummary) );
810
811 // print timing information
812#ifdef BELOS_TEUCHOS_TIME_MONITOR
813 // Calling summarize() requires communication in general, so don't
814 // call it unless the user wants to print out timing details.
815 // summarize() will do all the work even if it's passed a "black
816 // hole" output stream.
817 if (verbosity_ & TimingDetails) {
818 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
819 }
820#endif
821
822 // Save the iteration count for this solve.
823 numIters_ = maxIterTest_->getNumIters();
824
825 // Save the convergence test value ("achieved tolerance") for this solve.
826 {
827 // testValues is nonnull and not persistent.
828 const std::vector<MagnitudeType>* pTestValues = convTest_->getTestValue();
829
830 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
831 "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
832 "method returned NULL. Please report this bug to the Belos developers.");
833
834 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
835 "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
836 "method returned a vector of length zero. Please report this bug to the "
837 "Belos developers.");
838
839 // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
840 // achieved tolerances for all vectors in the current solve(), or
841 // just for the vectors from the last deflation?
842 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
843 }
844
845 if (!isConverged) {
846 return retType; // return from FixedPointSolMgr::solve()
847 }
848 return Converged; // return from FixedPointSolMgr::solve()
849}
850
851// This method requires the solver manager to return a std::string that describes itself.
852template<class ScalarType, class MV, class OP, class DM>
854{
855 std::ostringstream oss;
856 oss << "Belos::FixedPointSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
857 return oss.str();
858}
859
860} // end Belos namespace
861
862#ifdef HAVE_BELOS_TPETRA
864
865#define BELOS_TPETRA_FIXEDPOINTSOLMGR_NOEXTERN_CALL(SC, LO, GO, NT) \
866 BELOS_TPETRA_CALL(Belos::FixedPointSolMgr, SC, LO, GO, NT)
867
868#define BELOS_TPETRA_FIXEDPOINTSOLMGR_EXTERN_CALL(SC, LO, GO, NT) \
869 BELOS_TPETRA_EXTERN_CALL(Belos::FixedPointSolMgr, SC, LO, GO, NT)
870
871TPETRA_INSTANTIATE_SLGN_NO_ORDINAL_SCALAR(BELOS_TPETRA_FIXEDPOINTSOLMGR_EXTERN_CALL)
872#endif
873
874
875#endif /* BELOS_FIXEDPOINT_SOLMGR_HPP */
Belos concrete class for performing the conjugate-gradient (CG) iteration.
Belos header file which uses auto-configuration information to include necessary C++ headers.
Belos concrete class for performing fixed point iteration iteration.
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::FixedPointSolMgr provides a powerful and fully-featured solver manager over the FixedPoint...
Teuchos::RCP< SolverManager< ScalarType, MV, OP, DM > > clone() const override
clone for Inverted Injection (DII)
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
virtual ~FixedPointSolMgr()
Destructor.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
void replaceUserConvStatusTest(const Teuchos::RCP< StatusTestResNorm< ScalarType, MV, OP, DM > > &userConvStatusTest)
Set user-defined convergence status test.
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::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem) override
Set the linear problem that needs to be solved.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
int getNumIters() const override
Get the iteration count for the most recent call to solve().
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve.
FixedPointSolMgr()
Empty constructor for FixedPointSolMgr. This constructor takes no arguments and sets the default valu...
std::string description() const override
Method to return description of the block CG solver manager.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
FixedPointSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
FixedPointSolMgrLinearProblemFailure(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 ...
@ StatusTestDetails
@ FinalSummary
@ TimingDetails
ReturnType
Whether the Belos solve converged for all linear systems.
@ NaNDetected
@ Unconverged
@ MaxItersReached
@ NonspecificException
@ InconsistentState
@ Undetermined
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