Merge pull request #5460 from akva2/newtonmethod_param_split

NewtonMethod: split parameters and properties
This commit is contained in:
Bård Skaflestad 2024-07-01 17:31:40 +02:00 committed by GitHub
commit 0f556e583b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 103 additions and 80 deletions

View File

@ -156,7 +156,7 @@ public:
{
const auto& constraintsMap = this->model().linearizer().constraintsMap();
this->lastError_ = this->error_;
Scalar newtonMaxError = Parameters::get<TypeTag, Properties::NewtonMaxError>();
Scalar newtonMaxError = Parameters::get<TypeTag, Parameters::NewtonMaxError>();
// calculate the error as the maximum weighted tolerance of
// the solution's residual

View File

@ -28,15 +28,20 @@
#ifndef FLOW_EXP_HPP
#define FLOW_EXP_HPP
#include <opm/models/discretization/common/fvbaseproblem.hh>
#include <opm/models/utils/propertysystem.hh>
#include <opm/models/utils/start.hh>
#include <opm/simulators/aquifers/BlackoilAquiferModel.hpp>
#include <opm/simulators/flow/FlowProblem.hpp>
#include <opm/simulators/flow/FlowProblemProperties.hpp>
#include <opm/models/utils/start.hh>
#include <opm/models/discretization/common/fvbaseproblem.hh>
#include <opm/simulators/aquifers/BlackoilAquiferModel.hpp>
#include <opm/simulators/linalg/ISTLSolver.hpp>
#include <opm/simulators/timestepping/EclTimeSteppingParams.hpp>
#include <opm/simulators/wells/BlackoilWellModel.hpp>
namespace Opm {
@ -125,13 +130,6 @@ struct LinearSolverBackend<TTag::FlowExpTypeTag, TTag::FlowIstlSolverParams> {
using type = ISTLSolver<TTag::FlowExpTypeTag>;
};
// the default for the allowed volumetric error for oil per second
template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::FlowExpTypeTag> {
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 1e-1;
};
// set fraction of the pore volume where the volumetric residual may be violated during
// strict Newton iterations
template<class TypeTag>
@ -140,13 +138,6 @@ struct EclNewtonRelaxedVolumeFraction<TypeTag, TTag::FlowExpTypeTag> {
static constexpr type value = 0.05;
};
// the maximum volumetric error of a cell in the relaxed region
template<class TypeTag>
struct EclNewtonRelaxedTolerance<TypeTag, TTag::FlowExpTypeTag> {
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 1e6*getPropValue<TypeTag, Properties::NewtonTolerance>();
};
// the tolerated amount of "incorrect" amount of oil per time step for the complete
// reservoir. this is scaled by the pore volume of the reservoir, i.e., larger reservoirs
// will tolerate larger residuals.
@ -169,13 +160,6 @@ struct EclNewtonStrictIterations<TypeTag, TTag::FlowExpTypeTag> {
static constexpr int value = 100;
};
// set the maximum number of Newton iterations to 8 so that we fail quickly (albeit
// relatively often)
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, TTag::FlowExpTypeTag> {
static constexpr int value = 8;
};
template<class TypeTag>
struct LinearSolverBackend<TypeTag, TTag::FlowExpTypeTag> {
using type = ISTLSolver<TypeTag>;
@ -199,8 +183,33 @@ template<class TypeTag>
struct ContinueOnConvergenceError<TypeTag, Properties::TTag::FlowExpTypeTag>
{ static constexpr bool value = true; };
// the default for the allowed volumetric error for oil per second
template<class TypeTag>
struct NewtonTolerance<TypeTag, Properties::TTag::FlowExpTypeTag>
{
using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-1;
};
// set the maximum number of Newton iterations to 8 so that we fail quickly (albeit
// relatively often)
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, Properties::TTag::FlowExpTypeTag>
{ static constexpr int value = 8; };
} // namespace Opm::Parameters
namespace Opm::Properties {
// the maximum volumetric error of a cell in the relaxed region
template<class TypeTag>
struct EclNewtonRelaxedTolerance<TypeTag, TTag::FlowExpTypeTag> {
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 1e6*Parameters::NewtonTolerance<TypeTag, TTag::FlowExpTypeTag>::value;
};
}
namespace Opm {
template <class TypeTag>
class FlowExpProblem : public FlowProblem<TypeTag> //, public FvBaseProblem<TypeTag>

View File

@ -21,6 +21,7 @@
#include "flowexp.hpp"
#include <opm/models/discretization/common/tpfalinearizer.hh>
#include <opm/models/utils/parametersystem.hh>
#include <opm/simulators/flow/Main.hpp>
#include <opm/simulators/flow/FlowProblem.hpp>
@ -61,14 +62,6 @@ struct EclNewtonSumTolerance<TypeTag, TTag::FlowExpProblemBlackOil>
static constexpr type value = 1e-5;
};
// the default for the allowed volumetric error for oil per second
template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::FlowExpProblemBlackOil>
{
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 1e-2;
};
// set fraction of the pore volume where the volumetric residual may be violated during
// strict Newton iterations
template<class TypeTag>
@ -78,13 +71,6 @@ struct EclNewtonRelaxedVolumeFraction<TypeTag, TTag::FlowExpProblemBlackOil>
static constexpr type value = 0.0;
};
template<class TypeTag>
struct EclNewtonRelaxedTolerance<TypeTag, TTag::FlowExpProblemBlackOil>
{
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 10*getPropValue<TypeTag, Properties::NewtonTolerance>();
};
template<class TypeTag>
struct EnableDiffusion<TypeTag, TTag::FlowExpProblemBlackOil>
{
@ -103,7 +89,7 @@ struct Simulator<TypeTag, TTag::FlowExpProblemBlackOil>
using type = Opm::Simulator<TypeTag>;
};
}
} // namespace Opm::Properties
namespace Opm::Parameters {
@ -115,8 +101,27 @@ template<class TypeTag>
struct ContinueOnConvergenceError<TypeTag, Properties::TTag::FlowExpProblemBlackOil>
{ static constexpr bool value = false; };
// the default for the allowed volumetric error for oil per second
template<class TypeTag>
struct NewtonTolerance<TypeTag, Properties::TTag::FlowExpProblemBlackOil>
{
using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-2;
};
} // namespace Opm::Parameters
namespace Opm::Properties {
template<class TypeTag>
struct EclNewtonRelaxedTolerance<TypeTag, TTag::FlowExpProblemBlackOil>
{
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 10 * Parameters::NewtonTolerance<TypeTag,TTag::FlowExpProblemBlackOil>::value;
};
} // namespace Opm::Properties
int main(int argc, char** argv)
{
using TypeTag = Opm::Properties::TTag::FlowExpProblemBlackOil;

View File

@ -151,11 +151,11 @@ namespace Opm {
Parameters::hideParam<TypeTag, Properties::PredeterminedTimeStepsFile>();
// flow also does not use the eWoms Newton method
Parameters::hideParam<TypeTag, Properties::NewtonMaxError>();
Parameters::hideParam<TypeTag, Properties::NewtonTolerance>();
Parameters::hideParam<TypeTag, Properties::NewtonTargetIterations>();
Parameters::hideParam<TypeTag, Properties::NewtonVerbose>();
Parameters::hideParam<TypeTag, Properties::NewtonWriteConvergence>();
Parameters::hideParam<TypeTag, Parameters::NewtonMaxError>();
Parameters::hideParam<TypeTag, Parameters::NewtonTolerance>();
Parameters::hideParam<TypeTag, Parameters::NewtonTargetIterations>();
Parameters::hideParam<TypeTag, Parameters::NewtonVerbose>();
Parameters::hideParam<TypeTag, Parameters::NewtonWriteConvergence>();
// the default eWoms checkpoint/restart mechanism does not work with flow
Parameters::hideParam<TypeTag, Properties::RestartTime>();

View File

@ -290,13 +290,6 @@ struct InitialTimeStepSize<TypeTag, TTag::FlowBaseProblem> {
static constexpr type value = 3600*24;
};
// the default for the allowed volumetric error for oil per second
template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::FlowBaseProblem> {
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 1e-2;
};
// ... but enable the ECL output by default
template<class TypeTag>
struct EnableEclOutput<TypeTag,TTag::FlowBaseProblem> {
@ -521,6 +514,14 @@ template<class TypeTag>
struct EnableStorageCache<TypeTag, Properties::TTag::FlowBaseProblem>
{ static constexpr bool value = true; };
// the default for the allowed volumetric error for oil per second
template<class TypeTag>
struct NewtonTolerance<TypeTag, Properties::TTag::FlowBaseProblem>
{
using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-2;
};
} // namespace Opm::Parameters
#endif // OPM_FLOW_PROBLEM_PROPERTIES_HPP

View File

@ -21,18 +21,22 @@
#ifndef OPM_NON_LINEAR_SOLVER_HPP
#define OPM_NON_LINEAR_SOLVER_HPP
#include <opm/simulators/timestepping/SimulatorReport.hpp>
#include <dune/common/fmatrix.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <opm/common/ErrorMacros.hpp>
#include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
#include <opm/common/Exceptions.hpp>
#include <opm/models/nonlinear/newtonmethodparameters.hh>
#include <opm/models/nonlinear/newtonmethodproperties.hh>
#include <opm/models/utils/parametersystem.hh>
#include <opm/models/utils/propertysystem.hh>
#include <opm/models/utils/basicproperties.hh>
#include <opm/models/nonlinear/newtonmethodproperties.hh>
#include <opm/common/Exceptions.hpp>
#include <dune/common/fmatrix.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <opm/simulators/timestepping/SimulatorReport.hpp>
#include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
#include <memory>
namespace Opm::Properties {
@ -64,10 +68,6 @@ struct NewtonMaxRelax<TypeTag, TTag::FlowNonLinearSolver> {
static constexpr type value = 0.5;
};
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, TTag::FlowNonLinearSolver> {
static constexpr int value = 20;
};
template<class TypeTag>
struct NewtonMinIterations<TypeTag, TTag::FlowNonLinearSolver> {
static constexpr int value = 2;
};
@ -78,6 +78,14 @@ struct NewtonRelaxationType<TypeTag, TTag::FlowNonLinearSolver> {
} // namespace Opm::Properties
namespace Opm::Parameters {
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, Properties::TTag::FlowNonLinearSolver>
{ static constexpr int value = 20; };
} // namespace Opm::Parameters
namespace Opm {
// Available relaxation scheme types.
@ -128,7 +136,7 @@ void stabilizeNonlinearUpdate(BVector& dx, BVector& dxOld,
// overload with given parameters
relaxMax_ = Parameters::get<TypeTag, Properties::NewtonMaxRelax>();
maxIter_ = Parameters::get<TypeTag, Properties::NewtonMaxIterations>();
maxIter_ = Parameters::get<TypeTag, Parameters::NewtonMaxIterations>();
minIter_ = Parameters::get<TypeTag, Properties::NewtonMinIterations>();
const auto& relaxationTypeString = Parameters::get<TypeTag, Properties::NewtonRelaxationType>();
@ -146,7 +154,7 @@ void stabilizeNonlinearUpdate(BVector& dx, BVector& dxOld,
{
Parameters::registerParam<TypeTag, Properties::NewtonMaxRelax>
("The maximum relaxation factor of a Newton iteration");
Parameters::registerParam<TypeTag, Properties::NewtonMaxIterations>
Parameters::registerParam<TypeTag, Parameters::NewtonMaxIterations>
("The maximum number of Newton iterations per time step");
Parameters::registerParam<TypeTag, Properties::NewtonMinIterations>
("The minimum number of Newton iterations per time step");

View File

@ -112,20 +112,6 @@ struct LinearSolverBackend<TTag::TestTypeTag, TTag::FlowIstlSolverParams> {
using type = ISTLSolver<TTag::TestTypeTag>;
};
// the default for the allowed volumetric error for oil per second
template<class TypeTag>
struct NewtonTolerance<TypeTag, TTag::TestTypeTag> {
using type = GetPropType<TypeTag, Scalar>;
static constexpr type value = 1e-1;
};
// set the maximum number of Newton iterations to 8 so that we fail quickly (albeit
// relatively often)
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, TTag::TestTypeTag> {
static constexpr int value = 8;
};
} // namespace Opm::Properties
namespace Opm::Parameters {
@ -144,6 +130,20 @@ template<class TypeTag>
struct ContinueOnConvergenceError<TypeTag, Properties::TTag::TestTypeTag>
{ static constexpr bool value = true; };
// the default for the allowed volumetric error for oil per second
template<class TypeTag>
struct NewtonTolerance<TypeTag, Properties::TTag::TestTypeTag>
{
using type = GetPropType<TypeTag, Properties::Scalar>;
static constexpr type value = 1e-1;
};
// set the maximum number of Newton iterations to 8 so that we fail quickly (albeit
// relatively often)
template<class TypeTag>
struct NewtonMaxIterations<TypeTag, Properties::TTag::TestTypeTag>
{ static constexpr int value = 8; };
} // namespace Opm::Parameters
#endif // OPM_TEST_TYPETAG_HPP