Merge pull request #905 from akva2/newtonmethod_param_split

NewtonMethod: split parameters and properties
This commit is contained in:
Bård Skaflestad 2024-07-01 17:31:16 +02:00 committed by GitHub
commit 1a5476c873
16 changed files with 270 additions and 164 deletions

View File

@ -71,16 +71,22 @@ struct FlashSolver<TypeTag, TTag::Co2InjectionFlashEcfvProblem>
template<class TypeTag> template<class TypeTag>
struct Scalar<TypeTag, TTag::Co2InjectionFlashEcfvProblem> struct Scalar<TypeTag, TTag::Co2InjectionFlashEcfvProblem>
{ using type = quad; }; { using type = quad; };
#else #endif
} // namespace Opm::Properties
namespace Opm::Parameters {
#if ! HAVE_QUAD
template<class TypeTag> template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::Co2InjectionFlashEcfvProblem> struct NewtonTolerance<TypeTag, Properties::TTag::Co2InjectionFlashEcfvProblem>
{ {
using type = GetPropType<TypeTag, Scalar>; using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-5; static constexpr type value = 1e-5;
}; };
#endif #endif
} // namespace Opm::Properties } // namespace Opm::Parameters
int main(int argc, char **argv) int main(int argc, char **argv)
{ {

View File

@ -73,16 +73,22 @@ struct FlashSolver<TypeTag, TTag::Co2InjectionFlashNiEcfvProblem>
template<class TypeTag> template<class TypeTag>
struct Scalar<TypeTag, TTag::Co2InjectionFlashNiEcfvProblem> struct Scalar<TypeTag, TTag::Co2InjectionFlashNiEcfvProblem>
{ using type = quad; }; { using type = quad; };
#else #endif
} // namespace Opm::Properties
namespace Opm::Parameters {
#if ! HAVE_QUAD
template<class TypeTag> template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::Co2InjectionFlashNiEcfvProblem> struct NewtonTolerance<TypeTag, Properties::TTag::Co2InjectionFlashNiEcfvProblem>
{ {
using type = GetPropType<TypeTag, Scalar>; using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-5; static constexpr type value = 1e-5;
}; };
#endif #endif
} // namespace Opm::Properties } // namespace Opm::Parameters
int main(int argc, char **argv) int main(int argc, char **argv)
{ {

View File

@ -69,16 +69,22 @@ struct FlashSolver<TypeTag, TTag::Co2InjectionFlashNiVcfvProblem>
template<class TypeTag> template<class TypeTag>
struct Scalar<TypeTag, TTag::Co2InjectionFlashNiVcfvProblem> struct Scalar<TypeTag, TTag::Co2InjectionFlashNiVcfvProblem>
{ using type = quad; }; { using type = quad; };
#else #endif
} // namespace Opm::Properties
namespace Opm::Parameters {
#if ! HAVE_QUAD
template<class TypeTag> template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::Co2InjectionFlashNiVcfvProblem> struct NewtonTolerance<TypeTag, Properties::TTag::Co2InjectionFlashNiVcfvProblem>
{ {
using type = GetPropType<TypeTag, Scalar>; using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-5; static constexpr type value = 1e-5;
}; };
#endif #endif
} // namespace Opm::Properties } // namespace Opm::Parameters
int main(int argc, char **argv) int main(int argc, char **argv)
{ {

View File

@ -65,16 +65,22 @@ struct FlashSolver<TypeTag, TTag::Co2InjectionFlashVcfvProblem>
template<class TypeTag> template<class TypeTag>
struct Scalar<TypeTag, TTag::Co2InjectionFlashVcfvProblem> struct Scalar<TypeTag, TTag::Co2InjectionFlashVcfvProblem>
{ using type = quad; }; { using type = quad; };
#else #endif
} // namespace Opm::Properties
namespace Opm::Parameters {
#if ! HAVE_QUAD
template<class TypeTag> template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::Co2InjectionFlashVcfvProblem> struct NewtonTolerance<TypeTag, Properties::TTag::Co2InjectionFlashVcfvProblem>
{ {
using type = GetPropType<TypeTag, Scalar>; using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-5; static constexpr type value = 1e-5;
}; };
#endif #endif
} // namespace Opm::Properties } // namespace Opm::Parameters
int main(int argc, char **argv) int main(int argc, char **argv)
{ {

View File

@ -157,10 +157,6 @@ struct SolidEnergyLaw<TypeTag, TTag::Co2InjectionBaseProblem>
template<class TypeTag> template<class TypeTag>
struct LinearSolverSplice<TypeTag, TTag::Co2InjectionBaseProblem> { using type = TTag::ParallelAmgLinearSolver; }; struct LinearSolverSplice<TypeTag, TTag::Co2InjectionBaseProblem> { using type = TTag::ParallelAmgLinearSolver; };
// Write the Newton convergence behavior to disk?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, TTag::Co2InjectionBaseProblem> { static constexpr bool value = false; };
// Enable gravity // Enable gravity
template<class TypeTag> template<class TypeTag>
struct EnableGravity<TypeTag, TTag::Co2InjectionBaseProblem> { static constexpr bool value = true; }; struct EnableGravity<TypeTag, TTag::Co2InjectionBaseProblem> { static constexpr bool value = true; };
@ -232,6 +228,15 @@ struct GridFile<TypeTag, TTag::Co2InjectionBaseProblem> { static constexpr auto
} // namespace Opm::Properties } // namespace Opm::Properties
namespace Opm::Parameters {
// Write the Newton convergence behavior to disk?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::Co2InjectionBaseProblem>
{ static constexpr bool value = false; };
} // namespace Opm::Parameters
namespace Opm { namespace Opm {
/*! /*!
* \ingroup TestProblems * \ingroup TestProblems

View File

@ -140,11 +140,6 @@ public:
using type = EffMaterialLaw; using type = EffMaterialLaw;
}; };
// Write the Newton convergence behavior to disk?
template <class TypeTag>
struct NewtonWriteConvergence<TypeTag, TTag::CO2PTBaseProblem> {
static constexpr bool value = false; };
// Enable gravity false // Enable gravity false
template <class TypeTag> template <class TypeTag>
struct EnableGravity<TypeTag, TTag::CO2PTBaseProblem> { static constexpr bool value = false; struct EnableGravity<TypeTag, TTag::CO2PTBaseProblem> { static constexpr bool value = false;
@ -194,23 +189,6 @@ struct LinearSolverAbsTolerance<TypeTag, TTag::CO2PTBaseProblem> {
static constexpr type value = 0.; static constexpr type value = 0.;
}; };
template <class TypeTag>
struct NewtonTolerance<TypeTag, TTag::CO2PTBaseProblem> {
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 1e-3;
};
template <class TypeTag>
struct NewtonMaxIterations<TypeTag, TTag::CO2PTBaseProblem> {
static constexpr int value = 30;
};
template <class TypeTag>
struct NewtonTargetIterations<TypeTag, TTag::CO2PTBaseProblem> {
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 6;
};
// output // output
template <class TypeTag> template <class TypeTag>
struct VtkWriteFilterVelocities<TypeTag, TTag::CO2PTBaseProblem> { struct VtkWriteFilterVelocities<TypeTag, TTag::CO2PTBaseProblem> {
@ -297,8 +275,32 @@ struct EnableEnergy<TypeTag, TTag::CO2PTBaseProblem> {
} // namespace Opm::Properties } // namespace Opm::Properties
namespace Opm::Parameters {
// Write the Newton convergence behavior to disk?
template <class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::CO2PTBaseProblem>
{ static constexpr bool value = false; };
template <class TypeTag>
struct NewtonTolerance<TypeTag, Properties::TTag::CO2PTBaseProblem>
{
using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-3;
};
template <class TypeTag>
struct NewtonTargetIterations<TypeTag, Properties::TTag::CO2PTBaseProblem>
{
using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 6;
};
template <class TypeTag>
struct NewtonMaxIterations<TypeTag, Properties::TTag::CO2PTBaseProblem>
{ static constexpr int value = 30; };
} // namespace Opm::Parameters
namespace Opm { namespace Opm {
/*! /*!

View File

@ -124,10 +124,6 @@ struct MaterialLaw<TypeTag, TTag::FingerBaseProblem>
using type = ParkerLenhard; using type = ParkerLenhard;
}; };
// Write the solutions of individual newton iterations?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, TTag::FingerBaseProblem> { static constexpr bool value = false; };
// Use forward differences instead of central differences // Use forward differences instead of central differences
template<class TypeTag> template<class TypeTag>
struct NumericDifferenceMethod<TypeTag, TTag::FingerBaseProblem> { static constexpr int value = +1; }; struct NumericDifferenceMethod<TypeTag, TTag::FingerBaseProblem> { static constexpr int value = +1; };
@ -192,6 +188,15 @@ struct InitialTimeStepSize<TypeTag, TTag::FingerBaseProblem>
} // namespace Opm::Properties } // namespace Opm::Properties
namespace Opm::Parameters {
// Write the solutions of individual newton iterations?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::FingerBaseProblem>
{ static constexpr bool value = false; };
} // namespace Opm::Parameters
namespace Opm { namespace Opm {
/*! /*!

View File

@ -74,10 +74,6 @@ struct FluidSystem<TypeTag, TTag::InfiltrationBaseProblem>
template<class TypeTag> template<class TypeTag>
struct EnableGravity<TypeTag, TTag::InfiltrationBaseProblem> { static constexpr bool value = true; }; struct EnableGravity<TypeTag, TTag::InfiltrationBaseProblem> { static constexpr bool value = true; };
// Write newton convergence?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, TTag::InfiltrationBaseProblem> { static constexpr bool value = false; };
// -1 backward differences, 0: central differences, +1: forward differences // -1 backward differences, 0: central differences, +1: forward differences
template<class TypeTag> template<class TypeTag>
struct NumericDifferenceMethod<TypeTag, TTag::InfiltrationBaseProblem> { static constexpr int value = 1; }; struct NumericDifferenceMethod<TypeTag, TTag::InfiltrationBaseProblem> { static constexpr int value = 1; };
@ -123,6 +119,15 @@ struct GridFile<TypeTag, TTag::InfiltrationBaseProblem>
} // namespace Opm::Properties } // namespace Opm::Properties
namespace Opm::Parameters {
// Write newton convergence?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::InfiltrationBaseProblem>
{ static constexpr bool value = false; };
} // namespace Opm::Parameters
namespace Opm { namespace Opm {
/*! /*!
* \ingroup TestProblems * \ingroup TestProblems

View File

@ -129,10 +129,6 @@ public:
using type = Opm::EffToAbsLaw<EffectiveLaw>; using type = Opm::EffToAbsLaw<EffectiveLaw>;
}; };
// Write the solutions of individual newton iterations?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, TTag::LensBaseProblem> { static constexpr bool value = false; };
// Use forward differences instead of central differences // Use forward differences instead of central differences
template<class TypeTag> template<class TypeTag>
struct NumericDifferenceMethod<TypeTag, TTag::LensBaseProblem> { static constexpr int value = +1; }; struct NumericDifferenceMethod<TypeTag, TTag::LensBaseProblem> { static constexpr int value = +1; };
@ -239,6 +235,11 @@ template<class TypeTag>
struct EnableStorageCache<TypeTag, Properties::TTag::LensBaseProblem> struct EnableStorageCache<TypeTag, Properties::TTag::LensBaseProblem>
{ static constexpr bool value = true; }; { static constexpr bool value = true; };
// Write the solutions of individual newton iterations?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::LensBaseProblem>
{ static constexpr bool value = false; };
} // namespace Opm::Parameters } // namespace Opm::Parameters
namespace Opm { namespace Opm {

View File

@ -100,10 +100,6 @@ public:
using type = Opm::LinearMaterial<Traits>; using type = Opm::LinearMaterial<Traits>;
}; };
// Write the Newton convergence behavior to disk?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, TTag::ReservoirBaseProblem> { static constexpr bool value = false; };
// Enable gravity // Enable gravity
template<class TypeTag> template<class TypeTag>
struct EnableGravity<TypeTag, TTag::ReservoirBaseProblem> { static constexpr bool value = true; }; struct EnableGravity<TypeTag, TTag::ReservoirBaseProblem> { static constexpr bool value = true; };
@ -175,15 +171,24 @@ public:
template<class TypeTag> template<class TypeTag>
struct GridFile<TypeTag, TTag::ReservoirBaseProblem> { static constexpr auto value = "data/reservoir.dgf"; }; struct GridFile<TypeTag, TTag::ReservoirBaseProblem> { static constexpr auto value = "data/reservoir.dgf"; };
} // namespace Opm::Properties
namespace Opm::Parameters {
// Write the Newton convergence behavior to disk?
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::ReservoirBaseProblem>
{ static constexpr bool value = false; };
// increase the tolerance for this problem to get larger time steps // increase the tolerance for this problem to get larger time steps
template<class TypeTag> template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::ReservoirBaseProblem> struct NewtonTolerance<TypeTag, Properties::TTag::ReservoirBaseProblem>
{ {
using type = GetPropType<TypeTag, Scalar>; using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-6; static constexpr type value = 1e-6;
}; };
} // namespace Opm::Properties } // namespace Opm::Parameters
namespace Opm { namespace Opm {

View File

@ -107,18 +107,6 @@ struct EnableGravity<TypeTag, TTag::RichardsLensProblem> { static constexpr bool
template<class TypeTag> template<class TypeTag>
struct NumericDifferenceMethod<TypeTag, TTag::RichardsLensProblem> { static constexpr int value = 0; }; struct NumericDifferenceMethod<TypeTag, TTag::RichardsLensProblem> { static constexpr int value = 0; };
// Set the maximum number of newton iterations of a time step
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, TTag::RichardsLensProblem> { static constexpr int value = 28; };
// Set the "desireable" number of newton iterations of a time step
template<class TypeTag>
struct NewtonTargetIterations<TypeTag, TTag::RichardsLensProblem> { static constexpr int value = 18; };
// Do not write the intermediate results of the newton method
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, TTag::RichardsLensProblem> { static constexpr bool value = false; };
// The default for the end time of the simulation // The default for the end time of the simulation
template<class TypeTag> template<class TypeTag>
struct EndTime<TypeTag, TTag::RichardsLensProblem> struct EndTime<TypeTag, TTag::RichardsLensProblem>
@ -141,6 +129,25 @@ struct GridFile<TypeTag, TTag::RichardsLensProblem> { static constexpr auto valu
} // namespace Opm::Properties } // namespace Opm::Properties
namespace Opm::Parameters {
// Do not write the intermediate results of the newton method
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::RichardsLensProblem>
{ static constexpr bool value = false; };
// Set the "desireable" number of newton iterations of a time step
template<class TypeTag>
struct NewtonTargetIterations<TypeTag, Properties::TTag::RichardsLensProblem>
{ static constexpr int value = 18; };
// Set the maximum number of newton iterations of a time step
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, Properties::TTag::RichardsLensProblem>
{ static constexpr int value = 28; };
} // namespace Opm::Parameters
namespace Opm { namespace Opm {
/*! /*!

View File

@ -123,10 +123,6 @@ struct EnableGravity<TypeTag, TTag::WaterAirBaseProblem> { static constexpr bool
template<class TypeTag> template<class TypeTag>
struct NumericDifferenceMethod<TypeTag, TTag::WaterAirBaseProblem> { static constexpr int value = +1; }; struct NumericDifferenceMethod<TypeTag, TTag::WaterAirBaseProblem> { static constexpr int value = +1; };
// Write newton convergence
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, TTag::WaterAirBaseProblem> { static constexpr bool value = false; };
// The default for the end time of the simulation (1 year) // The default for the end time of the simulation (1 year)
template<class TypeTag> template<class TypeTag>
struct EndTime<TypeTag, TTag::WaterAirBaseProblem> struct EndTime<TypeTag, TTag::WaterAirBaseProblem>
@ -164,6 +160,15 @@ struct PreconditionerOrder<TypeTag, TTag::WaterAirBaseProblem> { static constexp
} // namespace Opm::Properties } // namespace Opm::Properties
namespace Opm::Parameters {
// Write newton convergence
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::WaterAirBaseProblem>
{ static constexpr bool value = false; };
} // namespace Opm::Parameters
namespace Opm { namespace Opm {
/*! /*!
* \ingroup TestProblems * \ingroup TestProblems

View File

@ -117,10 +117,10 @@ protected:
// make sure that the error never grows beyond the maximum // make sure that the error never grows beyond the maximum
// allowed one // allowed one
if (this->error_ > Parameters::get<TypeTag, Properties::NewtonMaxError>()) if (this->error_ > Parameters::get<TypeTag, Parameters::NewtonMaxError>())
throw Opm::NumericalProblem("Newton: Error "+std::to_string(double(this->error_))+ throw Opm::NumericalProblem("Newton: Error "+std::to_string(double(this->error_))+
+ " is larger than maximum allowed error of " + " is larger than maximum allowed error of "
+ std::to_string(Parameters::get<TypeTag, Properties::NewtonMaxError>())); + std::to_string(Parameters::get<TypeTag, Parameters::NewtonMaxError>()));
} }
/*! /*!

View File

@ -27,24 +27,25 @@
#ifndef EWOMS_NEWTON_METHOD_HH #ifndef EWOMS_NEWTON_METHOD_HH
#define EWOMS_NEWTON_METHOD_HH #define EWOMS_NEWTON_METHOD_HH
#include "nullconvergencewriter.hh" #include <dune/istl/istlexception.hh>
#include <dune/common/classname.hh>
#include "newtonmethodproperties.hh" #include <dune/common/parallel/mpihelper.hh>
#include <opm/common/Exceptions.hpp> #include <opm/common/Exceptions.hpp>
#include <opm/material/densead/Math.hpp> #include <opm/material/densead/Math.hpp>
#include <opm/models/discretization/common/fvbaseproperties.hh> #include <opm/models/discretization/common/fvbaseproperties.hh>
#include <opm/models/nonlinear/newtonmethodparameters.hh>
#include <opm/models/nonlinear/newtonmethodproperties.hh>
#include <opm/models/nonlinear/nullconvergencewriter.hh>
#include <opm/models/utils/timer.hh> #include <opm/models/utils/timer.hh>
#include <opm/models/utils/timerguard.hh> #include <opm/models/utils/timerguard.hh>
#include <opm/simulators/linalg/linalgproperties.hh> #include <opm/simulators/linalg/linalgproperties.hh>
#include <dune/istl/istlexception.hh>
#include <dune/common/classname.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -75,31 +76,45 @@ template<class TypeTag>
struct NewtonMethod<TypeTag, TTag::NewtonMethod> { using type = ::Opm::NewtonMethod<TypeTag>; }; struct NewtonMethod<TypeTag, TTag::NewtonMethod> { using type = ::Opm::NewtonMethod<TypeTag>; };
template<class TypeTag> template<class TypeTag>
struct NewtonConvergenceWriter<TypeTag, TTag::NewtonMethod> { using type = NullConvergenceWriter<TypeTag>; }; struct NewtonConvergenceWriter<TypeTag, TTag::NewtonMethod> { using type = NullConvergenceWriter<TypeTag>; };
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, TTag::NewtonMethod> { static constexpr bool value = false; };
template<class TypeTag>
struct NewtonVerbose<TypeTag, TTag::NewtonMethod> { static constexpr bool value = true; };
template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::NewtonMethod>
{
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 1e-8;
};
// set the abortion tolerace to some very large value. if not
// overwritten at run-time this basically disables abortions
template<class TypeTag>
struct NewtonMaxError<TypeTag, TTag::NewtonMethod>
{
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 1e100;
};
template<class TypeTag>
struct NewtonTargetIterations<TypeTag, TTag::NewtonMethod> { static constexpr int value = 10; };
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, TTag::NewtonMethod> { static constexpr int value = 20; };
} // namespace Opm::Properties } // namespace Opm::Properties
namespace Opm::Parameters {
template<class TypeTag>
struct NewtonVerbose<TypeTag, Properties::TTag::NewtonMethod>
{ static constexpr bool value = true; };
template<class TypeTag>
struct NewtonWriteConvergence<TypeTag, Properties::TTag::NewtonMethod>
{ static constexpr bool value = false; };
template<class TypeTag>
struct NewtonTolerance<TypeTag, Properties::TTag::NewtonMethod>
{
using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-8;
};
// set the abortion tolerance to some very large value. if not
// overwritten at run-time this basically disables abortions
template<class TypeTag>
struct NewtonMaxError<TypeTag, Properties::TTag::NewtonMethod>
{
using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e100;
};
template<class TypeTag>
struct NewtonTargetIterations<TypeTag, Properties::TTag::NewtonMethod>
{ static constexpr int value = 10; };
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, Properties::TTag::NewtonMethod>
{ static constexpr int value = 20; };
} // namespace Opm::Parameters
namespace Opm { namespace Opm {
/*! /*!
* \ingroup Newton * \ingroup Newton
@ -139,7 +154,7 @@ public:
{ {
lastError_ = 1e100; lastError_ = 1e100;
error_ = 1e100; error_ = 1e100;
tolerance_ = Parameters::get<TypeTag, Properties::NewtonTolerance>(); tolerance_ = Parameters::get<TypeTag, Parameters::NewtonTolerance>();
numIterations_ = 0; numIterations_ = 0;
} }
@ -151,20 +166,20 @@ public:
{ {
LinearSolverBackend::registerParameters(); LinearSolverBackend::registerParameters();
Parameters::registerParam<TypeTag, Properties::NewtonVerbose> Parameters::registerParam<TypeTag, Parameters::NewtonVerbose>
("Specify whether the Newton method should inform " ("Specify whether the Newton method should inform "
"the user about its progress or not"); "the user about its progress or not");
Parameters::registerParam<TypeTag, Properties::NewtonWriteConvergence> Parameters::registerParam<TypeTag, Parameters::NewtonWriteConvergence>
("Write the convergence behaviour of the Newton " ("Write the convergence behaviour of the Newton "
"method to a VTK file"); "method to a VTK file");
Parameters::registerParam<TypeTag, Properties::NewtonTargetIterations> Parameters::registerParam<TypeTag, Parameters::NewtonTargetIterations>
("The 'optimum' number of Newton iterations per time step"); ("The 'optimum' number of Newton iterations per time step");
Parameters::registerParam<TypeTag, Properties::NewtonMaxIterations> Parameters::registerParam<TypeTag, Parameters::NewtonMaxIterations>
("The maximum number of Newton iterations per time step"); ("The maximum number of Newton iterations per time step");
Parameters::registerParam<TypeTag, Properties::NewtonTolerance> Parameters::registerParam<TypeTag, Parameters::NewtonTolerance>
("The maximum raw error tolerated by the Newton" ("The maximum raw error tolerated by the Newton"
"method for considering a solution to be converged"); "method for considering a solution to be converged");
Parameters::registerParam<TypeTag, Properties::NewtonMaxError> Parameters::registerParam<TypeTag, Parameters::NewtonMaxError>
("The maximum error tolerated by the Newton " ("The maximum error tolerated by the Newton "
"method to which does not cause an abort"); "method to which does not cause an abort");
} }
@ -529,7 +544,7 @@ protected:
*/ */
bool verbose_() const bool verbose_() const
{ {
return Parameters::get<TypeTag, Properties::NewtonVerbose>() && (comm_.rank() == 0); return Parameters::get<TypeTag, Parameters::NewtonVerbose>() && (comm_.rank() == 0);
} }
/*! /*!
@ -542,7 +557,7 @@ protected:
{ {
numIterations_ = 0; numIterations_ = 0;
if (Parameters::get<TypeTag, Properties::NewtonWriteConvergence>()) if (Parameters::get<TypeTag, Parameters::NewtonWriteConvergence>())
convergenceWriter_.beginTimeStep(); convergenceWriter_.beginTimeStep();
} }
@ -594,7 +609,7 @@ protected:
{ {
const auto& constraintsMap = model().linearizer().constraintsMap(); const auto& constraintsMap = model().linearizer().constraintsMap();
lastError_ = error_; lastError_ = error_;
Scalar newtonMaxError = Parameters::get<TypeTag, Properties::NewtonMaxError>(); Scalar newtonMaxError = Parameters::get<TypeTag, Parameters::NewtonMaxError>();
// calculate the error as the maximum weighted tolerance of // calculate the error as the maximum weighted tolerance of
// the solution's residual // the solution's residual
@ -759,7 +774,7 @@ protected:
void writeConvergence_(const SolutionVector& currentSolution, void writeConvergence_(const SolutionVector& currentSolution,
const GlobalEqVector& solutionUpdate) const GlobalEqVector& solutionUpdate)
{ {
if (Parameters::get<TypeTag, Properties::NewtonWriteConvergence>()) { if (Parameters::get<TypeTag, Parameters::NewtonWriteConvergence>()) {
convergenceWriter_.beginIteration(); convergenceWriter_.beginIteration();
convergenceWriter_.writeFields(currentSolution, solutionUpdate); convergenceWriter_.writeFields(currentSolution, solutionUpdate);
convergenceWriter_.endIteration(); convergenceWriter_.endIteration();
@ -831,7 +846,7 @@ protected:
*/ */
void end_() void end_()
{ {
if (Parameters::get<TypeTag, Properties::NewtonWriteConvergence>()) if (Parameters::get<TypeTag, Parameters::NewtonWriteConvergence>())
convergenceWriter_.endTimeStep(); convergenceWriter_.endTimeStep();
} }
@ -853,10 +868,10 @@ protected:
// optimal number of iterations we want to achieve // optimal number of iterations we want to achieve
int targetIterations_() const int targetIterations_() const
{ return Parameters::get<TypeTag, Properties::NewtonTargetIterations>(); } { return Parameters::get<TypeTag, Parameters::NewtonTargetIterations>(); }
// maximum number of iterations we do before giving up // maximum number of iterations we do before giving up
int maxIterations_() const int maxIterations_() const
{ return Parameters::get<TypeTag, Properties::NewtonMaxIterations>(); } { return Parameters::get<TypeTag, Parameters::NewtonMaxIterations>(); }
static bool enableConstraints_() static bool enableConstraints_()
{ return getPropValue<TypeTag, Properties::EnableConstraints>(); } { return getPropValue<TypeTag, Properties::EnableConstraints>(); }

View File

@ -0,0 +1,70 @@
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef EWOMS_NEWTON_METHOD_PARAMETERS_HH
#define EWOMS_NEWTON_METHOD_PARAMETERS_HH
#include <opm/models/utils/propertysystem.hh>
namespace Opm::Parameters {
//! Specifies whether the Newton method should print messages or not
template<class TypeTag, class MyTypeTag>
struct NewtonVerbose { using type = Properties::UndefinedProperty; };
//! Specifies whether the convergence rate and the global residual
//! gets written out to disk for every Newton iteration
template<class TypeTag, class MyTypeTag>
struct NewtonWriteConvergence { using type = Properties::UndefinedProperty; };
/*!
* \brief The value for the error below which convergence is declared
*
* This value can (and for the porous media models will) be changed to account for grid
* scaling and other effects.
*/
template<class TypeTag, class MyTypeTag>
struct NewtonTolerance { using type = Properties::UndefinedProperty; };
//! The maximum error which may occur in a simulation before the
//! Newton method for the time step is aborted
template<class TypeTag, class MyTypeTag>
struct NewtonMaxError { using type = Properties::UndefinedProperty; };
/*!
* \brief The number of iterations at which the Newton method
* should aim at.
*
* This is used to control the time-step size. The heuristic used
* is to scale the last time-step size by the deviation of the
* number of iterations used from the target steps.
*/
template<class TypeTag, class MyTypeTag>
struct NewtonTargetIterations { using type = Properties::UndefinedProperty; };
//! Number of maximum iterations for the Newton method.
template<class TypeTag, class MyTypeTag>
struct NewtonMaxIterations { using type = Properties::UndefinedProperty; };
} // end namespace Opm::Parameters
#endif

View File

@ -20,11 +20,11 @@
module for the precise wording of the license and the list of module for the precise wording of the license and the list of
copyright holders. copyright holders.
*/ */
#ifndef EWOMS_NEWTON_METHOD_POPERTIES_HH #ifndef EWOMS_NEWTON_METHOD_PROPERTIES_HH
#define EWOMS_NEWTON_METHOD_POPERTIES_HH #define EWOMS_NEWTON_METHOD_PROPERTIES_HH
#include <opm/models/utils/propertysystem.hh> #include <opm/models/utils/propertysystem.hh>
#include <opm/models/utils/parametersystem.hh>
namespace Opm::Properties { namespace Opm::Properties {
//! Specifies the type of the actual Newton method //! Specifies the type of the actual Newton method
@ -35,53 +35,15 @@ struct NewtonMethod { using type = UndefinedProperty; };
template<class TypeTag, class MyTypeTag> template<class TypeTag, class MyTypeTag>
struct Linearizer { using type = UndefinedProperty; }; struct Linearizer { using type = UndefinedProperty; };
//! Specifies whether the Newton method should print messages or not
template<class TypeTag, class MyTypeTag>
struct NewtonVerbose { using type = UndefinedProperty; };
//! Specifies the type of the class which writes out the Newton convergence //! Specifies the type of the class which writes out the Newton convergence
template<class TypeTag, class MyTypeTag> template<class TypeTag, class MyTypeTag>
struct NewtonConvergenceWriter { using type = UndefinedProperty; }; struct NewtonConvergenceWriter { using type = UndefinedProperty; };
//! Specifies whether the convergence rate and the global residual
//! gets written out to disk for every Newton iteration
template<class TypeTag, class MyTypeTag>
struct NewtonWriteConvergence { using type = UndefinedProperty; };
//! Specifies whether the convergence rate and the global residual //! Specifies whether the convergence rate and the global residual
//! gets written out to disk for every Newton iteration //! gets written out to disk for every Newton iteration
template<class TypeTag, class MyTypeTag> template<class TypeTag, class MyTypeTag>
struct ConvergenceWriter { using type = UndefinedProperty; }; struct ConvergenceWriter { using type = UndefinedProperty; };
/*!
* \brief The value for the error below which convergence is declared
*
* This value can (and for the porous media models will) be changed to account for grid
* scaling and other effects.
*/
template<class TypeTag, class MyTypeTag>
struct NewtonTolerance { using type = UndefinedProperty; };
//! The maximum error which may occur in a simulation before the
//! Newton method for the time step is aborted
template<class TypeTag, class MyTypeTag>
struct NewtonMaxError { using type = UndefinedProperty; };
/*!
* \brief The number of iterations at which the Newton method
* should aim at.
*
* This is used to control the time-step size. The heuristic used
* is to scale the last time-step size by the deviation of the
* number of iterations used from the target steps.
*/
template<class TypeTag, class MyTypeTag>
struct NewtonTargetIterations { using type = UndefinedProperty; };
//! Number of maximum iterations for the Newton method.
template<class TypeTag, class MyTypeTag>
struct NewtonMaxIterations { using type = UndefinedProperty; };
} // end namespace Opm::Properties } // end namespace Opm::Properties
#endif #endif