46 #include <Teuchos_ParameterList.hpp> 80 template<
class Scalar,
class MV,
class OP>
83 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType
magnitude_type;
138 static Teuchos::RCP<base_test>
140 const int maxIterCount,
141 const bool haveLeftPreconditioner,
144 const int blockSize = 1,
145 const int defQuorum = -1,
146 const bool showMaxResNormOnly =
false);
156 static Teuchos::RCP<base_test>
157 gmresTest (
const bool haveLeftPreconditioner,
158 const Teuchos::RCP<Teuchos::ParameterList>& params);
184 static std::pair<bool, bool>
186 const magnitude_type convTol,
187 const int maxIterCount);
196 const int maxIterCount);
205 const magnitude_type convTol);
230 Teuchos::RCP<const Teuchos::ParameterList> defaultGmresParams_;
234 template<
class Scalar,
class MV,
class OP>
235 Teuchos::RCP<typename StatusTestFactory<Scalar, MV, OP>::base_test>
238 const int maxIterCount,
239 const bool haveLeftPreconditioner,
242 const int blockSize = 1,
243 const int defQuorum = -1,
244 const bool showMaxResNormOnly =
false)
247 using Teuchos::ParameterList;
251 TEUCHOS_TEST_FOR_EXCEPTION(blockSize < 1, std::invalid_argument,
252 "blockSize (= " << blockSize <<
") must be >= 1.");
253 TEUCHOS_TEST_FOR_EXCEPTION(defQuorum > blockSize, std::invalid_argument,
254 "defQuorum (= " << defQuorum <<
") may be no larger " 255 "than blockSize (= " << blockSize <<
").");
260 RCP<res_norm_test> implicitTest
264 implicitTest->setShowMaxResNormOnly (showMaxResNormOnly);
271 RCP<res_norm_test> explicitTest;
272 if (haveLeftPreconditioner) {
277 explicitTest->setShowMaxResNormOnly (showMaxResNormOnly);
288 RCP<base_test> convTest;
289 if (explicitTest.is_null()) {
290 convTest = implicitTest;
302 RCP<max_iter_test> maxIterTest = rcp (
new max_iter_test (maxIterCount));
311 template<
class Scalar,
class MV,
class OP>
312 Teuchos::RCP<typename StatusTestFactory<Scalar, MV, OP>::base_test>
315 const Teuchos::RCP<Teuchos::ParameterList>& params)
317 using Teuchos::Exceptions::InvalidParameter;
319 typedef Teuchos::ScalarTraits<magnitude_type> STM;
325 TEUCHOS_TEST_FOR_EXCEPTION(convTol < STM::zero(), std::invalid_argument,
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>
362 Teuchos::RCP<const Teuchos::ParameterList>
365 using Teuchos::ParameterList;
366 using Teuchos::parameterList;
368 typedef Teuchos::ScalarTraits<Scalar> STS;
369 typedef Teuchos::ScalarTraits<magnitude_type> STM;
371 if (defaultGmresParams_.is_null()) {
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;
409 using Teuchos::nonnull;
415 bool success =
false;
416 RCP<max_iter_test> maxIterTest = rcp_dynamic_cast<
max_iter_test> (test);
417 if (nonnull (maxIterTest))
424 RCP<combo_test> comboTest = rcp_dynamic_cast<
combo_test> (test);
425 if (nonnull (comboTest))
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)
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;
453 using Teuchos::nonnull;
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);
466 if (nonnull (normTest))
472 (void) test->setTolerance (convTol);
473 foundResNormTest =
true;
477 RCP<max_iter_test> maxIterTest =
479 if (nonnull (maxIterTest))
482 foundMaxIterTest =
true;
485 if (! foundResNormTest && ! foundMaxIterTest)
487 RCP<combo_test> comboTest = rcp_dynamic_cast<
combo_test> (test);
488 if (nonnull (comboTest))
490 typedef typename combo_test::st_vector st_vector;
491 typedef typename st_vector::size_type size_type;
496 for (size_type k = 0; result || k < tests.end(); ++k)
498 const std::pair<bool, bool> result =
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;
515 using Teuchos::nonnull;
522 bool success =
false;
523 RCP<res_norm_base_test> normTest =
524 rcp_dynamic_cast<res_norm_base_test> (test);
525 if (nonnull (normTest))
536 RCP<combo_test> comboTest = rcp_dynamic_cast<
combo_test> (test);
537 if (nonnull (comboTest))
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)
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];
582 TEUCHOS_TEST_FOR_EXCEPTION (
true, std::logic_error,
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.
StatusTest< Scalar, MV, OP > base_test
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.
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.
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.