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(); const auto& constraintsMap = this->model().linearizer().constraintsMap();
this->lastError_ = this->error_; 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 // calculate the error as the maximum weighted tolerance of
// the solution's residual // the solution's residual

View File

@ -28,15 +28,20 @@
#ifndef FLOW_EXP_HPP #ifndef FLOW_EXP_HPP
#define 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/FlowProblem.hpp>
#include <opm/simulators/flow/FlowProblemProperties.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/linalg/ISTLSolver.hpp>
#include <opm/simulators/timestepping/EclTimeSteppingParams.hpp> #include <opm/simulators/timestepping/EclTimeSteppingParams.hpp>
#include <opm/simulators/wells/BlackoilWellModel.hpp> #include <opm/simulators/wells/BlackoilWellModel.hpp>
namespace Opm { namespace Opm {
@ -125,13 +130,6 @@ struct LinearSolverBackend<TTag::FlowExpTypeTag, TTag::FlowIstlSolverParams> {
using type = ISTLSolver<TTag::FlowExpTypeTag>; 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 // set fraction of the pore volume where the volumetric residual may be violated during
// strict Newton iterations // strict Newton iterations
template<class TypeTag> template<class TypeTag>
@ -140,13 +138,6 @@ struct EclNewtonRelaxedVolumeFraction<TypeTag, TTag::FlowExpTypeTag> {
static constexpr type value = 0.05; 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 // 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 // reservoir. this is scaled by the pore volume of the reservoir, i.e., larger reservoirs
// will tolerate larger residuals. // will tolerate larger residuals.
@ -169,13 +160,6 @@ struct EclNewtonStrictIterations<TypeTag, TTag::FlowExpTypeTag> {
static constexpr int value = 100; 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> template<class TypeTag>
struct LinearSolverBackend<TypeTag, TTag::FlowExpTypeTag> { struct LinearSolverBackend<TypeTag, TTag::FlowExpTypeTag> {
using type = ISTLSolver<TypeTag>; using type = ISTLSolver<TypeTag>;
@ -199,8 +183,33 @@ template<class TypeTag>
struct ContinueOnConvergenceError<TypeTag, Properties::TTag::FlowExpTypeTag> struct ContinueOnConvergenceError<TypeTag, Properties::TTag::FlowExpTypeTag>
{ static constexpr bool value = true; }; { 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::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 { namespace Opm {
template <class TypeTag> template <class TypeTag>
class FlowExpProblem : public FlowProblem<TypeTag> //, public FvBaseProblem<TypeTag> class FlowExpProblem : public FlowProblem<TypeTag> //, public FvBaseProblem<TypeTag>

View File

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

View File

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

View File

@ -290,13 +290,6 @@ struct InitialTimeStepSize<TypeTag, TTag::FlowBaseProblem> {
static constexpr type value = 3600*24; 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 // ... but enable the ECL output by default
template<class TypeTag> template<class TypeTag>
struct EnableEclOutput<TypeTag,TTag::FlowBaseProblem> { struct EnableEclOutput<TypeTag,TTag::FlowBaseProblem> {
@ -521,6 +514,14 @@ template<class TypeTag>
struct EnableStorageCache<TypeTag, Properties::TTag::FlowBaseProblem> struct EnableStorageCache<TypeTag, Properties::TTag::FlowBaseProblem>
{ static constexpr bool value = true; }; { 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 } // namespace Opm::Parameters
#endif // OPM_FLOW_PROBLEM_PROPERTIES_HPP #endif // OPM_FLOW_PROBLEM_PROPERTIES_HPP

View File

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