80 template<
class Scalar,
class MV,
class OP>
140 const int maxIterCount,
141 const bool haveLeftPreconditioner,
144 const int blockSize = 1,
145 const int defQuorum = -1,
146 const bool showMaxResNormOnly =
false);
157 gmresTest (
const bool haveLeftPreconditioner,
184 static std::pair<bool, bool>
187 const int maxIterCount);
196 const int maxIterCount);
234 template<
class Scalar,
class MV,
class OP>
238 const int maxIterCount,
239 const bool haveLeftPreconditioner,
242 const int blockSize = 1,
243 const int defQuorum = -1,
244 const bool showMaxResNormOnly =
false)
252 "blockSize (= " << blockSize <<
") must be >= 1.");
254 "defQuorum (= " << defQuorum <<
") may be no larger "
255 "than blockSize (= " << blockSize <<
").");
260 RCP<res_norm_test> implicitTest
261 =
rcp (
new res_norm_test (convTol, defQuorum));
262 implicitTest->defineScaleForm (stringToScaleType (implicitScaleType),
264 implicitTest->setShowMaxResNormOnly (showMaxResNormOnly);
271 RCP<res_norm_test> explicitTest;
272 if (haveLeftPreconditioner) {
273 explicitTest =
rcp (
new res_norm_test (convTol, defQuorum));
274 explicitTest->defineResForm (res_norm_test::Explicit,
Belos::TwoNorm);
275 explicitTest->defineScaleForm (stringToScaleType (explicitScaleType),
277 explicitTest->setShowMaxResNormOnly (showMaxResNormOnly);
288 RCP<base_test> convTest;
289 if (explicitTest.is_null()) {
290 convTest = implicitTest;
296 convTest =
rcp (
new combo_test (combo_test::SEQ,
302 RCP<max_iter_test> maxIterTest =
rcp (
new max_iter_test (maxIterCount));
307 return rcp (
new combo_test (combo_test::OR, maxIterTest, convTest));
311 template<
class Scalar,
class MV,
class OP>
326 "Convergence tolerance " << convTol
329 const int maxIterCount = params->
get<
int> (
"Maximum Iterations");
330 TEUCHOS_TEST_FOR_EXCEPTION(maxIterCount < 0, std::invalid_argument,
331 "Maximum number of iterations " << maxIterCount
339 const std::string defaultImplicitScaleType (
"Norm of Preconditioned Initial Residual");
340 implicitScaleType = stringToScaleType (params->
get (
"Implicit Residual Scaling", defaultImplicitScaleType));
344 const std::string defaultExplicitScaleType (
"Norm of Initial Residual");
345 explicitScaleType = stringToScaleType (params->
get (
"Explicit Residual Scaling", defaultExplicitScaleType));
347 const int defaultBlockSize = 1;
348 int blockSize = params->
get (
"Block Size", defaultBlockSize);
350 const int defaultDefQuorum = -1;
351 int defQuorum = params->
get (
"Deflation Quorum", defaultDefQuorum);
353 const bool defaultShowMaxResNormOnly =
false;
354 bool showMaxResNormOnly = params->
get (
"Show Maximum Residual Norm Only", defaultShowMaxResNormOnly);
356 return gmresTest (convTol, maxIterCount, haveLeftPreconditioner,
357 implicitScaleType, explicitScaleType, blockSize,
358 defQuorum, showMaxResNormOnly);
361 template<
class Scalar,
class MV,
class OP>
366 using Teuchos::parameterList;
371 if (defaultGmresParams_.is_null()) {
374 const magnitude_type convTol = STS::squareroot (STS::eps());
375 const int maxIterCount = 200;
381 const std::string defaultImplicitScaleType (
"Norm of Preconditioned Initial Residual");
382 const std::string defaultExplicitScaleType (
"Norm of Initial Residual");
383 const int defaultBlockSize = 1;
384 const int defaultDefQuorum = -1;
385 const bool defaultShowMaxResNormOnly =
false;
387 RCP<ParameterList> params = parameterList ();
388 params->set (
"Convergence Tolerance", convTol);
389 params->set (
"Maximum Iterations", maxIterCount);
390 params->set (
"Implicit Residual Scaling", defaultImplicitScaleType);
391 params->set (
"Explicit Residual Scaling", defaultExplicitScaleType);
392 params->set (
"Block Size", defaultBlockSize);
393 params->set (
"Deflation Quorum", defaultDefQuorum);
394 params->set (
"Show Maximum Residual Norm Only", defaultShowMaxResNormOnly);
396 defaultGmresParams_ = params;
398 return defaultGmresParams_;
402 template<
class Scalar,
class MV,
class OP>
406 const int maxIterCount)
408 using Teuchos::rcp_dynamic_cast;
415 bool success =
false;
416 RCP<max_iter_test> maxIterTest = rcp_dynamic_cast<
max_iter_test> (test);
424 RCP<combo_test> comboTest = rcp_dynamic_cast<
combo_test> (test);
427 typedef typename combo_test::st_vector st_vector;
428 typedef typename st_vector::size_type size_type;
433 for (size_type k = 0; result || k < tests.end(); ++k)
437 changeMaxNumIters (tests[k], maxIterCount);
438 success = result || success;
445 template<
class Scalar,
class MV,
class OP>
446 std::pair<bool, bool>
450 const int maxIterCount)
452 using Teuchos::rcp_dynamic_cast;
457 RCP<max_iter_test> maxIterTest = rcp_dynamic_cast<max_iter_test> (test);
461 bool foundResNormTest =
false;
462 bool foundMaxIterTest =
false;
464 RCP<res_norm_base_test> normTest =
465 rcp_dynamic_cast<res_norm_base_test> (test);
473 foundResNormTest =
true;
477 RCP<max_iter_test> maxIterTest =
478 rcp_dynamic_cast<max_iter_test> (test);
481 test->setMaxIters (maxIterCount);
482 foundMaxIterTest =
true;
485 if (! foundResNormTest && ! foundMaxIterTest)
487 RCP<combo_test> comboTest = rcp_dynamic_cast<combo_test> (test);
490 typedef typename combo_test::st_vector st_vector;
491 typedef typename st_vector::size_type size_type;
492 st_vector tests = test->getStatusTests ();
496 for (size_type k = 0; result || k < tests.end(); ++k)
498 const std::pair<bool, bool> result =
499 changeConvTolAndMaxIters (tests[k], convTol, maxIterCount);
500 foundResNormTest = result.first || foundResNormTest;
501 foundMaxIterTest = result.second || foundMaxIterTest;
505 return std::make_pair (foundResNormTest, foundMaxIterTest);
508 template<
class Scalar,
class MV,
class OP>
514 using Teuchos::rcp_dynamic_cast;
522 bool success =
false;
523 RCP<res_norm_base_test> normTest =
524 rcp_dynamic_cast<res_norm_base_test> (test);
536 RCP<combo_test> comboTest = rcp_dynamic_cast<
combo_test> (test);
539 typedef typename combo_test::st_vector st_vector;
540 typedef typename st_vector::size_type size_type;
545 for (size_type k = 0; result || k < tests.end(); ++k)
548 const bool result = changeConvTol (tests[k], convTol);
549 success = result || success;
557 template<
class Scalar,
class MV,
class OP>
562 const char* validNames[] = {
563 "Norm of Initial Residual",
564 "Norm of Preconditioned Initial Residual",
566 "Norm of Right-Hand Side",
569 const int numValidNames = 5;
570 const ScaleType correspondingOutputs[] = {
577 for (
int k = 0; k < numValidNames; ++k)
579 if (scaleType == validNames[k])
580 return correspondingOutputs[k];
583 "Invalid residual scaling type \"" << scaleType
static bool changeMaxNumIters(const Teuchos::RCP< base_test > &test, const int maxIterCount)
Change max number of iterations in place.
static bool changeConvTol(const Teuchos::RCP< base_test > &test, const magnitude_type convTol)
Change convergence tolerance in place.
StatusTestMaxIters< Scalar, MV, OP > max_iter_test
ScaleType
The type of scaling to use on the residual norm value.
T & get(const std::string &name, T def_value)
StatusTest< Scalar, MV, OP > base_test
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
An abstract class of StatusTest for stopping criteria using residual norms.
An implementation of StatusTestResNorm using a family of residual norms.
Belos::StatusTest class for specifying a maximum number of iterations.
A pure virtual class for defining the status tests for the Belos iterative solvers.
static ScaleType stringToScaleType(const std::string &scaleType)
Convert string to enum that tells residual test how to scale.
Belos::StatusTest for logically combining several status tests.
A Belos::StatusTest class for specifying a maximum number of iterations.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static std::pair< bool, bool > changeConvTolAndMaxIters(const Teuchos::RCP< base_test > &test, const magnitude_type convTol, const int maxIterCount)
Change convergence tolerance and max number of iterations.
bool nonnull(const boost::shared_ptr< T > &p)
Teuchos::RCP< const Teuchos::ParameterList > getValidGmresParameters()
Belos::StatusTestResNorm for specifying general residual norm stopping criteria.
static Teuchos::RCP< base_test > gmresTest(const magnitude_type convTol, const int maxIterCount, const bool haveLeftPreconditioner, const ScaleType implicitScaleType=Belos::NormOfPrecInitRes, const ScaleType explicitScaleType=Belos::NormOfInitRes, const int blockSize=1, const int defQuorum=-1, const bool showMaxResNormOnly=false)
Status test suitable for (preconditioned) GMRES.
Belos::StatusTest for specifying an implicit residual norm stopping criteria that checks for loss of ...
StatusTestGenResNorm< Scalar, MV, OP > res_norm_test
A class for extending the status testing capabilities of Belos via logical combinations.
st_vector getStatusTests()
Return the vector of status tests.
StatusTestCombo< Scalar, MV, OP > combo_test
virtual int setTolerance(MagnitudeType tolerance)=0
Set the value of the tolerance.
A factory for making common cases of stopping criteria.
Teuchos::RCP< const Teuchos::ParameterList > getValidGmresParameters()
Default parameters for a status test suitable for GMRES.
void setMaxIters(int maxIters)
Sets the maximum number of iterations allowed.