Commit c4bde23e authored by Bernd Flemisch's avatar Bernd Flemisch
Browse files

[newton] increase backwards compatibility for the recent change in

terminology

1. The deprecated protected member variables now are references to the
new variables. This ensures that the right value is considered even if
the old name is used.

2. In the constructor of the NewtonController, a check is performed if
a value for an old parameter name is set run-time. If yes, this value is
used correspondingly. A warning is still printed when the controller is
destructed.

This should ensure that the same results are produced even if the old
names are used.

Reviewed by gruenich.



git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@14140 2fb0f335-1f38-0410-981e-8018bf24f1b0
parent c58566a2
......@@ -181,16 +181,26 @@ class NewtonController
typedef typename GET_PROP_TYPE(TypeTag, LinearSolver) LinearSolver;
public:
/*!
* \brief
*/
// Avoid warnings when deprecated member variables are default-initialized
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
/*!
* \brief Constructor
*/
NewtonController(const Problem &problem)
: endIterMsgStream_(std::ostringstream::out)
, convergenceWriter_(asImp_())
, linearSolver_(problem)
: endIterMsgStream_(std::ostringstream::out)
, convergenceWriter_(asImp_())
, linearSolver_(problem)
, error_(shift_)
, lastError_(lastShift_)
, tolerance_(shiftTolerance_)
, absoluteError_(reduction_)
, lastAbsoluteError_(lastReduction_)
, initialAbsoluteError_(initialResidual_)
, absoluteTolerance_(reductionTolerance_)
, enableRelativeCriterion_(enableShiftCriterion_)
, enableAbsoluteCriterion_(enableResidualCriterion_)
, satisfyAbsAndRel_(satisfyResidualAndShiftCriterion_)
{
enablePartialReassemble_ = GET_PARAM_FROM_GROUP(TypeTag, bool, Implicit, EnablePartialReassemble);
enableJacobianRecycling_ = GET_PARAM_FROM_GROUP(TypeTag, bool, Implicit, EnableJacobianRecycling);
......@@ -201,8 +211,9 @@ public:
satisfyResidualAndShiftCriterion_ = GET_PARAM_FROM_GROUP(TypeTag, bool, Newton, SatisfyResidualAndShiftCriterion);
if (!enableShiftCriterion_ && !enableResidualCriterion_)
{
DUNE_THROW(Dune::NotImplemented, "at least one of NewtonEnableShiftCriterion or "
<< "NewtonEnableResidualCriterion has to be set to true");
DUNE_THROW(Dune::NotImplemented,
"at least one of NewtonEnableShiftCriterion or "
<< "NewtonEnableResidualCriterion has to be set to true");
}
setMaxRelativeShift(GET_PARAM_FROM_GROUP(TypeTag, Scalar, Newton, MaxRelativeShift));
......@@ -210,6 +221,32 @@ public:
setTargetSteps(GET_PARAM_FROM_GROUP(TypeTag, int, Newton, TargetSteps));
setMaxSteps(GET_PARAM_FROM_GROUP(TypeTag, int, Newton, MaxSteps));
// Check if deprecated parameters are set run-time and use them.
// Otherwise, the default values would be used.
// A warning will be printed during destruction of the controller.
typedef typename GET_PROP(TypeTag, ParameterTree) Params;
const Dune::ParameterTree &tree = Params::tree();
if (tree.hasKey("Newton.EnableRelativeCriterion"))
{
enableShiftCriterion_ = GET_PARAM_FROM_GROUP(TypeTag, bool, Newton, EnableRelativeCriterion);
}
if (tree.hasKey("Newton.RelTolerance"))
{
setMaxRelativeShift(GET_PARAM_FROM_GROUP(TypeTag, Scalar, Newton, RelTolerance));
}
if (tree.hasKey("Newton.EnableAbsoluteCriterion"))
{
enableResidualCriterion_ = GET_PARAM_FROM_GROUP(TypeTag, bool, Newton, EnableAbsoluteCriterion);
}
if (tree.hasKey("Newton.AbsTolerance"))
{
setResidualReduction(GET_PARAM_FROM_GROUP(TypeTag, Scalar, Newton, AbsTolerance));
}
if (tree.hasKey("Newton.SatisfyAbsAndRel"))
{
satisfyResidualAndShiftCriterion_ = GET_PARAM_FROM_GROUP(TypeTag, bool, Newton, SatisfyAbsAndRel);
}
verbose_ = true;
numSteps_ = 0;
}
......@@ -231,7 +268,7 @@ public:
|| tree.hasKey("Newton.SatisfyAbsAndRel"))
{
std::cout << std::endl << "[Newton] The following DEPRECATED parameters"
<< "are set run-time and are therefore not used:" << std::endl;
<< " are set run-time:" << std::endl;
if (tree.hasKey("Newton.EnableRelativeCriterion"))
{
......@@ -264,7 +301,7 @@ public:
|| GET_PROP_VALUE(TypeTag, NewtonSatisfyAbsAndRel) != false)
{
std::cout << std::endl << "[Newton] The following DEPRECATED properties"
<< " are set compile-time and the corresponding new properties are used:"
<< " are set compile-time:"
<< std::endl;
if (GET_PROP_VALUE(TypeTag, NewtonEnableRelativeCriterion) != true)
......@@ -820,16 +857,16 @@ protected:
bool satisfyResidualAndShiftCriterion_;
// deprecated member variables
Scalar error_ DUNE_DEPRECATED_MSG("use shift_ instead");
Scalar lastError_ DUNE_DEPRECATED_MSG("use lastShift_ instead");
Scalar tolerance_ DUNE_DEPRECATED_MSG("use shiftTolerance_ instead");
Scalar absoluteError_ DUNE_DEPRECATED_MSG("use reduction_ instead");
Scalar lastAbsoluteError_ DUNE_DEPRECATED_MSG("use lastReduction_ instead");
Scalar initialAbsoluteError_ DUNE_DEPRECATED_MSG("use initialResidual_ instead");
Scalar absoluteTolerance_ DUNE_DEPRECATED_MSG("use reductionTolerance_ instead");
bool enableRelativeCriterion_ DUNE_DEPRECATED_MSG("use enableShiftCriterion_ instead");
bool enableAbsoluteCriterion_ DUNE_DEPRECATED_MSG("use enableResidualCriterion_ instead");
bool satisfyAbsAndRel_ DUNE_DEPRECATED_MSG("use satisfyResidualAndShiftCriterion_ instead");
Scalar& error_ DUNE_DEPRECATED_MSG("use shift_ instead");
Scalar& lastError_ DUNE_DEPRECATED_MSG("use lastShift_ instead");
Scalar& tolerance_ DUNE_DEPRECATED_MSG("use shiftTolerance_ instead");
Scalar& absoluteError_ DUNE_DEPRECATED_MSG("use reduction_ instead");
Scalar& lastAbsoluteError_ DUNE_DEPRECATED_MSG("use lastReduction_ instead");
Scalar& initialAbsoluteError_ DUNE_DEPRECATED_MSG("use initialResidual_ instead");
Scalar& absoluteTolerance_ DUNE_DEPRECATED_MSG("use reductionTolerance_ instead");
bool& enableRelativeCriterion_ DUNE_DEPRECATED_MSG("use enableShiftCriterion_ instead");
bool& enableAbsoluteCriterion_ DUNE_DEPRECATED_MSG("use enableResidualCriterion_ instead");
bool& satisfyAbsAndRel_ DUNE_DEPRECATED_MSG("use satisfyResidualAndShiftCriterion_ instead");
};
} // namespace Dumux
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment