Belos Version of the Day
Loading...
Searching...
No Matches
BelosTFQMRSolMgr.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_TFQMR_SOLMGR_HPP
11#define BELOS_TFQMR_SOLMGR_HPP
12
17#include "BelosConfigDefs.hpp"
18#include "BelosTypes.hpp"
19
22
23#include "BelosTFQMRIter.hpp"
31
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 TFQMRSolMgr : 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
106 const Teuchos::RCP<Teuchos::ParameterList> &pl );
107
109 virtual ~TFQMRSolMgr() {};
110
112 Teuchos::RCP<SolverManager<ScalarType, MV, OP, DM> > clone () const override {
113 return Teuchos::rcp(new TFQMRSolMgr<ScalarType,MV,OP,DM>);
114 }
116
118
119
121 return *problem_;
122 }
123
126 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override;
127
130 Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override { return params_; }
131
137 Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
138 return Teuchos::tuple(timerSolve_);
139 }
140
146 MagnitudeType achievedTol() const override {
147 return achievedTol_;
148 }
149
151 int getNumIters() const override {
152 return numIters_;
153 }
154
162 bool isLOADetected() const override { return false; }
164
166
167
169 void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > &problem ) override { problem_ = problem; }
170
172 void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
173
175
177
182 void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
184
186
187
205 ReturnType solve() override;
206
208
210
212 std::string description() const override;
214
215 private:
216
217 // Method for checking current status test against defined linear problem.
218 bool checkStatusTest();
219
220 // Linear problem.
221 Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > problem_;
222
223 // Output manager.
224 Teuchos::RCP<OutputManager<ScalarType> > printer_;
225 Teuchos::RCP<std::ostream> outputStream_;
226
227 // Status test.
228 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > sTest_;
229 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP,DM> > maxIterTest_;
230 Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > convTest_;
231 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP,DM> > expConvTest_, impConvTest_;
232 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP,DM> > outputTest_;
233
234 // Current parameter list.
235 Teuchos::RCP<Teuchos::ParameterList> params_;
236
237 // Default solver values.
238 static constexpr int maxIters_default_ = 1000;
239 static constexpr bool expResTest_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 const char * impResScale_default_ = "Norm of Preconditioned Initial Residual";
244 static constexpr const char * expResScale_default_ = "Norm of Initial Residual";
245 static constexpr const char * label_default_ = "Belos";
246
247 // Current solver values.
248 MagnitudeType convtol_, impTolScale_, achievedTol_;
249 int maxIters_, numIters_;
250 int verbosity_, outputStyle_, outputFreq_;
251 int blockSize_;
252 bool expResTest_;
253 std::string impResScale_, expResScale_;
254
255 // Timers.
256 std::string label_;
257 Teuchos::RCP<Teuchos::Time> timerSolve_;
258
259 // Internal state variables.
260 bool isSet_, isSTSet_;
261 };
262
263
264// Empty Constructor
265template<class ScalarType, class MV, class OP, class DM>
267 outputStream_(Teuchos::rcpFromRef(std::cout)),
268 convtol_(DefaultSolverParameters::convTol),
269 impTolScale_(DefaultSolverParameters::impTolScale),
270 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
271 maxIters_(maxIters_default_),
272 numIters_(0),
273 verbosity_(verbosity_default_),
274 outputStyle_(outputStyle_default_),
275 outputFreq_(outputFreq_default_),
276 blockSize_(1),
277 expResTest_(expResTest_default_),
278 impResScale_(impResScale_default_),
279 expResScale_(expResScale_default_),
280 label_(label_default_),
281 isSet_(false),
282 isSTSet_(false)
283{}
284
285
286// Basic Constructor
287template<class ScalarType, class MV, class OP, class DM>
289 const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > &problem,
290 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
291 problem_(problem),
292 outputStream_(Teuchos::rcpFromRef(std::cout)),
293 convtol_(DefaultSolverParameters::convTol),
294 impTolScale_(DefaultSolverParameters::impTolScale),
295 achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
296 maxIters_(maxIters_default_),
297 numIters_(0),
298 verbosity_(verbosity_default_),
299 outputStyle_(outputStyle_default_),
300 outputFreq_(outputFreq_default_),
301 blockSize_(1),
302 expResTest_(expResTest_default_),
303 impResScale_(impResScale_default_),
304 expResScale_(expResScale_default_),
305 label_(label_default_),
306 isSet_(false),
307 isSTSet_(false)
308{
309 TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument, "Problem not given to solver manager.");
310
311 // If the parameter list pointer is null, then set the current parameters to the default parameter list.
312 if ( !is_null(pl) ) {
313 setParameters( pl );
314 }
315}
316
317template<class ScalarType, class MV, class OP, class DM>
318void TFQMRSolMgr<ScalarType,MV,OP,DM>::setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params )
319{
320 // Create the internal parameter list if ones doesn't already exist.
321 if (params_ == Teuchos::null) {
322 params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
323 }
324 else {
325 params->validateParameters(*getValidParameters());
326 }
327
328 // Check for maximum number of iterations
329 if (params->isParameter("Maximum Iterations")) {
330 maxIters_ = params->get("Maximum Iterations",maxIters_default_);
331
332 // Update parameter in our list and in status test.
333 params_->set("Maximum Iterations", maxIters_);
334 if (maxIterTest_!=Teuchos::null)
335 maxIterTest_->setMaxIters( maxIters_ );
336 }
337
338 // Check for blocksize
339 if (params->isParameter("Block Size")) {
340 blockSize_ = params->get("Block Size",1);
341 TEUCHOS_TEST_FOR_EXCEPTION(blockSize_ != 1, std::invalid_argument,
342 "Belos::TFQMRSolMgr: \"Block Size\" must be 1.");
343
344 // Update parameter in our list.
345 params_->set("Block Size", blockSize_);
346 }
347
348 // Check to see if the timer label changed.
349 if (params->isParameter("Timer Label")) {
350 std::string tempLabel = params->get("Timer Label", label_default_);
351
352 // Update parameter in our list and solver timer
353 if (tempLabel != label_) {
354 label_ = tempLabel;
355 params_->set("Timer Label", label_);
356 std::string solveLabel = label_ + ": TFQMRSolMgr total solve time";
357#ifdef BELOS_TEUCHOS_TIME_MONITOR
358 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
359#endif
360 }
361 }
362
363 // Check for a change in verbosity level
364 if (params->isParameter("Verbosity")) {
365 if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
366 verbosity_ = params->get("Verbosity", verbosity_default_);
367 } else {
368 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
369 }
370
371 // Update parameter in our list.
372 params_->set("Verbosity", verbosity_);
373 if (printer_ != Teuchos::null)
374 printer_->setVerbosity(verbosity_);
375 }
376
377 // Check for a change in output style
378 if (params->isParameter("Output Style")) {
379 if (Teuchos::isParameterType<int>(*params,"Output Style")) {
380 outputStyle_ = params->get("Output Style", outputStyle_default_);
381 } else {
382 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
383 }
384
385 // Reconstruct the convergence test if the explicit residual test is not being used.
386 params_->set("Output Style", outputStyle_);
387 isSTSet_ = false;
388 }
389
390 // output stream
391 if (params->isParameter("Output Stream")) {
392 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
393
394 // Update parameter in our list.
395 params_->set("Output Stream", outputStream_);
396 if (printer_ != Teuchos::null)
397 printer_->setOStream( outputStream_ );
398 }
399
400 // frequency level
401 if (verbosity_ & Belos::StatusTestDetails) {
402 if (params->isParameter("Output Frequency")) {
403 outputFreq_ = params->get("Output Frequency", outputFreq_default_);
404 }
405
406 // Update parameter in out list and output status test.
407 params_->set("Output Frequency", outputFreq_);
408 if (outputTest_ != Teuchos::null)
409 outputTest_->setOutputFrequency( outputFreq_ );
410 }
411
412 // Create output manager if we need to.
413 if (printer_ == Teuchos::null) {
414 printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
415 }
416
417 // Check for convergence tolerance
418 if (params->isParameter("Convergence Tolerance")) {
419 if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
420 convtol_ = params->get ("Convergence Tolerance",
421 static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
422 }
423 else {
424 convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
425 }
426
427 // Update parameter in our list.
428 params_->set("Convergence Tolerance", convtol_);
429 isSTSet_ = false;
430 }
431
432 // Check for implicit residual scaling
433 if (params->isParameter("Implicit Tolerance Scale Factor")) {
434 if (params->isType<MagnitudeType> ("Implicit Tolerance Scale Factor")) {
435 impTolScale_ = params->get ("Implicit Tolerance Scale Factor",
436 static_cast<MagnitudeType> (DefaultSolverParameters::impTolScale));
437
438 }
439 else {
440 impTolScale_ = params->get ("Implicit Tolerance Scale Factor",
442 }
443
444 // Update parameter in our list.
445 params_->set("Implicit Tolerance Scale Factor", impTolScale_);
446 isSTSet_ = false;
447 }
448
449 // Check for a change in scaling, if so we need to build new residual tests.
450 if (params->isParameter("Implicit Residual Scaling")) {
451 std::string tempImpResScale = Teuchos::getParameter<std::string>( *params, "Implicit Residual Scaling" );
452
453 // Only update the scaling if it's different.
454 if (impResScale_ != tempImpResScale) {
455 impResScale_ = tempImpResScale;
456
457 // Update parameter in our list and residual tests
458 params_->set("Implicit Residual Scaling", impResScale_);
459
460 // Make sure the convergence test gets constructed again.
461 isSTSet_ = false;
462 }
463 }
464
465 if (params->isParameter("Explicit Residual Scaling")) {
466 std::string tempExpResScale = Teuchos::getParameter<std::string>( *params, "Explicit Residual Scaling" );
467
468 // Only update the scaling if it's different.
469 if (expResScale_ != tempExpResScale) {
470 expResScale_ = tempExpResScale;
471
472 // Update parameter in our list and residual tests
473 params_->set("Explicit Residual Scaling", expResScale_);
474
475 // Make sure the convergence test gets constructed again.
476 isSTSet_ = false;
477 }
478 }
479
480 if (params->isParameter("Explicit Residual Test")) {
481 expResTest_ = Teuchos::getParameter<bool>( *params,"Explicit Residual Test" );
482
483 // Reconstruct the convergence test if the explicit residual test is not being used.
484 params_->set("Explicit Residual Test", expResTest_);
485 if (expConvTest_ == Teuchos::null) {
486 isSTSet_ = false;
487 }
488 }
489
490 // Create the timer if we need to.
491 if (timerSolve_ == Teuchos::null) {
492 std::string solveLabel = label_ + ": TFQMRSolMgr total solve time";
493#ifdef BELOS_TEUCHOS_TIME_MONITOR
494 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
495#endif
496 }
497
498 // Inform the solver manager that the current parameters were set.
499 isSet_ = true;
500}
501
502
503// Check the status test versus the defined linear problem
504template<class ScalarType, class MV, class OP, class DM>
506
507 typedef Belos::StatusTestCombo<ScalarType,MV,OP,DM> StatusTestCombo_t;
509
510 // Basic test checks maximum iterations and native residual.
511 maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP,DM>( maxIters_ ) );
512
513 if (expResTest_) {
514
515 // Implicit residual test, using the native residual to determine if convergence was achieved.
516 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
517 Teuchos::rcp( new StatusTestGenResNorm_t( impTolScale_*convtol_ ) );
518 tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
519 impConvTest_ = tmpImpConvTest;
520
521 // Explicit residual test once the native residual is below the tolerance
522 Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
523 Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
524 tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit, Belos::TwoNorm );
525 tmpExpConvTest->defineScaleForm( convertStringToScaleType(expResScale_), Belos::TwoNorm );
526 expConvTest_ = tmpExpConvTest;
527
528 // The convergence test is a combination of the "cheap" implicit test and explicit test.
529 convTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
530 }
531 else {
532
533 // Implicit residual test, using the native residual to determine if convergence was achieved.
534 Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
535 Teuchos::rcp( new StatusTestGenResNorm_t( convtol_ ) );
536 tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
537 impConvTest_ = tmpImpConvTest;
538
539 // Set the explicit and total convergence test to this implicit test that checks for accuracy loss.
540 expConvTest_ = impConvTest_;
541 convTest_ = impConvTest_;
542 }
543 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
544
545 // Create the status test output class.
546 // This class manages and formats the output from the status test.
548 outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
549
550 // Set the solver string for the output test
551 std::string solverDesc = " TFQMR ";
552 outputTest_->setSolverDesc( solverDesc );
553
554
555 // The status test is now set.
556 isSTSet_ = true;
557
558 return false;
559}
560
561
562template<class ScalarType, class MV, class OP, class DM>
563Teuchos::RCP<const Teuchos::ParameterList>
565{
566 static Teuchos::RCP<const Teuchos::ParameterList> validPL;
567
568 // Set all the valid parameters and their default values.
569 if(is_null(validPL)) {
570 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
571
572 // The static_cast is to resolve an issue with older clang versions which
573 // would cause the constexpr to link fail. With c++17 the problem is resolved.
574 pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
575 "The relative residual tolerance that needs to be achieved by the\n"
576 "iterative solver in order for the linear system to be declared converged.");
577 pl->set("Implicit Tolerance Scale Factor", static_cast<MagnitudeType>(DefaultSolverParameters::impTolScale),
578 "The scale factor used by the implicit residual test when explicit residual\n"
579 "testing is used. May enable faster convergence when TFQMR bound is too loose.");
580 pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
581 "The maximum number of block iterations allowed for each\n"
582 "set of RHS solved.");
583 pl->set("Verbosity", static_cast<int>(verbosity_default_),
584 "What type(s) of solver information should be outputted\n"
585 "to the output stream.");
586 pl->set("Output Style", static_cast<int>(outputStyle_default_),
587 "What style is used for the solver information outputted\n"
588 "to the output stream.");
589 pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
590 "How often convergence information should be outputted\n"
591 "to the output stream.");
592 pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
593 "A reference-counted pointer to the output stream where all\n"
594 "solver output is sent.");
595 pl->set("Explicit Residual Test", static_cast<bool>(expResTest_default_),
596 "Whether the explicitly computed residual should be used in the convergence test.");
597 pl->set("Implicit Residual Scaling", static_cast<const char *>(impResScale_default_),
598 "The type of scaling used in the implicit residual convergence test.");
599 pl->set("Explicit Residual Scaling", static_cast<const char *>(expResScale_default_),
600 "The type of scaling used in the explicit residual convergence test.");
601 pl->set("Timer Label", static_cast<const char *>(label_default_),
602 "The string to use as a prefix for the timer labels.");
603 validPL = pl;
604 }
605 return validPL;
606}
607
608
609// solve()
610template<class ScalarType, class MV, class OP, class DM>
613
614 // Set the current parameters if they were not set before.
615 // NOTE: This may occur if the user generated the solver manager with the default constructor and
616 // then didn't set any parameters using setParameters().
617 if (!isSet_) {
618 setParameters(Teuchos::parameterList(*getValidParameters()));
619 }
620
622 "Belos::TFQMRSolMgr::solve(): Linear problem is not a valid object.");
623
625 "Belos::TFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
626
627 if (!isSTSet_) {
629 "Belos::TFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
630 }
631
632 // Create indices for the linear systems to be solved.
633 int startPtr = 0;
634 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
635 int numCurrRHS = blockSize_;
636
637 std::vector<int> currIdx, currIdx2;
638
639 // The index set is generated that informs the linear problem that some linear systems are augmented.
640 currIdx.resize( blockSize_ );
641 currIdx2.resize( blockSize_ );
642 for (int i=0; i<numCurrRHS; ++i)
643 { currIdx[i] = startPtr+i; currIdx2[i]=i; }
644
645 // Inform the linear problem of the current linear system to solve.
646 problem_->setLSIndex( currIdx );
647
649 // Parameter list
650 Teuchos::ParameterList plist;
651 plist.set("Block Size",blockSize_);
652
653 // Reset the status test.
654 outputTest_->reset();
655
656 // Assume convergence is achieved, then let any failed convergence set this to false.
657 bool isConverged = true;
658
660 // TFQMR solver
661
662 Teuchos::RCP<TFQMRIter<ScalarType,MV,OP,DM> > tfqmr_iter =
663 Teuchos::rcp( new TFQMRIter<ScalarType,MV,OP,DM>(problem_,printer_,outputTest_,plist) );
664
665 // Enter solve() iterations
666 {
667#ifdef BELOS_TEUCHOS_TIME_MONITOR
668 Teuchos::TimeMonitor slvtimer(*timerSolve_);
669#endif
670
671 while ( numRHS2Solve > 0 ) {
672 //
673 // Reset the active / converged vectors from this block
674 std::vector<int> convRHSIdx;
675 std::vector<int> currRHSIdx( currIdx );
676 currRHSIdx.resize(numCurrRHS);
677
678 // Reset the number of iterations.
679 tfqmr_iter->resetNumIters();
680
681 // Reset the number of calls that the status test output knows about.
682 outputTest_->resetNumCalls();
683
684 // Get the current residual for this block of linear systems.
685 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
686
687 // Set the new state and initialize the solver.
689 newstate.R = R_0;
690 tfqmr_iter->initializeTFQMR(newstate);
691
692 while(1) {
693
694 // tell tfqmr_iter to iterate
695 try {
696 tfqmr_iter->iterate();
697
699 //
700 // check convergence first
701 //
703 if ( convTest_->getStatus() == Passed ) {
704 // We have convergence of the linear system.
705 break; // break from while(1){tfqmr_iter->iterate()}
706 }
708 //
709 // check for maximum iterations
710 //
712 else if ( maxIterTest_->getStatus() == Passed ) {
713 // we don't have convergence
715 isConverged = false;
716 break; // break from while(1){tfqmr_iter->iterate()}
717 }
718
720 //
721 // we returned from iterate(), but none of our status tests Passed.
722 // something is wrong, and it is probably our fault.
723 //
725
726 else {
728 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
729 "Belos::TFQMRSolMgr::solve(): Invalid return from TFQMRIter::iterate().");
730 }
731 }
732 catch (const StatusTestNaNError& e) {
733 // A NaN was detected in the solver. Set the solution to zero and return unconverged.
735 achievedTol_ = MT::one();
736 Teuchos::RCP<MV> X = problem_->getLHS();
737 MVT::MvInit( *X, SCT::zero() );
738 printer_->stream(Warnings) << "Belos::TFQMRSolMgr::solve(): Warning! NaN has been detected!"
739 << std::endl;
740 return retType;
741 }
742 catch (const std::exception &e) {
744 printer_->stream(Errors) << "Error! Caught std::exception in TFQMRIter::iterate() at iteration "
745 << tfqmr_iter->getNumIters() << std::endl
746 << e.what() << std::endl;
747 throw;
748 }
749 }
750
751 // Update the current solution with the update computed by the iteration object.
752 problem_->updateSolution( tfqmr_iter->getCurrentUpdate(), true );
753
754 // Inform the linear problem that we are finished with this block linear system.
755 problem_->setCurrLS();
756
757 // Update indices for the linear systems to be solved.
760 if ( numRHS2Solve > 0 ) {
761 numCurrRHS = blockSize_;
762
763 currIdx.resize( blockSize_ );
764 currIdx2.resize( blockSize_ );
765 for (int i=0; i<numCurrRHS; ++i)
766 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
767 // Set the next indices.
768 problem_->setLSIndex( currIdx );
769
770 // Set the new blocksize for the solver.
771 tfqmr_iter->setBlockSize( blockSize_ );
772 }
773 else {
774 currIdx.resize( numRHS2Solve );
775 }
776
777 }// while ( numRHS2Solve > 0 )
778
779 }
780
781 // print final summary
782 sTest_->print( printer_->stream(FinalSummary) );
783
784 // print timing information
785#ifdef BELOS_TEUCHOS_TIME_MONITOR
786 // Calling summarize() can be expensive, so don't call unless the
787 // user wants to print out timing details. summarize() will do all
788 // the work even if it's passed a "black hole" output stream.
789 if (verbosity_ & TimingDetails)
790 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
791#endif
792
793 // get iteration information for this solve
794 numIters_ = maxIterTest_->getNumIters();
795
796 // Save the convergence test value ("achieved tolerance") for this
797 // solve. For this solver, convTest_ may either be a single
798 // (implicit) residual norm test, or a combination of two residual
799 // norm tests. In the latter case, the master convergence test
800 // convTest_ is a SEQ combo of the implicit resp. explicit tests.
801 // If the implicit test never passes, then the explicit test won't
802 // ever be executed. This manifests as
803 // expConvTest_->getTestValue()->size() < 1. We deal with this case
804 // by using the values returned by impConvTest_->getTestValue().
805 {
806 // We'll fetch the vector of residual norms one way or the other.
807 const std::vector<MagnitudeType>* pTestValues = NULL;
808 if (expResTest_) {
809 pTestValues = expConvTest_->getTestValue();
810 if (pTestValues == NULL || pTestValues->size() < 1) {
811 pTestValues = impConvTest_->getTestValue();
812 }
813 }
814 else {
815 // Only the implicit residual norm test is being used.
816 pTestValues = impConvTest_->getTestValue();
817 }
818 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
819 "Belos::TFQMRSolMgr::solve(): The implicit convergence test's "
820 "getTestValue() method returned NULL. Please report this bug to the "
821 "Belos developers.");
822 TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
823 "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
824 "getTestValue() method returned a vector of length zero. Please report "
825 "this bug to the Belos developers.");
826
827 // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
828 // achieved tolerances for all vectors in the current solve(), or
829 // just for the vectors from the last deflation?
830 achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
831 }
832
833 if (!isConverged) {
834 return retType; // return from TFQMRSolMgr::solve()
835 }
836 return Converged; // return from TFQMRSolMgr::solve()
837}
838
839// This method requires the solver manager to return a std::string that describes itself.
840template<class ScalarType, class MV, class OP, class DM>
842{
843 std::ostringstream oss;
844 oss << "Belos::TFQMRSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
845 oss << "{}";
846 return oss.str();
847}
848
849} // end Belos namespace
850
851#endif /* BELOS_TFQMR_SOLMGR_HPP */
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.
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
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.
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 ...
The Belos::TFQMRSolMgr provides a powerful and fully-featured solver manager over the TFQMR linear so...
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem) override
Set the linear problem that needs to be solved.
bool isLOADetected() const override
Whether loss of accuracy was detected during the last solve() invocation.
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.
std::string description() const override
Method to return description of the TFQMR solver manager.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
TFQMRSolMgr()
Empty constructor for TFQMRSolMgr. This constructor takes no arguments and sets the default values fo...
Teuchos::RCP< SolverManager< ScalarType, MV, OP, DM > > clone() const override
clone for Inverted Injection (DII)
int getNumIters() const override
Get the iteration count for the most recent call to solve().
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
virtual ~TFQMRSolMgr()
Destructor.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
TFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
TFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
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
@ Undetermined
ResetType
How to reset the solver.
Default parameters common to most Belos solvers.
static const double impTolScale
"Implicit Tolerance Scale Factor"
static const double convTol
Default convergence tolerance.

Generated for Belos by doxygen 1.9.8