Belos Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
BelosFixedPointSolMgr.hpp
Go to the documentation of this file.
1//@HEADER
2// ************************************************************************
3//
4// Belos: Block Linear Solvers Package
5// Copyright 2004 Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ************************************************************************
40//@HEADER
41
42#ifndef BELOS_FIXEDPOINT_SOLMGR_HPP
43#define BELOS_FIXEDPOINT_SOLMGR_HPP
44
49#include "BelosConfigDefs.hpp"
50#include "BelosTypes.hpp"
51
54
55#include "BelosCGIter.hpp"
62#ifdef BELOS_TEUCHOS_TIME_MONITOR
63# include "Teuchos_TimeMonitor.hpp"
64#endif
65#include <algorithm>
66
75namespace Belos {
76
78
79
87 FixedPointSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
88 {}};
89
90 template<class ScalarType, class MV, class OP>
91 class FixedPointSolMgr : public SolverManager<ScalarType,MV,OP> {
92
93 private:
96 typedef Teuchos::ScalarTraits<ScalarType> SCT;
97 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
98 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
99
100 public:
101
103
104
111
129 FixedPointSolMgr( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem,
130 const Teuchos::RCP<Teuchos::ParameterList> &pl );
131
133 virtual ~FixedPointSolMgr() {};
134
136 Teuchos::RCP<SolverManager<ScalarType, MV, OP> > clone () const override {
137 return Teuchos::rcp(new FixedPointSolMgr<ScalarType,MV,OP>);
138 }
140
142
143
145 return *problem_;
146 }
147
150 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override;
151
154 Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override { return params_; }
155
161 Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
162 return Teuchos::tuple(timerSolve_);
163 }
164
170 MagnitudeType achievedTol() const override {
171 return achievedTol_;
172 }
173
175 int getNumIters() const override {
176 return numIters_;
177 }
178
181 bool isLOADetected() const override { return false; }
183
185
186
188 void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) override { problem_ = problem; }
189
191 void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
192
194 void replaceUserConvStatusTest( const Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > &userConvStatusTest )
195 {
196
197 convTest_ = userConvStatusTest;
198
199 typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
200 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
201
204
205 std::string solverDesc = " Fixed Point ";
206 outputTest_->setSolverDesc( solverDesc );
207 }
208
210
212
213
217 void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
219
221
222
240 ReturnType solve() override;
242
245
247 std::string description() const override;
249
250 private:
251
253 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
254
256 Teuchos::RCP<OutputManager<ScalarType> > printer_;
258 Teuchos::RCP<std::ostream> outputStream_;
259
264 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
265
267 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
268
270 Teuchos::RCP<StatusTestResNorm<ScalarType,MV,OP> > convTest_;
271
273 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
274
276 Teuchos::RCP<Teuchos::ParameterList> params_;
277
278 //
279 // Default solver parameters.
280 //
281 static constexpr int maxIters_default_ = 1000;
282 static constexpr bool showMaxResNormOnly_default_ = false;
283 static constexpr int blockSize_default_ = 1;
284 static constexpr int verbosity_default_ = Belos::Errors;
285 static constexpr int outputStyle_default_ = Belos::General;
286 static constexpr int outputFreq_default_ = -1;
287 static constexpr const char * label_default_ = "Belos";
288
289 //
290 // Current solver parameters and other values.
291 //
292
295
302
305
308
311
313 std::string label_;
314
316 Teuchos::RCP<Teuchos::Time> timerSolve_;
317
319 bool isSet_;
320 };
321
322
323// Empty Constructor
324template<class ScalarType, class MV, class OP>
326 outputStream_(Teuchos::rcpFromRef(std::cout)),
327 convtol_(DefaultSolverParameters::convTol),
328 achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
329 maxIters_(maxIters_default_),
330 numIters_(0),
331 blockSize_(blockSize_default_),
332 verbosity_(verbosity_default_),
333 outputStyle_(outputStyle_default_),
334 outputFreq_(outputFreq_default_),
335 showMaxResNormOnly_(showMaxResNormOnly_default_),
336 label_(label_default_),
337 isSet_(false)
338{}
339
340
341// Basic Constructor
342template<class ScalarType, class MV, class OP>
344FixedPointSolMgr(const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem,
345 const Teuchos::RCP<Teuchos::ParameterList> &pl) :
346 problem_(problem),
347 outputStream_(Teuchos::rcpFromRef(std::cout)),
348 convtol_(DefaultSolverParameters::convTol),
349 achievedTol_(Teuchos::ScalarTraits<MagnitudeType>::zero()),
350 maxIters_(maxIters_default_),
351 numIters_(0),
352 blockSize_(blockSize_default_),
353 verbosity_(verbosity_default_),
354 outputStyle_(outputStyle_default_),
355 outputFreq_(outputFreq_default_),
356 showMaxResNormOnly_(showMaxResNormOnly_default_),
357 label_(label_default_),
358 isSet_(false)
359{
360 TEUCHOS_TEST_FOR_EXCEPTION(problem_.is_null(), std::invalid_argument,
361 "FixedPointSolMgr's constructor requires a nonnull LinearProblem instance.");
362
363 // If the user passed in a nonnull parameter list, set parameters.
364 // Otherwise, the next solve() call will use default parameters,
365 // unless the user calls setParameters() first.
366 if (! pl.is_null()) {
367 setParameters (pl);
368 }
369}
370
371template<class ScalarType, class MV, class OP>
372void
374setParameters (const Teuchos::RCP<Teuchos::ParameterList> &params)
375{
376 // Create the internal parameter list if one doesn't already exist.
377 if (params_ == Teuchos::null) {
378 params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
379 }
380 else {
381 params->validateParameters(*getValidParameters());
382 }
383
384 // Check for maximum number of iterations
385 if (params->isParameter("Maximum Iterations")) {
386 maxIters_ = params->get("Maximum Iterations",maxIters_default_);
387
388 // Update parameter in our list and in status test.
389 params_->set("Maximum Iterations", maxIters_);
390 if (maxIterTest_!=Teuchos::null)
391 maxIterTest_->setMaxIters( maxIters_ );
392 }
393
394 // Check for blocksize
395 if (params->isParameter("Block Size")) {
396 blockSize_ = params->get("Block Size",blockSize_default_);
397 TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ <= 0, std::invalid_argument,
398 "Belos::FixedPointSolMgr: \"Block Size\" must be strictly positive.");
399
400 // Update parameter in our list.
401 params_->set("Block Size", blockSize_);
402 }
403
404 // Check to see if the timer label changed.
405 if (params->isParameter("Timer Label")) {
406 std::string tempLabel = params->get("Timer Label", label_default_);
407
408 // Update parameter in our list and solver timer
409 if (tempLabel != label_) {
410 label_ = tempLabel;
411 params_->set("Timer Label", label_);
412 std::string solveLabel = label_ + ": FixedPointSolMgr total solve time";
413#ifdef BELOS_TEUCHOS_TIME_MONITOR
414 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
415#endif
416 }
417 }
418
419 // Check for a change in verbosity level
420 if (params->isParameter("Verbosity")) {
421 if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
422 verbosity_ = params->get("Verbosity", verbosity_default_);
423 } else {
424 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
425 }
426
427 // Update parameter in our list.
428 params_->set("Verbosity", verbosity_);
429 if (printer_ != Teuchos::null)
430 printer_->setVerbosity(verbosity_);
431 }
432
433 // Check for a change in output style
434 if (params->isParameter("Output Style")) {
435 if (Teuchos::isParameterType<int>(*params,"Output Style")) {
436 outputStyle_ = params->get("Output Style", outputStyle_default_);
437 } else {
438 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
439 }
440
441 // Update parameter in our list.
442 params_->set("Output Style", outputStyle_);
443 outputTest_ = Teuchos::null;
444 }
445
446 // output stream
447 if (params->isParameter("Output Stream")) {
448 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
449
450 // Update parameter in our list.
451 params_->set("Output Stream", outputStream_);
452 if (printer_ != Teuchos::null)
453 printer_->setOStream( outputStream_ );
454 }
455
456 // frequency level
457 if (verbosity_ & Belos::StatusTestDetails) {
458 if (params->isParameter("Output Frequency")) {
459 outputFreq_ = params->get("Output Frequency", outputFreq_default_);
460 }
461
462 // Update parameter in out list and output status test.
463 params_->set("Output Frequency", outputFreq_);
464 if (outputTest_ != Teuchos::null)
465 outputTest_->setOutputFrequency( outputFreq_ );
466 }
467
468 // Create output manager if we need to.
469 if (printer_ == Teuchos::null) {
470 printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
471 }
472
473 // Convergence
474 typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
475 typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestResNorm_t;
476
477 // Check for convergence tolerance
478 if (params->isParameter("Convergence Tolerance")) {
479 if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
480 convtol_ = params->get ("Convergence Tolerance",
482 }
483 else {
484 convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
485 }
486
487 // Update parameter in our list and residual tests.
488 params_->set("Convergence Tolerance", convtol_);
489 if (convTest_ != Teuchos::null)
490 convTest_->setTolerance( convtol_ );
491 }
492
493 if (params->isParameter("Show Maximum Residual Norm Only")) {
494 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
495
496 // Update parameter in our list and residual tests
497 params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
498 if (convTest_ != Teuchos::null)
499 convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
500 }
501
502 // Create status tests if we need to.
503
504 // Basic test checks maximum iterations and native residual.
505 if (maxIterTest_ == Teuchos::null)
506 maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
507
508 // Implicit residual test, using the native residual to determine if convergence was achieved.
509 if (convTest_ == Teuchos::null)
510 convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, 1 ) );
511
512 if (sTest_ == Teuchos::null)
513 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
514
515 if (outputTest_ == Teuchos::null) {
516
517 // Create the status test output class.
518 // This class manages and formats the output from the status test.
519 StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
520 outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
521
522 // Set the solver string for the output test
523 std::string solverDesc = " Fixed Point ";
524 outputTest_->setSolverDesc( solverDesc );
525
526 }
527
528 // Create the timer if we need to.
529 if (timerSolve_ == Teuchos::null) {
530 std::string solveLabel = label_ + ": FixedPointSolMgr total solve time";
531#ifdef BELOS_TEUCHOS_TIME_MONITOR
532 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
533#endif
534 }
535
536 // Inform the solver manager that the current parameters were set.
537 isSet_ = true;
538}
539
540
541template<class ScalarType, class MV, class OP>
542Teuchos::RCP<const Teuchos::ParameterList>
544{
545 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
546
547 // Set all the valid parameters and their default values.
548 if(is_null(validPL)) {
549 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
550
551 // The static_cast is to resolve an issue with older clang versions which
552 // would cause the constexpr to link fail. With c++17 the problem is resolved.
553 pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
554 "The relative residual tolerance that needs to be achieved by the\n"
555 "iterative solver in order for the linear system to be declared converged.");
556 pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
557 "The maximum number of block iterations allowed for each\n"
558 "set of RHS solved.");
559 pl->set("Block Size", static_cast<int>(blockSize_default_),
560 "The number of vectors in each block.");
561 pl->set("Verbosity", static_cast<int>(verbosity_default_),
562 "What type(s) of solver information should be outputted\n"
563 "to the output stream.");
564 pl->set("Output Style", static_cast<int>(outputStyle_default_),
565 "What style is used for the solver information outputted\n"
566 "to the output stream.");
567 pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
568 "How often convergence information should be outputted\n"
569 "to the output stream.");
570 pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
571 "A reference-counted pointer to the output stream where all\n"
572 "solver output is sent.");
573 pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
574 "When convergence information is printed, only show the maximum\n"
575 "relative residual norm when the block size is greater than one.");
576 pl->set("Timer Label", static_cast<const char *>(label_default_),
577 "The string to use as a prefix for the timer labels.");
578 validPL = pl;
579 }
580 return validPL;
581}
582
583
584// solve()
585template<class ScalarType, class MV, class OP>
587 using Teuchos::RCP;
588 using Teuchos::rcp;
589 using Teuchos::rcp_const_cast;
590 using Teuchos::rcp_dynamic_cast;
591
592 // Set the current parameters if they were not set before. NOTE:
593 // This may occur if the user generated the solver manager with the
594 // default constructor and then didn't set any parameters using
595 // setParameters().
596 if (!isSet_) {
597 setParameters(Teuchos::parameterList(*getValidParameters()));
598 }
599
600 TEUCHOS_TEST_FOR_EXCEPTION( !problem_->isProblemSet(),
602 "Belos::FixedPointSolMgr::solve(): Linear problem is not ready, setProblem() "
603 "has not been called.");
604
605 // Create indices for the linear systems to be solved.
606 int startPtr = 0;
607 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
608 int numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
609
610 std::vector<int> currIdx, currIdx2;
611 currIdx.resize( blockSize_ );
612 currIdx2.resize( blockSize_ );
613 for (int i=0; i<numCurrRHS; ++i)
614 { currIdx[i] = startPtr+i; currIdx2[i]=i; }
615 for (int i=numCurrRHS; i<blockSize_; ++i)
616 { currIdx[i] = -1; currIdx2[i] = i; }
617
618 // Inform the linear problem of the current linear system to solve.
619 problem_->setLSIndex( currIdx );
620
622 // Set up the parameter list for the Iteration subclass.
623 Teuchos::ParameterList plist;
624 plist.set("Block Size",blockSize_);
625
626 // Reset the output status test (controls all the other status tests).
627 outputTest_->reset();
628
629 // Assume convergence is achieved, then let any failed convergence
630 // set this to false. "Innocent until proven guilty."
631 bool isConverged = true;
632
634 // Set up the FixedPoint Iteration subclass.
635
636 RCP<FixedPointIteration<ScalarType,MV,OP> > block_fp_iter;
637 block_fp_iter = rcp (new FixedPointIter<ScalarType,MV,OP> (problem_, printer_, outputTest_, plist));
638
639 // Enter solve() iterations
640 {
641#ifdef BELOS_TEUCHOS_TIME_MONITOR
642 Teuchos::TimeMonitor slvtimer(*timerSolve_);
643#endif
644
645 while ( numRHS2Solve > 0 ) {
646 //
647 // Reset the active / converged vectors from this block
648 std::vector<int> convRHSIdx;
649 std::vector<int> currRHSIdx( currIdx );
650 currRHSIdx.resize(numCurrRHS);
651
652 // Reset the number of iterations.
653 block_fp_iter->resetNumIters();
654
655 // Reset the number of calls that the status test output knows about.
656 outputTest_->resetNumCalls();
657
658 // Get the current residual for this block of linear systems.
659 RCP<MV> R_0 = MVT::CloneViewNonConst( *(rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
660
661 // Set the new state and initialize the solver.
663 newstate.R = R_0;
664 block_fp_iter->initializeFixedPoint(newstate);
665
666 while(1) {
667
668 // tell block_fp_iter to iterate
669 try {
670 block_fp_iter->iterate();
671 //
672 // Check whether any of the linear systems converged.
673 //
674 if (convTest_->getStatus() == Passed) {
675 // At least one of the linear system(s) converged.
676 //
677 // Get the column indices of the linear systems that converged.
678 std::vector<int> convIdx = convTest_->convIndices();
679
680 // If the number of converged linear systems equals the
681 // number of linear systems currently being solved, then
682 // we are done with this block.
683 if (convIdx.size() == currRHSIdx.size())
684 break; // break from while(1){block_fp_iter->iterate()}
685
686 // Inform the linear problem that we are finished with
687 // this current linear system.
688 problem_->setCurrLS();
689
690 // Reset currRHSIdx to contain the right-hand sides that
691 // are left to converge for this block.
692 int have = 0;
693 std::vector<int> unconvIdx(currRHSIdx.size());
694 for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
695 bool found = false;
696 for (unsigned int j=0; j<convIdx.size(); ++j) {
697 if (currRHSIdx[i] == convIdx[j]) {
698 found = true;
699 break;
700 }
701 }
702 if (!found) {
703 currIdx2[have] = currIdx2[i];
704 currRHSIdx[have++] = currRHSIdx[i];
705 }
706 else {
707 }
708 }
709 currRHSIdx.resize(have);
710 currIdx2.resize(have);
711
712 // Set the remaining indices after deflation.
713 problem_->setLSIndex( currRHSIdx );
714
715 // Get the current residual vector.
716 std::vector<MagnitudeType> norms;
717 R_0 = MVT::CloneCopy( *(block_fp_iter->getNativeResiduals(&norms)),currIdx2 );
718 for (int i=0; i<have; ++i) { currIdx2[i] = i; }
719
720 // Set the new blocksize for the solver.
721 block_fp_iter->setBlockSize( have );
722
723 // Set the new state and initialize the solver.
725 defstate.R = R_0;
726 block_fp_iter->initializeFixedPoint(defstate);
727 }
728 //
729 // None of the linear systems converged. Check whether the
730 // maximum iteration count was reached.
731 //
732 else if (maxIterTest_->getStatus() == Passed) {
733 isConverged = false; // None of the linear systems converged.
734 break; // break from while(1){block_fp_iter->iterate()}
735 }
736 //
737 // iterate() returned, but none of our status tests Passed.
738 // This indicates a bug.
739 //
740 else {
741 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
742 "Belos::FixedPointSolMgr::solve(): Neither the convergence test nor "
743 "the maximum iteration count test passed. Please report this bug "
744 "to the Belos developers.");
745 }
746 }
747 catch (const std::exception &e) {
748 std::ostream& err = printer_->stream (Errors);
749 err << "Error! Caught std::exception in FixedPointIteration::iterate() at "
750 << "iteration " << block_fp_iter->getNumIters() << std::endl
751 << e.what() << std::endl;
752 throw;
753 }
754 }
755
756 // Inform the linear problem that we are finished with this
757 // block linear system.
758 problem_->setCurrLS();
759
760 // Update indices for the linear systems to be solved.
761 startPtr += numCurrRHS;
762 numRHS2Solve -= numCurrRHS;
763 if ( numRHS2Solve > 0 ) {
764 numCurrRHS = ( numRHS2Solve < blockSize_) ? numRHS2Solve : blockSize_;
765
766
767 currIdx.resize( blockSize_ );
768 currIdx2.resize( blockSize_ );
769 for (int i=0; i<numCurrRHS; ++i)
770 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
771 for (int i=numCurrRHS; i<blockSize_; ++i)
772 { currIdx[i] = -1; currIdx2[i] = i; }
773
774 // Set the next indices.
775 problem_->setLSIndex( currIdx );
776
777 // Set the new blocksize for the solver.
778 block_fp_iter->setBlockSize( blockSize_ );
779 }
780 else {
781 currIdx.resize( numRHS2Solve );
782 }
783
784 }// while ( numRHS2Solve > 0 )
785
786 }
787
788 // print final summary
789 sTest_->print( printer_->stream(FinalSummary) );
790
791 // print timing information
792#ifdef BELOS_TEUCHOS_TIME_MONITOR
793 // Calling summarize() requires communication in general, so don't
794 // call it unless the user wants to print out timing details.
795 // summarize() will do all the work even if it's passed a "black
796 // hole" output stream.
797 if (verbosity_ & TimingDetails) {
798 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
799 }
800#endif
801
802 // Save the iteration count for this solve.
803 numIters_ = maxIterTest_->getNumIters();
804
805 // Save the convergence test value ("achieved tolerance") for this solve.
806 {
807 // testValues is nonnull and not persistent.
808 const std::vector<MagnitudeType>* pTestValues = convTest_->getTestValue();
809
810 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
811 "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
812 "method returned NULL. Please report this bug to the Belos developers.");
813
814 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
815 "Belos::FixedPointSolMgr::solve(): The convergence test's getTestValue() "
816 "method returned a vector of length zero. Please report this bug to the "
817 "Belos developers.");
818
819 // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
820 // achieved tolerances for all vectors in the current solve(), or
821 // just for the vectors from the last deflation?
822 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
823 }
824
825 if (!isConverged) {
826 return Unconverged; // return from FixedPointSolMgr::solve()
827 }
828 return Converged; // return from FixedPointSolMgr::solve()
829}
830
831// This method requires the solver manager to return a std::string that describes itself.
832template<class ScalarType, class MV, class OP>
834{
835 std::ostringstream oss;
836 oss << "Belos::FixedPointSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
837 return oss.str();
838}
839
840} // end Belos namespace
841
842#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.
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.
Definition: BelosTypes.hpp:60
This class implements the preconditioned fixed point iteration.
FixedPointSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
FixedPointSolMgrLinearProblemFailure(const std::string &what_arg)
The Belos::FixedPointSolMgr provides a powerful and fully-featured solver manager over the FixedPoint...
MagnitudeType achievedTol_
Tolerance achieved by the last solve() invocation.
FixedPointSolMgr()
Empty constructor for FixedPointSolMgr. This constructor takes no arguments and sets the default valu...
static constexpr int blockSize_default_
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.
static constexpr int outputFreq_default_
int getNumIters() const override
Get the iteration count for the most recent call to solve().
Teuchos::RCP< Teuchos::ParameterList > params_
Current parameter list.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
Teuchos::ScalarTraits< MagnitudeType > MT
Teuchos::RCP< std::ostream > outputStream_
Output stream to which the output manager prints.
int numIters_
Number of iterations taken by the last solve() invocation.
bool isSet_
Whether or not the parameters have been set (via setParameters()).
void replaceUserConvStatusTest(const Teuchos::RCP< StatusTestResNorm< ScalarType, MV, OP > > &userConvStatusTest)
Set user-defined convergence status test.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Teuchos::RCP< OutputManager< ScalarType > > printer_
Output manager, that handles printing of different kinds of messages.
static constexpr int verbosity_default_
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > outputTest_
Output "status test" that controls all the other status tests.
Teuchos::RCP< StatusTestResNorm< ScalarType, MV, OP > > convTest_
Convergence stopping criterion.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
std::string label_
Prefix label for all the timers.
MagnitudeType convtol_
Convergence tolerance (read from parameter list).
Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > problem_
The linear problem to solve.
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve.
static constexpr int outputStyle_default_
Teuchos::ScalarTraits< ScalarType > SCT
Teuchos::RCP< Teuchos::Time > timerSolve_
Solve timer.
static constexpr bool showMaxResNormOnly_default_
static constexpr const char * label_default_
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
Teuchos::RCP< StatusTest< ScalarType, MV, OP > > sTest_
Aggregate stopping criterion.
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
int maxIters_
Maximum iteration count (read from parameter list).
MultiVecTraits< ScalarType, MV > MVT
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
static constexpr int maxIters_default_
virtual ~FixedPointSolMgr()
Destructor.
OperatorTraits< ScalarType, MV, OP > OPT
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
Teuchos::RCP< StatusTestMaxIters< ScalarType, MV, OP > > maxIterTest_
Maximum iteration count stopping criterion.
A linear system to solve, and its associated information.
Traits class which defines basic operations on multivectors.
Class which defines basic traits for the operator type.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
A class for extending the status testing capabilities of Belos via logical combinations.
An implementation of StatusTestResNorm using a family of residual norms.
int setTolerance(MagnitudeType tolerance)
Set the value of the tolerance.
A Belos::StatusTest class for specifying a maximum number of iterations.
A factory class for generating StatusTestOutput objects.
Teuchos::RCP< StatusTestOutput< ScalarType, MV, OP > > create(const Teuchos::RCP< OutputManager< ScalarType > > &printer, Teuchos::RCP< StatusTest< ScalarType, MV, OP > > test, int mod, int printStates)
Create the StatusTestOutput object specified by the outputStyle.
An abstract class of StatusTest for stopping criteria using residual norms.
@ StatusTestDetails
Definition: BelosTypes.hpp:261
@ FinalSummary
Definition: BelosTypes.hpp:259
@ TimingDetails
Definition: BelosTypes.hpp:260
@ Undefined
Definition: BelosTypes.hpp:191
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:155
@ Unconverged
Definition: BelosTypes.hpp:157
@ Converged
Definition: BelosTypes.hpp:156
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:206
Default parameters common to most Belos solvers.
Definition: BelosTypes.hpp:283
static const double convTol
Default convergence tolerance.
Definition: BelosTypes.hpp:293
Structure to contain pointers to FixedPointIteration state variables.
Teuchos::RCP< const MV > R
The current residual.