Belos  Version of the Day
BelosPseudoBlockTFQMRSolMgr.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_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP
43 #define BELOS_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP
44 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosTypes.hpp"
51 
52 #include "BelosLinearProblem.hpp"
53 #include "BelosSolverManager.hpp"
54 
58 #include "BelosStatusTestCombo.hpp"
60 #include "BelosOutputManager.hpp"
61 #ifdef BELOS_TEUCHOS_TIME_MONITOR
62 #include "Teuchos_TimeMonitor.hpp"
63 #endif
64 
78 namespace Belos {
79 
81 
82 
90  PseudoBlockTFQMRSolMgrLinearProblemFailure(const std::string& what_arg) : BelosError(what_arg)
91  {}};
92 
100  PseudoBlockTFQMRSolMgrOrthoFailure(const std::string& what_arg) : BelosError(what_arg)
101  {}};
102 
103  template<class ScalarType, class MV, class OP>
104  class PseudoBlockTFQMRSolMgr : public SolverManager<ScalarType,MV,OP> {
105 
106  private:
109  typedef Teuchos::ScalarTraits<ScalarType> SCT;
110  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
111  typedef Teuchos::ScalarTraits<MagnitudeType> MT;
112 
113  public:
114 
116 
117 
124 
141  PseudoBlockTFQMRSolMgr( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem,
142  const Teuchos::RCP<Teuchos::ParameterList> &pl );
143 
146 
148  Teuchos::RCP<SolverManager<ScalarType, MV, OP> > clone () const override {
149  return Teuchos::rcp(new PseudoBlockTFQMRSolMgr<ScalarType,MV,OP>);
150  }
152 
154 
155 
156  const LinearProblem<ScalarType,MV,OP>& getProblem() const override {
157  return *problem_;
158  }
159 
162  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const override;
163 
166  Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const override { return params_; }
167 
173  Teuchos::Array<Teuchos::RCP<Teuchos::Time> > getTimers() const {
174  return Teuchos::tuple(timerSolve_);
175  }
176 
182  MagnitudeType achievedTol() const override {
183  return achievedTol_;
184  }
185 
187  int getNumIters() const override {
188  return numIters_;
189  }
190 
198  bool isLOADetected() const override { return false; }
200 
202 
203 
205  void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) override { problem_ = problem; }
206 
208  void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) override;
209 
211 
213 
218  void reset( const ResetType type ) override { if ((type & Belos::Problem) && !Teuchos::is_null(problem_)) problem_->setProblem(); }
220 
222 
223 
241  ReturnType solve() override;
242 
244 
246 
248  std::string description() const override;
249 
251  private:
252 
253  // Method for checking current status test against defined linear problem.
254  bool checkStatusTest();
255 
256  // Linear problem.
257  Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > problem_;
258 
259  // Output manager.
260  Teuchos::RCP<OutputManager<ScalarType> > printer_;
261  Teuchos::RCP<std::ostream> outputStream_;
262 
263  // Status test.
264  Teuchos::RCP<StatusTest<ScalarType,MV,OP> > sTest_;
265  Teuchos::RCP<StatusTestMaxIters<ScalarType,MV,OP> > maxIterTest_;
266  Teuchos::RCP<StatusTest<ScalarType,MV,OP> > convTest_;
267  Teuchos::RCP<StatusTestGenResNorm<ScalarType,MV,OP> > expConvTest_, impConvTest_;
268  Teuchos::RCP<StatusTestOutput<ScalarType,MV,OP> > outputTest_;
269 
270  // Current parameter list.
271  Teuchos::RCP<Teuchos::ParameterList> params_;
272 
273  // Default solver values.
274  static constexpr int maxIters_default_ = 1000;
275  static constexpr bool expResTest_default_ = false;
276  static constexpr int verbosity_default_ = Belos::Errors;
277  static constexpr int outputStyle_default_ = Belos::General;
278  static constexpr int outputFreq_default_ = -1;
279  static constexpr int defQuorum_default_ = 1;
280  static constexpr const char * impResScale_default_ = "Norm of Preconditioned Initial Residual";
281  static constexpr const char * expResScale_default_ = "Norm of Initial Residual";
282  static constexpr const char * label_default_ = "Belos";
283  static constexpr std::ostream * outputStream_default_ = &std::cout;
284 
285  // Current solver values.
286  MagnitudeType convtol_, impTolScale_, achievedTol_;
287  int maxIters_, numIters_;
288  int verbosity_, outputStyle_, outputFreq_, defQuorum_;
289  bool expResTest_;
290  std::string impResScale_, expResScale_;
291 
292  // Timers.
293  std::string label_;
294  Teuchos::RCP<Teuchos::Time> timerSolve_;
295 
296  // Internal state variables.
297  bool isSet_, isSTSet_;
298  };
299 
300 
301 // Empty Constructor
302 template<class ScalarType, class MV, class OP>
304  outputStream_(Teuchos::rcp(outputStream_default_,false)),
305  convtol_(DefaultSolverParameters::convTol),
306  impTolScale_(DefaultSolverParameters::impTolScale),
307  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
308  maxIters_(maxIters_default_),
309  numIters_(0),
310  verbosity_(verbosity_default_),
311  outputStyle_(outputStyle_default_),
312  outputFreq_(outputFreq_default_),
313  defQuorum_(defQuorum_default_),
314  expResTest_(expResTest_default_),
315  impResScale_(impResScale_default_),
316  expResScale_(expResScale_default_),
317  label_(label_default_),
318  isSet_(false),
319  isSTSet_(false)
320 {}
321 
322 
323 // Basic Constructor
324 template<class ScalarType, class MV, class OP>
326  const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem,
327  const Teuchos::RCP<Teuchos::ParameterList> &pl ) :
328  problem_(problem),
329  outputStream_(Teuchos::rcp(outputStream_default_,false)),
330  convtol_(DefaultSolverParameters::convTol),
331  impTolScale_(DefaultSolverParameters::impTolScale),
332  achievedTol_(Teuchos::ScalarTraits<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>::zero()),
333  maxIters_(maxIters_default_),
334  numIters_(0),
335  verbosity_(verbosity_default_),
336  outputStyle_(outputStyle_default_),
337  outputFreq_(outputFreq_default_),
338  defQuorum_(defQuorum_default_),
339  expResTest_(expResTest_default_),
340  impResScale_(impResScale_default_),
341  expResScale_(expResScale_default_),
342  label_(label_default_),
343  isSet_(false),
344  isSTSet_(false)
345 {
346  TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null, std::invalid_argument, "Problem not given to solver manager.");
347 
348  // If the parameter list pointer is null, then set the current parameters to the default parameter list.
349  if ( !is_null(pl) ) {
350  setParameters( pl );
351  }
352 }
353 
354 template<class ScalarType, class MV, class OP>
355 void PseudoBlockTFQMRSolMgr<ScalarType,MV,OP>::setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params )
356 {
357  // Create the internal parameter list if ones doesn't already exist.
358  if (params_ == Teuchos::null) {
359  params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) );
360  }
361  else {
362  params->validateParameters(*getValidParameters());
363  }
364 
365  // Check for maximum number of iterations
366  if (params->isParameter("Maximum Iterations")) {
367  maxIters_ = params->get("Maximum Iterations",maxIters_default_);
368 
369  // Update parameter in our list and in status test.
370  params_->set("Maximum Iterations", maxIters_);
371  if (maxIterTest_!=Teuchos::null)
372  maxIterTest_->setMaxIters( maxIters_ );
373  }
374 
375  // Check to see if the timer label changed.
376  if (params->isParameter("Timer Label")) {
377  std::string tempLabel = params->get("Timer Label", label_default_);
378 
379  // Update parameter in our list and solver timer
380  if (tempLabel != label_) {
381  label_ = tempLabel;
382  params_->set("Timer Label", label_);
383  std::string solveLabel = label_ + ": PseudoBlockTFQMRSolMgr total solve time";
384 #ifdef BELOS_TEUCHOS_TIME_MONITOR
385  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
386 #endif
387  }
388  }
389 
390  // Check for a change in verbosity level
391  if (params->isParameter("Verbosity")) {
392  if (Teuchos::isParameterType<int>(*params,"Verbosity")) {
393  verbosity_ = params->get("Verbosity", verbosity_default_);
394  } else {
395  verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity");
396  }
397 
398  // Update parameter in our list.
399  params_->set("Verbosity", verbosity_);
400  if (printer_ != Teuchos::null)
401  printer_->setVerbosity(verbosity_);
402  }
403 
404  // Check for a change in output style
405  if (params->isParameter("Output Style")) {
406  if (Teuchos::isParameterType<int>(*params,"Output Style")) {
407  outputStyle_ = params->get("Output Style", outputStyle_default_);
408  } else {
409  outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style");
410  }
411 
412  // Reconstruct the convergence test if the explicit residual test is not being used.
413  params_->set("Output Style", outputStyle_);
414  isSTSet_ = false;
415  }
416 
417  // output stream
418  if (params->isParameter("Output Stream")) {
419  outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream");
420 
421  // Update parameter in our list.
422  params_->set("Output Stream", outputStream_);
423  if (printer_ != Teuchos::null)
424  printer_->setOStream( outputStream_ );
425  }
426 
427  // frequency level
428  if (verbosity_ & Belos::StatusTestDetails) {
429  if (params->isParameter("Output Frequency")) {
430  outputFreq_ = params->get("Output Frequency", outputFreq_default_);
431  }
432 
433  // Update parameter in out list and output status test.
434  params_->set("Output Frequency", outputFreq_);
435  if (outputTest_ != Teuchos::null)
436  outputTest_->setOutputFrequency( outputFreq_ );
437  }
438 
439  // Create output manager if we need to.
440  if (printer_ == Teuchos::null) {
441  printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) );
442  }
443 
444  // Check for convergence tolerance
445  if (params->isParameter("Convergence Tolerance")) {
446  if (params->isType<MagnitudeType> ("Convergence Tolerance")) {
447  convtol_ = params->get ("Convergence Tolerance",
448  static_cast<MagnitudeType> (DefaultSolverParameters::convTol));
449  }
450  else {
451  convtol_ = params->get ("Convergence Tolerance", DefaultSolverParameters::convTol);
452  }
453 
454  // Update parameter in our list and residual tests.
455  params_->set("Convergence Tolerance", convtol_);
456  isSTSet_ = false;
457  }
458 
459  if (params->isParameter("Implicit Tolerance Scale Factor")) {
460  if (params->isType<MagnitudeType> ("Implicit Tolerance Scale Factor")) {
461  impTolScale_ = params->get ("Implicit Tolerance Scale Factor",
462  static_cast<MagnitudeType> (DefaultSolverParameters::impTolScale));
463 
464  }
465  else {
466  impTolScale_ = params->get ("Implicit Tolerance Scale Factor",
468  }
469 
470  // Update parameter in our list.
471  params_->set("Implicit Tolerance Scale Factor", impTolScale_);
472  isSTSet_ = false;
473  }
474 
475  if (params->isParameter("Implicit Residual Scaling")) {
476  std::string tempImpResScale = Teuchos::getParameter<std::string>( *params, "Implicit Residual Scaling" );
477 
478  // Only update the scaling if it's different.
479  if (impResScale_ != tempImpResScale) {
480  impResScale_ = tempImpResScale;
481 
482  // Update parameter in our list.
483  params_->set("Implicit Residual Scaling", impResScale_);
484  isSTSet_ = false;
485  }
486  }
487 
488  if (params->isParameter("Explicit Residual Scaling")) {
489  std::string tempExpResScale = Teuchos::getParameter<std::string>( *params, "Explicit Residual Scaling" );
490 
491  // Only update the scaling if it's different.
492  if (expResScale_ != tempExpResScale) {
493  expResScale_ = tempExpResScale;
494 
495  // Update parameter in our list.
496  params_->set("Explicit Residual Scaling", expResScale_);
497  isSTSet_ = false;
498  }
499  }
500 
501  if (params->isParameter("Explicit Residual Test")) {
502  expResTest_ = Teuchos::getParameter<bool>( *params,"Explicit Residual Test" );
503 
504  // Reconstruct the convergence test if the explicit residual test is not being used.
505  params_->set("Explicit Residual Test", expResTest_);
506  if (expConvTest_ == Teuchos::null) {
507  isSTSet_ = false;
508  }
509  }
510 
511  // Get the deflation quorum, or number of converged systems before deflation is allowed
512  if (params->isParameter("Deflation Quorum")) {
513  defQuorum_ = params->get("Deflation Quorum", defQuorum_);
514  params_->set ("Deflation Quorum", defQuorum_);
515  if (! impConvTest_.is_null ()) {
516  impConvTest_->setQuorum (defQuorum_);
517  }
518  if (! expConvTest_.is_null ()) {
519  expConvTest_->setQuorum (defQuorum_);
520  }
521  }
522 
523  // Create the timer if we need to.
524  if (timerSolve_ == Teuchos::null) {
525  std::string solveLabel = label_ + ": PseudoBlockTFQMRSolMgr total solve time";
526 #ifdef BELOS_TEUCHOS_TIME_MONITOR
527  timerSolve_ = Teuchos::TimeMonitor::getNewCounter(solveLabel);
528 #endif
529  }
530 
531  // Inform the solver manager that the current parameters were set.
532  isSet_ = true;
533 }
534 
535 
536 // Check the status test versus the defined linear problem
537 template<class ScalarType, class MV, class OP>
539 
540  typedef Belos::StatusTestCombo<ScalarType,MV,OP> StatusTestCombo_t;
541  typedef Belos::StatusTestGenResNorm<ScalarType,MV,OP> StatusTestGenResNorm_t;
542 
543  // Basic test checks maximum iterations and native residual.
544  maxIterTest_ = Teuchos::rcp( new StatusTestMaxIters<ScalarType,MV,OP>( maxIters_ ) );
545 
546  if (expResTest_) {
547 
548  // Implicit residual test, using the native residual to determine if convergence was achieved.
549  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
550  Teuchos::rcp( new StatusTestGenResNorm_t( impTolScale_*convtol_, defQuorum_ ) );
551  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
552  impConvTest_ = tmpImpConvTest;
553 
554  // Explicit residual test once the native residual is below the tolerance
555  Teuchos::RCP<StatusTestGenResNorm_t> tmpExpConvTest =
556  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
557  tmpExpConvTest->defineResForm( StatusTestGenResNorm_t::Explicit, Belos::TwoNorm );
558  tmpExpConvTest->defineScaleForm( convertStringToScaleType(expResScale_), Belos::TwoNorm );
559  expConvTest_ = tmpExpConvTest;
560 
561  // The convergence test is a combination of the "cheap" implicit test and explicit test.
562  convTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::SEQ, impConvTest_, expConvTest_ ) );
563  }
564  else {
565 
566  // Implicit residual test, using the native residual to determine if convergence was achieved.
567  Teuchos::RCP<StatusTestGenResNorm_t> tmpImpConvTest =
568  Teuchos::rcp( new StatusTestGenResNorm_t( convtol_, defQuorum_ ) );
569  tmpImpConvTest->defineScaleForm( convertStringToScaleType(impResScale_), Belos::TwoNorm );
570  impConvTest_ = tmpImpConvTest;
571 
572  // Set the explicit and total convergence test to this implicit test that checks for accuracy loss.
573  expConvTest_ = impConvTest_;
574  convTest_ = impConvTest_;
575  }
576  sTest_ = Teuchos::rcp( new StatusTestCombo_t( StatusTestCombo_t::OR, maxIterTest_, convTest_ ) );
577 
578  // Create the status test output class.
579  // This class manages and formats the output from the status test.
580  StatusTestOutputFactory<ScalarType,MV,OP> stoFactory( outputStyle_ );
581  outputTest_ = stoFactory.create( printer_, sTest_, outputFreq_, Passed+Failed+Undefined );
582 
583  // Set the solver string for the output test
584  std::string solverDesc = " Pseudo Block TFQMR ";
585  outputTest_->setSolverDesc( solverDesc );
586 
587 
588  // The status test is now set.
589  isSTSet_ = true;
590 
591  return false;
592 }
593 
594 
595 template<class ScalarType, class MV, class OP>
596 Teuchos::RCP<const Teuchos::ParameterList>
598 {
599  static Teuchos::RCP<const Teuchos::ParameterList> validPL;
600 
601  // Set all the valid parameters and their default values.
602  if(is_null(validPL)) {
603  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
604 
605  // The static_cast is to resolve an issue with older clang versions which
606  // would cause the constexpr to link fail. With c++17 the problem is resolved.
607  pl->set("Convergence Tolerance", static_cast<MagnitudeType>(DefaultSolverParameters::convTol),
608  "The relative residual tolerance that needs to be achieved by the\n"
609  "iterative solver in order for the linear system to be declared converged.");
610  pl->set("Implicit Tolerance Scale Factor", static_cast<MagnitudeType>(DefaultSolverParameters::impTolScale),
611  "The scale factor used by the implicit residual test when explicit residual\n"
612  "testing is used. May enable faster convergence when TFQMR bound is too loose.");
613  pl->set("Maximum Iterations", static_cast<int>(maxIters_default_),
614  "The maximum number of block iterations allowed for each\n"
615  "set of RHS solved.");
616  pl->set("Verbosity", static_cast<int>(verbosity_default_),
617  "What type(s) of solver information should be outputted\n"
618  "to the output stream.");
619  pl->set("Output Style", static_cast<int>(outputStyle_default_),
620  "What style is used for the solver information outputted\n"
621  "to the output stream.");
622  pl->set("Output Frequency", static_cast<int>(outputFreq_default_),
623  "How often convergence information should be outputted\n"
624  "to the output stream.");
625  pl->set("Deflation Quorum", static_cast<int>(defQuorum_default_),
626  "The number of linear systems that need to converge before they are deflated.");
627  pl->set("Output Stream", Teuchos::rcp(outputStream_default_,false),
628  "A reference-counted pointer to the output stream where all\n"
629  "solver output is sent.");
630  pl->set("Explicit Residual Test", static_cast<bool>(expResTest_default_),
631  "Whether the explicitly computed residual should be used in the convergence test.");
632  pl->set("Implicit Residual Scaling", static_cast<const char *>(impResScale_default_),
633  "The type of scaling used in the implicit residual convergence test.");
634  pl->set("Explicit Residual Scaling", static_cast<const char *>(expResScale_default_),
635  "The type of scaling used in the explicit residual convergence test.");
636  pl->set("Timer Label", static_cast<const char *>(label_default_),
637  "The string to use as a prefix for the timer labels.");
638  validPL = pl;
639  }
640  return validPL;
641 }
642 
643 
644 // solve()
645 template<class ScalarType, class MV, class OP>
647 
648  // Set the current parameters if they were not set before.
649  // NOTE: This may occur if the user generated the solver manager with the default constructor and
650  // then didn't set any parameters using setParameters().
651  if (!isSet_) {
652  setParameters(Teuchos::parameterList(*getValidParameters()));
653  }
654 
655  TEUCHOS_TEST_FOR_EXCEPTION(problem_ == Teuchos::null,PseudoBlockTFQMRSolMgrLinearProblemFailure,
656  "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not a valid object.");
657 
658  TEUCHOS_TEST_FOR_EXCEPTION(!problem_->isProblemSet(),PseudoBlockTFQMRSolMgrLinearProblemFailure,
659  "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called.");
660 
661  if (!isSTSet_) {
662  TEUCHOS_TEST_FOR_EXCEPTION( checkStatusTest(),PseudoBlockTFQMRSolMgrLinearProblemFailure,
663  "Belos::PseudoBlockTFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible.");
664  }
665 
666  // Create indices for the linear systems to be solved.
667  int startPtr = 0;
668  int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) );
669  int numCurrRHS = numRHS2Solve;
670 
671  std::vector<int> currIdx( numRHS2Solve );
672  for (int i=0; i<numRHS2Solve; ++i) {
673  currIdx[i] = startPtr+i;
674  }
675 
676  // Inform the linear problem of the current linear system to solve.
677  problem_->setLSIndex( currIdx );
678 
680  // Parameter list
681  Teuchos::ParameterList plist;
682 
683  // Reset the status test.
684  outputTest_->reset();
685 
686  // Assume convergence is achieved, then let any failed convergence set this to false.
687  bool isConverged = true;
688 
690  // TFQMR solver
691 
692  Teuchos::RCP<PseudoBlockTFQMRIter<ScalarType,MV,OP> > block_tfqmr_iter =
693  Teuchos::rcp( new PseudoBlockTFQMRIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,plist) );
694 
695  // Enter solve() iterations
696  {
697 #ifdef BELOS_TEUCHOS_TIME_MONITOR
698  Teuchos::TimeMonitor slvtimer(*timerSolve_);
699 #endif
700 
701  while ( numRHS2Solve > 0 ) {
702  //
703  // Reset the active / converged vectors from this block
704  std::vector<int> convRHSIdx;
705  std::vector<int> currRHSIdx( currIdx );
706  currRHSIdx.resize(numCurrRHS);
707 
708  // Reset the number of iterations.
709  block_tfqmr_iter->resetNumIters();
710 
711  // Reset the number of calls that the status test output knows about.
712  outputTest_->resetNumCalls();
713 
714  // Get the current residual for this block of linear systems.
715  Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx );
716 
717  // Set the new state and initialize the solver.
719  newstate.Rtilde = R_0;
720  block_tfqmr_iter->initializeTFQMR(newstate);
721 
722  while(1) {
723 
724  // tell block_tfqmr_iter to iterate
725  try {
726  block_tfqmr_iter->iterate();
727 
729  //
730  // check convergence first
731  //
733  if ( convTest_->getStatus() == Passed ) {
734 
735  // Figure out which linear systems converged.
736  std::vector<int> convIdx = expConvTest_->convIndices();
737 
738  // If the number of converged linear systems is equal to the
739  // number of current linear systems, then we are done with this block.
740  if (convIdx.size() == currRHSIdx.size())
741  break; // break from while(1){block_tfqmr_iter->iterate()}
742 
743  // Update the current solution with the update computed by the iteration object.
744  problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
745 
746  // Inform the linear problem that we are finished with this current linear system.
747  problem_->setCurrLS();
748 
749  // Reset currRHSIdx to have the right-hand sides that are left to converge for this block.
750  int have = 0;
751  std::vector<int> unconvIdx( currRHSIdx.size() );
752  for (unsigned int i=0; i<currRHSIdx.size(); ++i) {
753  bool found = false;
754  for (unsigned int j=0; j<convIdx.size(); ++j) {
755  if (currRHSIdx[i] == convIdx[j]) {
756  found = true;
757  break;
758  }
759  }
760  if (!found) {
761  unconvIdx[have] = i;
762  currRHSIdx[have++] = currRHSIdx[i];
763  }
764  }
765  unconvIdx.resize(have);
766  currRHSIdx.resize(have);
767 
768  // Set the remaining indices after deflation.
769  problem_->setLSIndex( currRHSIdx );
770 
771  // Get the current residual vector.
772  // Set the new state and initialize the solver.
773  PseudoBlockTFQMRIterState<ScalarType,MV> currentState = block_tfqmr_iter->getState();
774 
775  // Set the new state and initialize the solver.
777 
778  // Copy over the vectors.
779  defstate.Rtilde = MVT::CloneView( *currentState.Rtilde, unconvIdx);
780  defstate.U = MVT::CloneView( *currentState.U, unconvIdx );
781  defstate.AU = MVT::CloneView( *currentState.AU, unconvIdx );
782  defstate.V = MVT::CloneView( *currentState.V, unconvIdx );
783  defstate.W = MVT::CloneView( *currentState.W, unconvIdx );
784  defstate.D = MVT::CloneView( *currentState.D, unconvIdx );
785 
786  // Copy over the scalars.
787  for (std::vector<int>::iterator uIter = unconvIdx.begin(); uIter != unconvIdx.end(); uIter++)
788  {
789  defstate.alpha.push_back( currentState.alpha[ *uIter ] );
790  defstate.eta.push_back( currentState.eta[ *uIter ] );
791  defstate.rho.push_back( currentState.rho[ *uIter ] );
792  defstate.tau.push_back( currentState.tau[ *uIter ] );
793  defstate.theta.push_back( currentState.theta[ *uIter ] );
794  }
795 
796  block_tfqmr_iter->initializeTFQMR(defstate);
797  }
799  //
800  // check for maximum iterations
801  //
803  else if ( maxIterTest_->getStatus() == Passed ) {
804  // we don't have convergence
805  isConverged = false;
806  break; // break from while(1){block_tfqmr_iter->iterate()}
807  }
808 
810  //
811  // we returned from iterate(), but none of our status tests Passed.
812  // something is wrong, and it is probably our fault.
813  //
815 
816  else {
817  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
818  "Belos::PseudoBlockTFQMRSolMgr::solve(): Invalid return from PseudoBlockTFQMRIter::iterate().");
819  }
820  }
821  catch (const std::exception &e) {
822  printer_->stream(Errors) << "Error! Caught std::exception in PseudoBlockTFQMRIter::iterate() at iteration "
823  << block_tfqmr_iter->getNumIters() << std::endl
824  << e.what() << std::endl;
825  throw;
826  }
827  }
828 
829  // Update the current solution with the update computed by the iteration object.
830  problem_->updateSolution( block_tfqmr_iter->getCurrentUpdate(), true );
831 
832  // Inform the linear problem that we are finished with this block linear system.
833  problem_->setCurrLS();
834 
835  // Update indices for the linear systems to be solved.
836  startPtr += numCurrRHS;
837  numRHS2Solve -= numCurrRHS;
838  if ( numRHS2Solve > 0 ) {
839  numCurrRHS = numRHS2Solve;
840  currIdx.resize( numCurrRHS );
841  for (int i=0; i<numCurrRHS; ++i)
842  { currIdx[i] = startPtr+i; }
843 
844  // Adapt the status test quorum if we need to.
845  if (defQuorum_ > numCurrRHS) {
846  if (impConvTest_ != Teuchos::null)
847  impConvTest_->setQuorum( numCurrRHS );
848  if (expConvTest_ != Teuchos::null)
849  expConvTest_->setQuorum( numCurrRHS );
850  }
851 
852  // Set the next indices.
853  problem_->setLSIndex( currIdx );
854  }
855  else {
856  currIdx.resize( numRHS2Solve );
857  }
858 
859  }// while ( numRHS2Solve > 0 )
860 
861  }
862 
863  // print final summary
864  sTest_->print( printer_->stream(FinalSummary) );
865 
866  // print timing information
867 #ifdef BELOS_TEUCHOS_TIME_MONITOR
868  // Calling summarize() can be expensive, so don't call unless the
869  // user wants to print out timing details. summarize() will do all
870  // the work even if it's passed a "black hole" output stream.
871  if (verbosity_ & TimingDetails)
872  Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) );
873 #endif
874 
875  // get iteration information for this solve
876  numIters_ = maxIterTest_->getNumIters();
877 
878  // Save the convergence test value ("achieved tolerance") for this
879  // solve. For this solver, convTest_ may either be a single
880  // (implicit) residual norm test, or a combination of two residual
881  // norm tests. In the latter case, the master convergence test
882  // convTest_ is a SEQ combo of the implicit resp. explicit tests.
883  // If the implicit test never passes, then the explicit test won't
884  // ever be executed. This manifests as
885  // expConvTest_->getTestValue()->size() < 1. We deal with this case
886  // by using the values returned by impConvTest_->getTestValue().
887  {
888  // We'll fetch the vector of residual norms one way or the other.
889  const std::vector<MagnitudeType>* pTestValues = NULL;
890  if (expResTest_) {
891  pTestValues = expConvTest_->getTestValue();
892  if (pTestValues == NULL || pTestValues->size() < 1) {
893  pTestValues = impConvTest_->getTestValue();
894  }
895  }
896  else {
897  // Only the implicit residual norm test is being used.
898  pTestValues = impConvTest_->getTestValue();
899  }
900  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues == NULL, std::logic_error,
901  "Belos::PseudoBlockTFQMRSolMgr::solve(): The implicit convergence test's "
902  "getTestValue() method returned NULL. Please report this bug to the "
903  "Belos developers.");
904  TEUCHOS_TEST_FOR_EXCEPTION(pTestValues->size() < 1, std::logic_error,
905  "Belos::TMQMRSolMgr::solve(): The implicit convergence test's "
906  "getTestValue() method returned a vector of length zero. Please report "
907  "this bug to the Belos developers.");
908 
909  // FIXME (mfh 12 Dec 2011) Does pTestValues really contain the
910  // achieved tolerances for all vectors in the current solve(), or
911  // just for the vectors from the last deflation?
912  achievedTol_ = *std::max_element (pTestValues->begin(), pTestValues->end());
913  }
914 
915  if (!isConverged) {
916  return Unconverged; // return from PseudoBlockTFQMRSolMgr::solve()
917  }
918  return Converged; // return from PseudoBlockTFQMRSolMgr::solve()
919 }
920 
921 // This method requires the solver manager to return a std::string that describes itself.
922 template<class ScalarType, class MV, class OP>
924 {
925  std::ostringstream oss;
926  oss << "Belos::PseudoBlockTFQMRSolMgr<...,"<<Teuchos::ScalarTraits<ScalarType>::name()<<">";
927  oss << "{}";
928  return oss.str();
929 }
930 
931 } // end Belos namespace
932 
933 #endif /* BELOS_PSEUDO_BLOCK_TFQMR_SOLMGR_HPP */
BelosPseudoBlockTFQMRIter.hpp
Belos concrete class for generating iterations with the preconditioned tranpose-free QMR (TFQMR) meth...
Belos::PseudoBlockTFQMRSolMgr::description
std::string description() const override
Method to return description of the pseudo-block TFQMR solver manager.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:923
Belos::PseudoBlockTFQMRIterState::Rtilde
Teuchos::RCP< const MV > Rtilde
Definition: BelosPseudoBlockTFQMRIter.hpp:102
Belos::PseudoBlockTFQMRSolMgr::~PseudoBlockTFQMRSolMgr
virtual ~PseudoBlockTFQMRSolMgr()
Destructor.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:145
Belos::PseudoBlockTFQMRSolMgr::getCurrentParameters
Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const override
Get a parameter list containing the current parameters for this object.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:166
Belos::PseudoBlockTFQMRSolMgrLinearProblemFailure::PseudoBlockTFQMRSolMgrLinearProblemFailure
PseudoBlockTFQMRSolMgrLinearProblemFailure(const std::string &what_arg)
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:90
BelosConfigDefs.hpp
Belos header file which uses auto-configuration information to include necessary C++ headers.
Belos::PseudoBlockTFQMRSolMgr::solve
ReturnType solve() override
This method performs possibly repeated calls to the underlying linear solver's iterate() routine unti...
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:646
Belos::OperatorTraits
Class which defines basic traits for the operator type.
Definition: BelosOperatorTraits.hpp:109
Belos::DefaultSolverParameters
Default parameters common to most Belos solvers.
Definition: BelosTypes.hpp:286
Belos::OutputManager
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Definition: BelosIteration.hpp:64
BelosLinearProblem.hpp
Class which describes the linear problem to be solved by the iterative solver.
Belos::PseudoBlockTFQMRIter
This class implements the preconditioned transpose-free QMR algorithm for solving non-Hermitian linea...
Definition: BelosPseudoBlockTFQMRIter.hpp:147
Belos::PseudoBlockTFQMRSolMgr::reset
void reset(const ResetType type) override
Performs a reset of the solver manager specified by the ResetType. This informs the solver manager th...
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:218
Belos::General
Definition: BelosTypes.hpp:140
Belos::PseudoBlockTFQMRIterState::alpha
std::vector< ScalarType > alpha
Definition: BelosPseudoBlockTFQMRIter.hpp:105
Belos::TimingDetails
Definition: BelosTypes.hpp:263
Belos::PseudoBlockTFQMRSolMgr::getTimers
Teuchos::Array< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return the timers for this object.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:173
Belos::StatusTestMaxIters
A Belos::StatusTest class for specifying a maximum number of iterations.
Definition: BelosStatusTestMaxIters.hpp:63
BelosSolverManager.hpp
Pure virtual base class which describes the basic interface for a solver manager.
Belos::Passed
Definition: BelosTypes.hpp:188
Belos::StatusTestDetails
Definition: BelosTypes.hpp:264
Belos::TwoNorm
Definition: BelosTypes.hpp:98
Belos::FinalSummary
Definition: BelosTypes.hpp:262
Belos::LinearProblem
A linear system to solve, and its associated information.
Definition: BelosIteration.hpp:61
BelosStatusTestGenResNorm.hpp
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
Belos::PseudoBlockTFQMRSolMgr::achievedTol
MagnitudeType achievedTol() const override
Tolerance achieved by the last solve() invocation.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:182
BelosOutputManager.hpp
Class which manages the output and verbosity of the Belos solvers.
Belos::PseudoBlockTFQMRIterState::theta
std::vector< MagnitudeType > theta
Definition: BelosPseudoBlockTFQMRIter.hpp:106
Belos
Definition: Belos_Details_EBelosSolverType.cpp:45
Belos::PseudoBlockTFQMRIterState::AU
Teuchos::RCP< const MV > AU
Definition: BelosPseudoBlockTFQMRIter.hpp:101
BelosStatusTestMaxIters.hpp
Belos::StatusTest class for specifying a maximum number of iterations.
Belos::Undefined
Definition: BelosTypes.hpp:190
Belos::PseudoBlockTFQMRSolMgr::setParameters
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the parameters the solver manager should use to solve the linear problem.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:355
Belos::PseudoBlockTFQMRSolMgrLinearProblemFailure
PseudoBlockTFQMRSolMgrLinearProblemFailure is thrown when the linear problem is not setup (i....
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:89
Belos::PseudoBlockTFQMRIterState::U
Teuchos::RCP< const MV > U
Definition: BelosPseudoBlockTFQMRIter.hpp:100
Belos::PseudoBlockTFQMRSolMgr
The Belos::PseudoBlockTFQMRSolMgr provides a powerful and fully-featured solver manager over the pseu...
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:104
Belos::PseudoBlockTFQMRSolMgr::getValidParameters
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Get a parameter list containing the valid parameters for this object.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:597
Belos::StatusTestGenResNorm
An implementation of StatusTestResNorm using a family of residual norms.
Definition: BelosStatusTestGenResNorm.hpp:79
Belos::Problem
Definition: BelosTypes.hpp:205
Belos::PseudoBlockTFQMRIterState::eta
std::vector< ScalarType > eta
Definition: BelosPseudoBlockTFQMRIter.hpp:105
Belos::ReturnType
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:154
Belos::Unconverged
Definition: BelosTypes.hpp:156
Belos::PseudoBlockTFQMRIterState
Structure to contain pointers to PseudoBlockTFQMRIter state variables.
Definition: BelosPseudoBlockTFQMRIter.hpp:93
Belos::PseudoBlockTFQMRSolMgrOrthoFailure
PseudoBlockTFQMRSolMgrOrthoFailure is thrown when the orthogonalization manager is unable to generate...
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:99
Belos::convertStringToScaleType
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:88
Belos::PseudoBlockTFQMRIterState::rho
std::vector< ScalarType > rho
Definition: BelosPseudoBlockTFQMRIter.hpp:105
Belos::PseudoBlockTFQMRSolMgr::getProblem
const LinearProblem< ScalarType, MV, OP > & getProblem() const override
Return a reference to the linear problem being solved by this solver manager.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:156
Belos::ResetType
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:205
Belos::PseudoBlockTFQMRIterState::tau
std::vector< MagnitudeType > tau
Definition: BelosPseudoBlockTFQMRIter.hpp:106
Belos::PseudoBlockTFQMRSolMgr::setProblem
void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem) override
Set the linear problem that needs to be solved.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:205
Belos::PseudoBlockTFQMRSolMgrOrthoFailure::PseudoBlockTFQMRSolMgrOrthoFailure
PseudoBlockTFQMRSolMgrOrthoFailure(const std::string &what_arg)
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:100
Belos::PseudoBlockTFQMRSolMgr::isLOADetected
bool isLOADetected() const override
Whether loss of accuracy was detected during the last solve() invocation.
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:198
Belos::PseudoBlockTFQMRSolMgr::getNumIters
int getNumIters() const override
Get the iteration count for the most recent call to solve().
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:187
Belos::BelosError
Parent class to all Belos exceptions.
Definition: BelosTypes.hpp:60
Belos::StatusTestCombo
A class for extending the status testing capabilities of Belos via logical combinations.
Definition: BelosStatusTestCombo.hpp:91
Belos::PseudoBlockTFQMRIterState::D
Teuchos::RCP< const MV > D
Definition: BelosPseudoBlockTFQMRIter.hpp:103
BelosTypes.hpp
Collection of types and exceptions used within the Belos solvers.
Belos::DefaultSolverParameters::convTol
static constexpr double convTol
Default convergence tolerance.
Definition: BelosTypes.hpp:294
Belos::PseudoBlockTFQMRIterState::W
Teuchos::RCP< const MV > W
The current residual basis.
Definition: BelosPseudoBlockTFQMRIter.hpp:99
Belos::Converged
Definition: BelosTypes.hpp:155
Belos::Errors
Definition: BelosTypes.hpp:258
Belos::SolverManager
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Definition: BelosSolverManager.hpp:72
Belos::DefaultSolverParameters::impTolScale
static constexpr double impTolScale
"Implicit Tolerance Scale Factor"
Definition: BelosTypes.hpp:306
BelosStatusTestOutputFactory.hpp
A factory class for generating StatusTestOutput objects.
Belos::PseudoBlockTFQMRIterState::V
Teuchos::RCP< const MV > V
Definition: BelosPseudoBlockTFQMRIter.hpp:104
Belos::Failed
Definition: BelosTypes.hpp:189
Belos::PseudoBlockTFQMRSolMgr::PseudoBlockTFQMRSolMgr
PseudoBlockTFQMRSolMgr()
Empty constructor for PseudoBlockTFQMRSolMgr. This constructor takes no arguments and sets the defaul...
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:303
Belos::PseudoBlockTFQMRSolMgr::clone
Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const override
clone for Inverted Injection (DII)
Definition: BelosPseudoBlockTFQMRSolMgr.hpp:148
Belos::MultiVecTraits
Traits class which defines basic operations on multivectors.
Definition: BelosMultiVecTraits.hpp:129
BelosStatusTestCombo.hpp
Belos::StatusTest for logically combining several status tests.

Generated on Thu Feb 27 2020 16:06:46 for Belos by doxygen 1.8.16