Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_BelosLinearOpWithSolve_def.hpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Stratimikos: Thyra-based strategies for linear solvers
6 // Copyright (2006) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 
45 #ifndef THYRA_BELOS_LINEAR_OP_WITH_SOLVE_HPP
46 #define THYRA_BELOS_LINEAR_OP_WITH_SOLVE_HPP
47 
49 #include "Thyra_GeneralSolveCriteriaBelosStatusTest.hpp"
50 #include "Thyra_LinearOpWithSolveHelpers.hpp"
52 #include "Teuchos_Assert.hpp"
53 #include "Teuchos_TimeMonitor.hpp"
54 
55 namespace {
56  // Set the Belos solver's parameter list to scale its residual norms
57  // in the specified way.
58  //
59  // We break this out in a separate function because the parameters
60  // to set depend on which parameters the Belos solver supports. Not
61  // all Belos solvers support both the "Implicit Residual Scaling"
62  // and "Explicit Residual Scaling" parameters, so we have to check
63  // the solver's list of valid parameters for the existence of these.
64  //
65  // Scaling options: Belos lets you decide whether the solver will
66  // scale residual norms by the (left-)preconditioned initial
67  // residual norms (residualScalingType = "Norm of Initial
68  // Residual"), or by the unpreconditioned initial residual norms
69  // (residualScalingType = "Norm of RHS"). Usually you want to scale
70  // by the unpreconditioned initial residual norms. This is because
71  // preconditioning is just an optimization, and you really want to
72  // make ||B - AX|| small, rather than ||M B - M (A X)||. If you're
73  // measuring ||B - AX|| and scaling by the initial residual, you
74  // should use the unpreconditioned initial residual to match it.
75  //
76  // Note, however, that the implicit residual test computes
77  // left-preconditioned residuals, if a left preconditioner was
78  // provided. That's OK because when Belos solvers (at least the
79  // GMRES variants) are given a left preconditioner, they first check
80  // the implicit residuals. If those converge, they then check the
81  // explicit residuals. The explicit residual test does _not_ apply
82  // the left preconditioner when computing the residual. The
83  // implicit residual test is just an optimization so that Belos
84  // doesn't have to compute explicit residuals B - A*X at every
85  // iteration. This is why we use the same scaling factor for both
86  // the implicit and explicit residuals.
87  //
88  // Arguments:
89  //
90  // solverParams [in/out] Parameters for the current solve.
91  //
92  // solverValidParams [in] Valid parameter list for the Belos solver.
93  // Result of calling the solver's getValidParameters() method.
94  //
95  // residualScalingType [in] String describing how the solver should
96  // scale residuals. Valid values include "Norm of RHS" and "Norm
97  // of Initial Residual" (these are the only two options this file
98  // currently uses, though Belos offers other options).
99  void
100  setResidualScalingType (const Teuchos::RCP<Teuchos::ParameterList>& solverParams,
101  const Teuchos::RCP<const Teuchos::ParameterList>& solverValidParams,
102  const std::string& residualScalingType)
103  {
104  // Many Belos solvers (especially the GMRES variants) define both
105  // "Implicit Residual Scaling" and "Explicit Residual Scaling"
106  // options.
107  //
108  // "Implicit" means "the left-preconditioned approximate
109  // a.k.a. 'recursive' residual as computed by the Krylov method."
110  //
111  // "Explicit" means ||B - A*X||, the unpreconditioned, "exact"
112  // residual.
113  //
114  // Belos' GMRES implementations chain these two tests in sequence.
115  // Implicit comes first, and explicit is not evaluated unless
116  // implicit passes. In some cases (e.g., no left preconditioner),
117  // GMRES _only_ uses the implicit tests. This means that only
118  // setting "Explicit Residual Scaling" won't change the solver's
119  // behavior. Stratimikos tends to prefer using a right
120  // preconditioner, in which case setting only the "Explicit
121  // Residual Scaling" argument has no effect. Furthermore, if
122  // "Explicit Residual Scaling" is set to something other than the
123  // default (initial residual norm), without "Implicit Residual
124  // Scaling" getting the same setting, then the implicit residual
125  // test will be using a radically different scaling factor than
126  // the user wanted.
127  //
128  // Not all Belos solvers support both options. We check the
129  // solver's valid parameter list first before attempting to set
130  // the option.
131  if (solverValidParams->isParameter ("Implicit Residual Scaling")) {
132  solverParams->set ("Implicit Residual Scaling", residualScalingType);
133  }
134  if (solverValidParams->isParameter ("Explicit Residual Scaling")) {
135  solverParams->set ("Explicit Residual Scaling", residualScalingType);
136  }
137  }
138 
139 } // namespace (anonymous)
140 
141 
142 namespace Thyra {
143 
144 
145 // Constructors/initializers/accessors
146 
147 
148 template<class Scalar>
150  :convergenceTestFrequency_(-1),
151  isExternalPrec_(false),
152  supportSolveUse_(SUPPORT_SOLVE_UNSPECIFIED),
153  defaultTol_(-1.0)
154 {}
155 
156 
157 template<class Scalar>
159  const RCP<Belos::LinearProblem<Scalar,MV_t,LO_t> > &lp,
160  const RCP<Teuchos::ParameterList> &solverPL,
161  const RCP<Belos::SolverManager<Scalar,MV_t,LO_t> > &iterativeSolver,
162  const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
163  const RCP<const PreconditionerBase<Scalar> > &prec,
164  const bool isExternalPrec,
165  const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
166  const ESupportSolveUse &supportSolveUse,
167  const int convergenceTestFrequency
168  )
169 {
170  this->setLinePrefix("BELOS/T");
171  // ToDo: Validate input
172  lp_ = lp;
173  solverPL_ = solverPL;
174  iterativeSolver_ = iterativeSolver;
175  fwdOpSrc_ = fwdOpSrc;
176  prec_ = prec;
177  isExternalPrec_ = isExternalPrec;
178  approxFwdOpSrc_ = approxFwdOpSrc;
179  supportSolveUse_ = supportSolveUse;
180  convergenceTestFrequency_ = convergenceTestFrequency;
181  // Check if "Convergence Tolerance" is in the solver parameter list. If
182  // not, use the default from the solver.
183  if ( !is_null(solverPL_) ) {
184  if (solverPL_->isParameter("Convergence Tolerance")) {
185  defaultTol_ = solverPL_->get<double>("Convergence Tolerance");
186  }
187  }
188  else {
190  iterativeSolver->getValidParameters();
191  defaultTol_ = defaultPL->get<double>("Convergence Tolerance");
192  }
193 }
194 
195 
196 template<class Scalar>
199 {
201  _fwdOpSrc = fwdOpSrc_;
202  fwdOpSrc_ = Teuchos::null;
203  return _fwdOpSrc;
204 }
205 
206 
207 template<class Scalar>
210 {
212  _prec = prec_;
213  prec_ = Teuchos::null;
214  return _prec;
215 }
216 
217 
218 template<class Scalar>
220 {
221  return isExternalPrec_;
222 }
223 
224 
225 template<class Scalar>
228 {
230  _approxFwdOpSrc = approxFwdOpSrc_;
231  approxFwdOpSrc_ = Teuchos::null;
232  return _approxFwdOpSrc;
233 }
234 
235 
236 template<class Scalar>
238 {
239  return supportSolveUse_;
240 }
241 
242 
243 template<class Scalar>
245  RCP<Belos::LinearProblem<Scalar,MV_t,LO_t> > *lp,
246  RCP<Teuchos::ParameterList> *solverPL,
247  RCP<Belos::SolverManager<Scalar,MV_t,LO_t> > *iterativeSolver,
248  RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
249  RCP<const PreconditionerBase<Scalar> > *prec,
250  bool *isExternalPrec,
251  RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
252  ESupportSolveUse *supportSolveUse
253  )
254 {
255  if (lp) *lp = lp_;
256  if (solverPL) *solverPL = solverPL_;
257  if (iterativeSolver) *iterativeSolver = iterativeSolver_;
258  if (fwdOpSrc) *fwdOpSrc = fwdOpSrc_;
259  if (prec) *prec = prec_;
260  if (isExternalPrec) *isExternalPrec = isExternalPrec_;
261  if (approxFwdOpSrc) *approxFwdOpSrc = approxFwdOpSrc_;
262  if (supportSolveUse) *supportSolveUse = supportSolveUse_;
263 
264  lp_ = Teuchos::null;
265  solverPL_ = Teuchos::null;
266  iterativeSolver_ = Teuchos::null;
267  fwdOpSrc_ = Teuchos::null;
268  prec_ = Teuchos::null;
269  isExternalPrec_ = false;
270  approxFwdOpSrc_ = Teuchos::null;
271  supportSolveUse_ = SUPPORT_SOLVE_UNSPECIFIED;
272 }
273 
274 
275 // Overridden from LinearOpBase
276 
277 
278 template<class Scalar>
281 {
282  if (!is_null(lp_))
283  return lp_->getOperator()->range();
284  return Teuchos::null;
285 }
286 
287 
288 template<class Scalar>
291 {
292  if (!is_null(lp_))
293  return lp_->getOperator()->domain();
294  return Teuchos::null;
295 }
296 
297 
298 template<class Scalar>
301 {
302  return Teuchos::null; // Not supported yet but could be
303 }
304 
305 
306 // Overridden from Teuchos::Describable
307 
308 
309 template<class Scalar>
311 {
312  std::ostringstream oss;
314  if ( !is_null(lp_) && !is_null(lp_->getOperator()) ) {
315  oss << "{";
316  oss << "iterativeSolver=\'"<<iterativeSolver_->description()<<"\'";
317  oss << ",fwdOp=\'"<<lp_->getOperator()->description()<<"\'";
318  if (lp_->getLeftPrec().get())
319  oss << ",leftPrecOp=\'"<<lp_->getLeftPrec()->description()<<"\'";
320  if (lp_->getRightPrec().get())
321  oss << ",rightPrecOp=\'"<<lp_->getRightPrec()->description()<<"\'";
322  oss << "}";
323  }
324  // ToDo: Make Belos::SolverManager derive from Teuchos::Describable so
325  // that we can get better information.
326  return oss.str();
327 }
328 
329 
330 template<class Scalar>
332  Teuchos::FancyOStream &out_arg,
333  const Teuchos::EVerbosityLevel verbLevel
334  ) const
335 {
336  using Teuchos::FancyOStream;
337  using Teuchos::OSTab;
338  using Teuchos::describe;
339  RCP<FancyOStream> out = rcp(&out_arg,false);
340  OSTab tab(out);
341  switch (verbLevel) {
343  case Teuchos::VERB_LOW:
344  *out << this->description() << std::endl;
345  break;
347  case Teuchos::VERB_HIGH:
349  {
350  *out
352  << "rangeDim=" << this->range()->dim()
353  << ",domainDim=" << this->domain()->dim() << "}\n";
354  if (lp_->getOperator().get()) {
355  OSTab tab(out);
356  *out
357  << "iterativeSolver = "<<describe(*iterativeSolver_,verbLevel)
358  << "fwdOp = " << describe(*lp_->getOperator(),verbLevel);
359  if (lp_->getLeftPrec().get())
360  *out << "leftPrecOp = "<<describe(*lp_->getLeftPrec(),verbLevel);
361  if (lp_->getRightPrec().get())
362  *out << "rightPrecOp = "<<describe(*lp_->getRightPrec(),verbLevel);
363  }
364  break;
365  }
366  default:
367  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
368  }
369 }
370 
371 
372 // protected
373 
374 
375 // Overridden from LinearOpBase
376 
377 
378 template<class Scalar>
380 {
381  return ::Thyra::opSupported(*lp_->getOperator(),M_trans);
382 }
383 
384 
385 template<class Scalar>
387  const EOpTransp M_trans,
388  const MultiVectorBase<Scalar> &X,
389  const Ptr<MultiVectorBase<Scalar> > &Y,
390  const Scalar alpha,
391  const Scalar beta
392  ) const
393 {
394  ::Thyra::apply<Scalar>(*lp_->getOperator(), M_trans, X, Y, alpha, beta);
395 }
396 
397 
398 // Overridden from LinearOpWithSolveBase
399 
400 
401 template<class Scalar>
402 bool
404 {
405  return solveSupportsNewImpl(M_trans, Teuchos::null);
406 }
407 
408 
409 template<class Scalar>
410 bool
412  const Ptr<const SolveCriteria<Scalar> > solveCriteria) const
413 {
414  // Only support forward solve right now!
415  if (real_trans(transp)==NOTRANS) return true;
416  return false; // ToDo: Support adjoint solves!
417  // Otherwise, Thyra/Belos now supports every solve criteria type that exists
418  // because of the class Thyra::GeneralSolveCriteriaBelosStatusTest!
419  return true;
420 /*
421  if (real_trans(M_trans)==NOTRANS) {
422  return (
423  solveMeasureType.useDefault()
424  ||
425  solveMeasureType(SOLVE_MEASURE_NORM_RESIDUAL,SOLVE_MEASURE_NORM_RHS)
426  ||
427  solveMeasureType(SOLVE_MEASURE_NORM_RESIDUAL,SOLVE_MEASURE_NORM_INIT_RESIDUAL)
428  );
429  }
430 */
431 }
432 
433 
434 template<class Scalar>
435 bool
437  EOpTransp M_trans, const SolveMeasureType& solveMeasureType) const
438 {
439  SolveCriteria<Scalar> solveCriteria(solveMeasureType, SolveCriteria<Scalar>::unspecifiedTolerance());
440  return solveSupportsNewImpl(M_trans, Teuchos::constOptInArg(solveCriteria));
441 }
442 
443 
444 template<class Scalar>
445 SolveStatus<Scalar>
447  const EOpTransp M_trans,
448  const MultiVectorBase<Scalar> &B,
449  const Ptr<MultiVectorBase<Scalar> > &X,
450  const Ptr<const SolveCriteria<Scalar> > solveCriteria
451  ) const
452 {
453 
454  THYRA_FUNC_TIME_MONITOR("Stratimikos: BelosLOWS");
455 
456  using Teuchos::rcp;
457  using Teuchos::rcpFromRef;
458  using Teuchos::rcpFromPtr;
459  using Teuchos::FancyOStream;
460  using Teuchos::OSTab;
462  using Teuchos::parameterList;
463  using Teuchos::describe;
465  typedef typename ST::magnitudeType ScalarMag;
466  Teuchos::Time totalTimer(""), timer("");
467  totalTimer.start(true);
468 
469  assertSolveSupports(*this, M_trans, solveCriteria);
470  // 2010/08/22: rabartl: Bug 4915 ToDo: Move the above into the NIV function
471  // solve(...).
472 
473  const RCP<FancyOStream> out = this->getOStream();
474  const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
475  OSTab tab = this->getOSTab();
476  if (out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW)) {
477  *out << "\nStarting iterations with Belos:\n";
478  OSTab tab2(out);
479  *out << "Using forward operator = " << describe(*fwdOpSrc_->getOp(),verbLevel);
480  *out << "Using iterative solver = " << describe(*iterativeSolver_,verbLevel);
481  *out << "With #Eqns="<<B.range()->dim()<<", #RHSs="<<B.domain()->dim()<<" ...\n";
482  }
483 
484  //
485  // Set RHS and LHS
486  //
487 
488  bool ret = lp_->setProblem( rcpFromPtr(X), rcpFromRef(B) );
490  ret == false, CatastrophicSolveFailure
491  ,"Error, the Belos::LinearProblem could not be set for the current solve!"
492  );
493 
494  //
495  // Set the solution criteria
496  //
497 
498  // Parameter list for the current solve.
499  const RCP<ParameterList> tmpPL = Teuchos::parameterList();
500 
501  // The solver's valid parameter list.
502  RCP<const ParameterList> validPL = iterativeSolver_->getValidParameters();
503 
504  SolveMeasureType solveMeasureType;
505  RCP<GeneralSolveCriteriaBelosStatusTest<Scalar> > generalSolveCriteriaBelosStatusTest;
506  if (nonnull(solveCriteria)) {
507  solveMeasureType = solveCriteria->solveMeasureType;
508  const ScalarMag requestedTol = solveCriteria->requestedTol;
509  if (solveMeasureType.useDefault()) {
510  tmpPL->set("Convergence Tolerance", defaultTol_);
511  }
512  else if (solveMeasureType(SOLVE_MEASURE_NORM_RESIDUAL, SOLVE_MEASURE_NORM_RHS)) {
513  if (requestedTol != SolveCriteria<Scalar>::unspecifiedTolerance()) {
514  tmpPL->set("Convergence Tolerance", requestedTol);
515  }
516  else {
517  tmpPL->set("Convergence Tolerance", defaultTol_);
518  }
519  setResidualScalingType (tmpPL, validPL, "Norm of RHS");
520  }
521  else if (solveMeasureType(SOLVE_MEASURE_NORM_RESIDUAL, SOLVE_MEASURE_NORM_INIT_RESIDUAL)) {
522  if (requestedTol != SolveCriteria<Scalar>::unspecifiedTolerance()) {
523  tmpPL->set("Convergence Tolerance", requestedTol);
524  }
525  else {
526  tmpPL->set("Convergence Tolerance", defaultTol_);
527  }
528  setResidualScalingType (tmpPL, validPL, "Norm of Initial Residual");
529  }
530  else {
531  // Set the most generic (and inefficient) solve criteria
532  generalSolveCriteriaBelosStatusTest = createGeneralSolveCriteriaBelosStatusTest(
533  *solveCriteria, convergenceTestFrequency_);
534  // Set the verbosity level (one level down)
535  generalSolveCriteriaBelosStatusTest->setOStream(out);
536  generalSolveCriteriaBelosStatusTest->setVerbLevel(incrVerbLevel(verbLevel, -1));
537  // Set the default convergence tolerance to always converged to allow
538  // the above status test to control things.
539  tmpPL->set("Convergence Tolerance", 1.0);
540  }
541  // maximum iterations
542  if (nonnull(solveCriteria->extraParameters)) {
543  if (Teuchos::isParameterType<int>(*solveCriteria->extraParameters,"Maximum Iterations")) {
544  tmpPL->set("Maximum Iterations", Teuchos::get<int>(*solveCriteria->extraParameters,"Maximum Iterations"));
545  }
546  }
547  }
548  else {
549  // No solveCriteria was even passed in!
550  tmpPL->set("Convergence Tolerance", defaultTol_);
551  }
552 
553  //
554  // Solve the linear system
555  //
556 
557  Belos::ReturnType belosSolveStatus;
558  {
560  outUsed =
561  ( static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_LOW)
562  ? out
564  );
565  Teuchos::OSTab tab(outUsed,1,"BELOS");
566  tmpPL->set("Output Stream", outUsed);
567  iterativeSolver_->setParameters(tmpPL);
568  if (nonnull(generalSolveCriteriaBelosStatusTest)) {
569  iterativeSolver_->setUserConvStatusTest(generalSolveCriteriaBelosStatusTest);
570  }
571  belosSolveStatus = iterativeSolver_->solve();
572  }
573 
574  //
575  // Report the solve status
576  //
577 
578  totalTimer.stop();
579 
580  SolveStatus<Scalar> solveStatus;
581 
582  switch (belosSolveStatus) {
583  case Belos::Unconverged: {
584  solveStatus.solveStatus = SOLVE_STATUS_UNCONVERGED;
585  // Set achievedTol even if the solver did not converge. This is
586  // helpful for things like nonlinear solvers, which might be
587  // able to use a partially converged result, and which would
588  // like to know the achieved convergence tolerance for use in
589  // computing bounds. It's also helpful for estimating whether a
590  // small increase in the maximum iteration count might be
591  // helpful next time.
592  try {
593  // Some solvers might not have implemented achievedTol().
594  // The default implementation throws std::runtime_error.
595  solveStatus.achievedTol = iterativeSolver_->achievedTol();
596  } catch (std::runtime_error&) {
597  // Do nothing; use the default value of achievedTol.
598  }
599  break;
600  }
601  case Belos::Converged: {
602  solveStatus.solveStatus = SOLVE_STATUS_CONVERGED;
603  if (nonnull(generalSolveCriteriaBelosStatusTest)) {
604  // The user set a custom status test. This means that we
605  // should ask the custom status test itself, rather than the
606  // Belos solver, what the final achieved convergence tolerance
607  // was.
608  const ArrayView<const ScalarMag> achievedTol =
609  generalSolveCriteriaBelosStatusTest->achievedTol();
610  solveStatus.achievedTol = ST::zero();
611  for (Ordinal i = 0; i < achievedTol.size(); ++i) {
612  solveStatus.achievedTol = std::max(solveStatus.achievedTol, achievedTol[i]);
613  }
614  }
615  else {
616  try {
617  // Some solvers might not have implemented achievedTol().
618  // The default implementation throws std::runtime_error.
619  solveStatus.achievedTol = iterativeSolver_->achievedTol();
620  } catch (std::runtime_error&) {
621  // Use the default convergence tolerance. This is a correct
622  // upper bound, since we did actually converge.
623  solveStatus.achievedTol = tmpPL->get("Convergence Tolerance", defaultTol_);
624  }
625  }
626  break;
627  }
629  }
630 
631  std::ostringstream ossmessage;
632  ossmessage
633  << "The Belos solver of type \""<<iterativeSolver_->description()
634  <<"\" returned a solve status of \""<< toString(solveStatus.solveStatus) << "\""
635  << " in " << iterativeSolver_->getNumIters() << " iterations"
636  << " with total CPU time of " << totalTimer.totalElapsedTime() << " sec" ;
637  if (out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_NONE))
638  *out << "\n" << ossmessage.str() << "\n";
639 
640  solveStatus.message = ossmessage.str();
641 
642  // Dump the getNumIters() and the achieved convergence tolerance
643  // into solveStatus.extraParameters, as the "Belos/Iteration Count"
644  // resp. "Belos/Achieved Tolerance" parameters.
645  if (solveStatus.extraParameters.is_null()) {
646  solveStatus.extraParameters = parameterList ();
647  }
648  solveStatus.extraParameters->set ("Belos/Iteration Count",
649  iterativeSolver_->getNumIters());\
650  // package independent version of the same
651  solveStatus.extraParameters->set ("Iteration Count",
652  iterativeSolver_->getNumIters());\
653  // NOTE (mfh 13 Dec 2011) Though the most commonly used Belos
654  // solvers do implement achievedTol(), some Belos solvers currently
655  // do not. In the latter case, if the solver did not converge, the
656  // reported achievedTol() value may just be the default "invalid"
657  // value -1, and if the solver did converge, the reported value will
658  // just be the convergence tolerance (a correct upper bound).
659  solveStatus.extraParameters->set ("Belos/Achieved Tolerance",
660  solveStatus.achievedTol);
661 
662 // This information is in the previous line, which is printed anytime the verbosity
663 // is not set to Teuchos::VERB_NONE, so I'm commenting this out for now.
664 // if (out.get() && static_cast<int>(verbLevel) > static_cast<int>(Teuchos::VERB_NONE))
665 // *out << "\nTotal solve time in Belos = "<<totalTimer.totalElapsedTime()<<" sec\n";
666 
667  return solveStatus;
668 
669 }
670 
671 
672 } // end namespace Thyra
673 
674 
675 #endif // THYRA_BELOS_LINEAR_OP_WITH_SOLVE_HPP
virtual bool solveSupportsImpl(EOpTransp M_trans) const
RCP< const VectorSpaceBase< Scalar > > domain() const
const std::string toString(const EAdjointEpetraOp adjointEpetraOp)
bool is_null(const boost::shared_ptr< T > &p)
virtual SolveStatus< Scalar > solveImpl(const EOpTransp transp, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > > solveCriteria) const
RCP< const LinearOpSourceBase< Scalar > > extract_approxFwdOpSrc()
T & get(ParameterList &l, const std::string &name)
void initialize(const RCP< Belos::LinearProblem< Scalar, MV_t, LO_t > > &lp, const RCP< Teuchos::ParameterList > &solverPL, const RCP< Belos::SolverManager< Scalar, MV_t, LO_t > > &iterativeSolver, const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const PreconditionerBase< Scalar > > &prec, const bool isExternalPrec, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, const ESupportSolveUse &supportSolveUse, const int convergenceTestFrequency)
Initializes given precreated solver objects.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< const PreconditionerBase< Scalar > > extract_prec()
virtual bool solveSupportsNewImpl(EOpTransp transp, const Ptr< const SolveCriteria< Scalar > > solveCriteria) const
T * get() const
RCP< const VectorSpaceBase< Scalar > > range() const
virtual void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
basic_OSTab< char > OSTab
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEUCHOS_SWITCH_DEFAULT_DEBUG_ASSERT()
virtual std::string description() const
ParameterList & setParameters(const ParameterList &source)
RCP< const LinearOpSourceBase< Scalar > > extract_fwdOpSrc()
TEUCHOSCORE_LIB_DLL_EXPORT EVerbosityLevel incrVerbLevel(const EVerbosityLevel inputVerbLevel, const int numLevels)
bool nonnull(const boost::shared_ptr< T > &p)
basic_FancyOStream< char > FancyOStream
BelosLinearOpWithSolve()
Construct to unintialize.
void uninitialize(RCP< Belos::LinearProblem< Scalar, MV_t, LO_t > > *lp=NULL, RCP< Teuchos::ParameterList > *solverPL=NULL, RCP< Belos::SolverManager< Scalar, MV_t, LO_t > > *iterativeSolver=NULL, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc=NULL, RCP< const PreconditionerBase< Scalar > > *prec=NULL, bool *isExternalPrec=NULL, RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc=NULL, ESupportSolveUse *supportSolveUse=NULL)
Uninitializes and returns stored quantities.
RCP< const LinearOpBase< Scalar > > clone() const
virtual bool opSupportedImpl(EOpTransp M_trans) const
Teuchos_Ordinal Ordinal
virtual bool solveSupportsSolveMeasureTypeImpl(EOpTransp M_trans, const SolveMeasureType &solveMeasureType) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)