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