Belos Version of the Day
Loading...
Searching...
No Matches
BelosPseudoBlockStochasticCGSolMgr.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_PSEUDO_BLOCK_STOCHASTIC_CG_SOLMGR_HPP
11#define BELOS_PSEUDO_BLOCK_STOCHASTIC_CG_SOLMGR_HPP
12
17#include "BelosConfigDefs.hpp"
18#include "BelosTypes.hpp"
19
22
29#ifdef BELOS_TEUCHOS_TIME_MONITOR
30#include "Teuchos_TimeMonitor.hpp"
31#endif
32
42namespace Belos {
43
45
46
56
57 template<class ScalarType, class MV, class OP>
58 class PseudoBlockStochasticCGSolMgr : public SolverManager<ScalarType,MV,OP> {
59
60 private:
63 typedef Teuchos::ScalarTraits<ScalarType> SCT;
64 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
65 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
66
67 public:
68
70
71
78
89 const Teuchos::RCP<Teuchos::ParameterList> &pl );
90
93
95 Teuchos::RCP<SolverManager<ScalarType, MV, OP> > clone () const override {
97 }
99
101
102
104 return *problem_;
105 }
106
109 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override;
110
113 Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override { return params_; }
114
120 Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
121 return Teuchos::tuple(timerSolve_);
122 }
123
125 int getNumIters() const override {
126 return numIters_;
127 }
128
132 bool isLOADetected() const override { return false; }
133
135
137
138
140 void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) override { problem_ = problem; }
141
143 void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
144
146
148
149
153 void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
155
157
158
176 ReturnType solve() override;
177
179
181 Teuchos::RCP<MV> getStochasticVector() { return Y_;}
182
185
187 std::string description() const override;
188
190
191 private:
192
193 // Linear problem.
194 Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
195
196 // Output manager.
197 Teuchos::RCP<OutputManager<ScalarType> > printer_;
198 Teuchos::RCP<std::ostream> outputStream_;
199
200 // Status test.
201 Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
202 Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
203 Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > convTest_;
204 Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
205
206 // Current parameter list.
207 Teuchos::RCP<Teuchos::ParameterList> params_;
208
214 mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
215
216 // Default solver values.
217 static constexpr int maxIters_default_ = 1000;
218 static constexpr bool assertPositiveDefiniteness_default_ = true;
219 static constexpr bool showMaxResNormOnly_default_ = false;
220 static constexpr int verbosity_default_ = Belos::Errors;
221 static constexpr int outputStyle_default_ = Belos::General;
222 static constexpr int outputFreq_default_ = -1;
223 static constexpr int defQuorum_default_ = 1;
224 static constexpr const char * resScale_default_ = "Norm of Initial Residual";
225 static constexpr const char * label_default_ = "Belos";
226
227 // Current solver values.
228 MagnitudeType convtol_;
229 int maxIters_, numIters_;
230 int verbosity_, outputStyle_, outputFreq_, defQuorum_;
231 bool assertPositiveDefiniteness_, showMaxResNormOnly_;
232 std::string resScale_;
233
234 // Timers.
235 std::string label_;
236 Teuchos::RCP<Teuchos::Time> timerSolve_;
237
238 // Internal state variables.
239 bool isSet_;
240
241 // Stashed copy of the stochastic vector
242 Teuchos::RCP<MV> Y_;
243
244 };
245
246
247// Empty Constructor
248template<class ScalarType, class MV, class OP>
250 outputStream_(Teuchos::rcpFromRef(std::cout)),
251 convtol_(DefaultSolverParameters::convTol),
252 maxIters_(maxIters_default_),
253 numIters_(0),
254 verbosity_(verbosity_default_),
255 outputStyle_(outputStyle_default_),
256 outputFreq_(outputFreq_default_),
257 defQuorum_(defQuorum_default_),
258 assertPositiveDefiniteness_(assertPositiveDefiniteness_default_),
259 showMaxResNormOnly_(showMaxResNormOnly_default_),
260 resScale_(resScale_default_),
261 label_(label_default_),
262 isSet_(false)
263{}
264
265// Basic Constructor
266template<class ScalarType, class MV, class OP>
269 const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
270 problem_(problem),
271 outputStream_(Teuchos::rcpFromRef(std::cout)),
272 convtol_(DefaultSolverParameters::convTol),
273 maxIters_(maxIters_default_),
274 numIters_(0),
275 verbosity_(verbosity_default_),
276 outputStyle_(outputStyle_default_),
277 outputFreq_(outputFreq_default_),
278 defQuorum_(defQuorum_default_),
279 assertPositiveDefiniteness_(assertPositiveDefiniteness_default_),
280 showMaxResNormOnly_(showMaxResNormOnly_default_),
281 resScale_(resScale_default_),
282 label_(label_default_),
283 isSet_(false)
284{
286 problem_.is_null (), std::invalid_argument,
287 "Belos::PseudoBlockStochasticCGSolMgr two-argument constructor: "
288 "'problem' is null. You must supply a non-null Belos::LinearProblem "
289 "instance when calling this constructor.");
290
291 if (! pl.is_null ()) {
292 // Set the parameters using the list that was passed in.
294 }
295}
296
297template<class ScalarType, class MV, class OP>
298void PseudoBlockStochasticCGSolMgr<ScalarType,MV,OP>::setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params )
299{
300 using Teuchos::ParameterList;
301 using Teuchos::parameterList;
302 using Teuchos::RCP;
303
304 RCP<const ParameterList> defaultParams = getValidParameters();
305
306 // Create the internal parameter list if one doesn't already exist.
307 if (params_.is_null()) {
308 params_ = parameterList (*defaultParams);
309 } else {
310 params->validateParameters (*defaultParams);
311 }
312
313 // Check for maximum number of iterations
314 if (params->isParameter("Maximum Iterations")) {
315 maxIters_ = params->get("Maximum Iterations",maxIters_default_);
316
317 // Update parameter in our list and in status test.
318 params_->set("Maximum Iterations", maxIters_);
319 if (maxIterTest_!=Teuchos::null)
320 maxIterTest_->setMaxIters( maxIters_ );
321 }
322
323 // Check if positive definiteness assertions are to be performed
324 if (params->isParameter("Assert Positive Definiteness")) {
325 assertPositiveDefiniteness_ = params->get("Assert Positive Definiteness",assertPositiveDefiniteness_default_);
326
327 // Update parameter in our list.
328 params_->set("Assert Positive Definiteness", assertPositiveDefiniteness_);
329 }
330
331 // Check to see if the timer label changed.
332 if (params->isParameter("Timer Label")) {
333 std::string tempLabel = params->get("Timer Label", label_default_);
334
335 // Update parameter in our list and solver timer
336 if (tempLabel != label_) {
337 label_ = tempLabel;
338 params_->set("Timer Label", label_);
339 std::string solveLabel = label_ + ": PseudoBlockStochasticCGSolMgr total solve time";
340#ifdef BELOS_TEUCHOS_TIME_MONITOR
341 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
342#endif
343 }
344 }
345
346 // Check for a change in verbosity level
347 if (params->isParameter("Verbosity")) {
348 if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
349 verbosity_ = params->get("Verbosity", verbosity_default_);
350 } else {
351 verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
352 }
353
354 // Update parameter in our list.
355 params_->set("Verbosity", verbosity_);
356 if (printer_ != Teuchos::null)
357 printer_->setVerbosity(verbosity_);
358 }
359
360 // Check for a change in output style
361 if (params->isParameter("Output Style")) {
362 if (Teuchos::isParameterType<int>(*params,"Output Style")) {
363 outputStyle_ = params->get("Output Style", outputStyle_default_);
364 } else {
365 outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
366 }
367
368 // Reconstruct the convergence test if the explicit residual test is not being used.
369 params_->set("Output Style", outputStyle_);
370 outputTest_ = Teuchos::null;
371 }
372
373 // output stream
374 if (params->isParameter("Output Stream")) {
375 outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
376
377 // Update parameter in our list.
378 params_->set("Output Stream", outputStream_);
379 if (printer_ != Teuchos::null)
380 printer_->setOStream( outputStream_ );
381 }
382
383 // frequency level
384 if (verbosity_ & Belos::StatusTestDetails) {
385 if (params->isParameter("Output Frequency")) {
386 outputFreq_ = params->get("Output Frequency", outputFreq_default_);
387 }
388
389 // Update parameter in out list and output status test.
390 params_->set("Output Frequency", outputFreq_);
391 if (outputTest_ != Teuchos::null)
392 outputTest_->setOutputFrequency( outputFreq_ );
393 }
394
395 // Create output manager if we need to.
396 if (printer_ == Teuchos::null) {
397 printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
398 }
399
400 // Convergence
401 typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
402 typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestResNorm_t;
403
404 // Check for convergence tolerance
405 if (params->isParameter("Convergence Tolerance")) {
406 if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
407 convtol_ = params->get ("Convergence Tolerance",
408 static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
409 }
410 else {
411 convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
412 }
413
414 // Update parameter in our list and residual tests.
415 params_->set("Convergence Tolerance", convtol_);
416 if (convTest_ != Teuchos::null)
417 convTest_->setTolerance( convtol_ );
418 }
419
420 if (params->isParameter("Show Maximum Residual Norm Only")) {
421 showMaxResNormOnly_ = Teuchos::getParameter<bool>(*params,"Show Maximum Residual Norm Only");
422
423 // Update parameter in our list and residual tests
424 params_->set("Show Maximum Residual Norm Only", showMaxResNormOnly_);
425 if (convTest_ != Teuchos::null)
426 convTest_->setShowMaxResNormOnly( showMaxResNormOnly_ );
427 }
428
429 // Check for a change in scaling, if so we need to build new residual tests.
430 bool newResTest = false;
431 {
432 // "Residual Scaling" is the old parameter name; "Implicit
433 // Residual Scaling" is the new name. We support both options for
434 // backwards compatibility.
435 std::string tempResScale = resScale_;
436 bool implicitResidualScalingName = false;
437 if (params->isParameter ("Residual Scaling")) {
438 tempResScale = params->get<std::string> ("Residual Scaling");
439 }
440 else if (params->isParameter ("Implicit Residual Scaling")) {
441 tempResScale = params->get<std::string> ("Implicit Residual Scaling");
443 }
444
445 // Only update the scaling if it's different.
446 if (resScale_ != tempResScale) {
448 resScale_ = tempResScale;
449
450 // Update parameter in our list and residual tests, using the
451 // given parameter name.
453 params_->set ("Implicit Residual Scaling", resScale_);
454 }
455 else {
456 params_->set ("Residual Scaling", resScale_);
457 }
458
459 if (! convTest_.is_null()) {
460 try {
461 convTest_->defineScaleForm( resScaleType, Belos::TwoNorm );
462 }
463 catch (std::exception& e) {
464 // Make sure the convergence test gets constructed again.
465 newResTest = true;
466 }
467 }
468 }
469 }
470
471 // Get the deflation quorum, or number of converged systems before deflation is allowed
472 if (params->isParameter("Deflation Quorum")) {
473 defQuorum_ = params->get("Deflation Quorum", defQuorum_);
474 params_->set("Deflation Quorum", defQuorum_);
475 if (convTest_ != Teuchos::null)
476 convTest_->setQuorum( defQuorum_ );
477 }
478
479 // Create status tests if we need to.
480
481 // Basic test checks maximum iterations and native residual.
482 if (maxIterTest_ == Teuchos::null)
483 maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
484
485 // Implicit residual test, using the native residual to determine if convergence was achieved.
486 if (convTest_ == Teuchos::null || newResTest) {
487 convTest_ = Teuchos::rcp( new StatusTestResNorm_t( convtol_, defQuorum_, showMaxResNormOnly_ ) );
488 convTest_->defineScaleForm( convertStringToScaleType( resScale_ ), Belos::TwoNorm );
489 }
490
491 if (sTest_ == Teuchos::null || newResTest)
492 sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
493
494 if (outputTest_ == Teuchos::null || newResTest) {
495
496 // Create the status test output class.
497 // This class manages and formats the output from the status test.
499 outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
500
501 // Set the solver string for the output test
502 std::string solverDesc = " Pseudo Block CG ";
503 outputTest_->setSolverDesc( solverDesc );
504
505 }
506
507 // Create the timer if we need to.
508 if (timerSolve_ == Teuchos::null) {
509 std::string solveLabel = label_ + ": PseudoBlockStochasticCGSolMgr total solve time";
510#ifdef BELOS_TEUCHOS_TIME_MONITOR
511 timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
512#endif
513 }
514
515 // Inform the solver manager that the current parameters were set.
516 isSet_ = true;
517}
518
519
520template<class ScalarType, class MV, class OP>
521Teuchos::RCP<const Teuchos::ParameterList>
523{
524 using Teuchos::ParameterList;
525 using Teuchos::parameterList;
526 using Teuchos::RCP;
527
528 if (validParams_.is_null()) {
529 // Set all the valid parameters and their default values.
530
531 // The static_cast is to resolve an issue with older clang versions which
532 // would cause the constexpr to link fail. With c++17 the problem is resolved.
534 pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
535 "The relative residual tolerance that needs to be achieved by the\n"
536 "iterative solver in order for the linera system to be declared converged.");
537 pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
538 "The maximum number of block iterations allowed for each\n"
539 "set of RHS solved.");
540 pl->set("Assert Positive Definiteness", static_cast<bool>(assertPositiveDefiniteness_default_),
541 "Whether or not to assert that the linear operator\n"
542 "and the preconditioner are indeed positive definite.");
543 pl->set("Verbosity", static_cast<int>(verbosity_default_),
544 "What type(s) of solver information should be outputted\n"
545 "to the output stream.");
546 pl->set("Output Style", static_cast<int>(outputStyle_default_),
547 "What style is used for the solver information outputted\n"
548 "to the output stream.");
549 pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
550 "How often convergence information should be outputted\n"
551 "to the output stream.");
552 pl->set("Deflation Quorum", static_cast<int>(defQuorum_default_),
553 "The number of linear systems that need to converge before\n"
554 "they are deflated. This number should be <= block size.");
555 pl->set("Output Stream", Teuchos::rcpFromRef(std::cout),
556 "A reference-counted pointer to the output stream where all\n"
557 "solver output is sent.");
558 pl->set("Show Maximum Residual Norm Only", static_cast<bool>(showMaxResNormOnly_default_),
559 "When convergence information is printed, only show the maximum\n"
560 "relative residual norm when the block size is greater than one.");
561 pl->set("Implicit Residual Scaling", resScale_default_,
562 "The type of scaling used in the residual convergence test.");
563 // We leave the old name as a valid parameter for backwards
564 // compatibility (so that validateParametersAndSetDefaults()
565 // doesn't raise an exception if it encounters "Residual
566 // Scaling"). The new name was added for compatibility with other
567 // solvers, none of which use "Residual Scaling".
568 pl->set("Residual Scaling", resScale_default_,
569 "The type of scaling used in the residual convergence test. This "
570 "name is deprecated; the new name is \"Implicit Residual Scaling\".");
571 pl->set("Timer Label", static_cast<const char *>(label_default_),
572 "The string to use as a prefix for the timer labels.");
573 validParams_ = pl;
574 }
575 return validParams_;
576}
577
578
579// solve()
580template<class ScalarType, class MV, class OP>
582
583 // Set the current parameters if they were not set before.
584 // NOTE: This may occur if the user generated the solver manager with the default constructor and
585 // then didn't set any parameters using setParameters().
586 if (!isSet_) { setParameters( params_ ); }
587
589 "Belos::PseudoBlockStochasticCGSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
590
591 // Create indices for the linear systems to be solved.
592 int startPtr = 0;
593 int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
595
596 std::vector<int> currIdx( numRHS2Solve ), currIdx2( numRHS2Solve );
597 for (int i=0; i<numRHS2Solve; ++i) {
598 currIdx[i] = startPtr+i;
599 currIdx2[i]=i;
600 }
601
602 // Inform the linear problem of the current linear system to solve.
603 problem_->setLSIndex( currIdx );
604
606 // Parameter list
607 Teuchos::ParameterList plist;
608
609 plist.set("Assert Positive Definiteness",assertPositiveDefiniteness_);
610
611 // Reset the status test.
612 outputTest_->reset();
613
614 // Assume convergence is achieved, then let any failed convergence set this to false.
615 bool isConverged = true;
616
618 // Pseudo-Block CG solver
619
620 Teuchos::RCP<PseudoBlockStochasticCGIter<ScalarType,MV,OP> > block_cg_iter
621 = Teuchos::rcp( new PseudoBlockStochasticCGIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,plist) );
622
623 // Enter solve() iterations
624 {
625#ifdef BELOS_TEUCHOS_TIME_MONITOR
626 Teuchos::TimeMonitor slvtimer(*timerSolve_);
627#endif
628
629 while ( numRHS2Solve > 0 ) {
630
631 // Reset the active / converged vectors from this block
632 std::vector<int> convRHSIdx;
633 std::vector<int> currRHSIdx( currIdx );
634 currRHSIdx.resize(numCurrRHS);
635
636 // Reset the number of iterations.
637 block_cg_iter->resetNumIters();
638
639 // Reset the number of calls that the status test output knows about.
640 outputTest_->resetNumCalls();
641
642 // Get the current residual for this block of linear systems.
643 Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitResVec())), currIdx );
644
645 // Get a new state struct and initialize the solver.
647 newState.R = R_0;
648 block_cg_iter->initializeCG(newState);
649
650 while(1) {
651
652 // tell block_gmres_iter to iterate
653 try {
654 block_cg_iter->iterate();
655
657 //
658 // check convergence first
659 //
661 if ( convTest_->getStatus() == Passed ) {
662
663 // Figure out which linear systems converged.
664 std::vector<int> convIdx = Teuchos::rcp_dynamic_cast<StatusTestGenResNorm<ScalarType,MV,OP> >(convTest_)->convIndices();
665
666 // If the number of converged linear systems is equal to the
667 // number of current linear systems, then we are done with this block.
668 if (convIdx.size() == currRHSIdx.size())
669 break; // break from while(1){block_cg_iter->iterate()}
670
671 // Inform the linear problem that we are finished with this current linear system.
672 problem_->setCurrLS();
673
674 // Reset currRHSIdx to have the right-hand sides that are left to converge for this block.
675 int have = 0;
676 std::vector<int> unconvIdx(currRHSIdx.size());
677 for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
678 bool found = false;
679 for (unsigned int j=0; j<convIdx.size(); ++j) {
680 if (currRHSIdx[i] == convIdx[j]) {
681 found = true;
682 break;
683 }
684 }
685 if (!found) {
688 }
689 }
690 currRHSIdx.resize(have);
691 currIdx2.resize(have);
692
693 // Set the remaining indices after deflation.
694 problem_->setLSIndex( currRHSIdx );
695
696 // Get the current residual vector.
697 std::vector<MagnitudeType> norms;
698 R_0 = MVT::CloneCopy( *(block_cg_iter->getNativeResiduals(&norms)),currIdx2 );
699 for (int i=0; i<have; ++i) { currIdx2[i] = i; }
700
701 // Set the new state and initialize the solver.
703 defstate.R = R_0;
704 block_cg_iter->initializeCG(defstate);
705 }
706
708 //
709 // check for maximum iterations
710 //
712 else if ( maxIterTest_->getStatus() == Passed ) {
713 // we don't have convergence
714 isConverged = false;
715 break; // break from while(1){block_cg_iter->iterate()}
716 }
717
719 //
720 // we returned from iterate(), but none of our status tests Passed.
721 // something is wrong, and it is probably our fault.
722 //
724
725 else {
726 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
727 "Belos::PseudoBlockStochasticCGSolMgr::solve(): Invalid return from PseudoBlockStochasticCGIter::iterate().");
728 }
729 }
730 catch (const std::exception &e) {
731 printer_->stream(Errors) << "Error! Caught std::exception in PseudoBlockStochasticCGIter::iterate() at iteration "
732 << block_cg_iter->getNumIters() << std::endl
733 << e.what() << std::endl;
734 throw;
735 }
736 }
737
738 // Inform the linear problem that we are finished with this block linear system.
739 problem_->setCurrLS();
740
741 // Update indices for the linear systems to be solved.
744
745 if ( numRHS2Solve > 0 ) {
746
748 currIdx.resize( numCurrRHS );
749 currIdx2.resize( numCurrRHS );
750 for (int i=0; i<numCurrRHS; ++i)
751 { currIdx[i] = startPtr+i; currIdx2[i] = i; }
752
753 // Set the next indices.
754 problem_->setLSIndex( currIdx );
755 }
756 else {
757 currIdx.resize( numRHS2Solve );
758 }
759
760 }// while ( numRHS2Solve > 0 )
761
762 }
763
764 // get the final stochastic vector
765 Y_=block_cg_iter->getStochasticVector();
766
767
768 // print final summary
769 sTest_->print( printer_->stream(FinalSummary) );
770
771 // print timing information
772#ifdef BELOS_TEUCHOS_TIME_MONITOR
773 // Calling summarize() can be expensive, so don't call unless the
774 // user wants to print out timing details. summarize() will do all
775 // the work even if it's passed a "black hole" output stream.
776 if (verbosity_ & TimingDetails)
777 Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
778#endif
779
780 // get iteration information for this solve
781 numIters_ = maxIterTest_->getNumIters();
782
783 if (!isConverged ) {
784 return Unconverged; // return from PseudoBlockStochasticCGSolMgr::solve()
785 }
786 return Converged; // return from PseudoBlockStochasticCGSolMgr::solve()
787}
788
789// This method requires the solver manager to return a std::string that describes itself.
790template<class ScalarType, class MV, class OP>
792{
793 std::ostringstream oss;
794 oss << "Belos::PseudoBlockStochasticCGSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
795 oss << "{";
796 oss << "}";
797 return oss.str();
798}
799
800} // end Belos namespace
801
802#endif /* BELOS_PSEUDO_BLOCK_CG_SOLMGR_HPP */
Belos header file which uses auto-configuration information to include necessary C++ headers.
Class which describes the linear problem to be solved by the iterative solver.
Class which manages the output and verbosity of the Belos solvers.
Belos concrete class for performing the stochastic pseudo-block CG iteration.
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.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
PseudoBlockStochasticCGSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
The Belos::PseudoBlockStochasticCGSolMgr provides a powerful and fully-featured solver manager over t...
PseudoBlockStochasticCGSolMgr()
Empty constructor for BlockStochasticCGSolMgr. This constructor takes no arguments and sets the defau...
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
std::string description() const override
Method to return description of the block CG solver manager.
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
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< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
int getNumIters() const override
Get the iteration count for the most recent call to solve().
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
bool isLOADetected() const override
Return whether a loss of accuracy was detected by this solver during the most current solve.
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Teuchos::RCP< MV > getStochasticVector()
Get a copy of the final stochastic vector.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
@ StatusTestDetails
@ FinalSummary
@ TimingDetails
ReturnType
Whether the Belos solve converged for all linear systems.
@ Unconverged
ScaleType
The type of scaling to use on the residual norm value.
ResetType
How to reset the solver.
Default parameters common to most Belos solvers.
static const double convTol
Default convergence tolerance.

Generated for Belos by doxygen 1.9.8