Merge pull request #6378 from daavid00/newtmxn

Support for NEWTMX and NEWTMN in TUNING
This commit is contained in:
Tor Harald Sandve authored and GitHub committed 2025-09-05 14:26:39 +02:00
commit 1b54832d2f
10 files changed
+97 -44

No files matched your search

+3 -3
View File
@@ -365,7 +365,7 @@ ParamType Get_(const std::string& paramName, ParamType defaultValue,
{
if (errorIfNotRegistered) {
if (MetaData::registrationOpen()) {
throw std::runtime_error("Parameters can only retrieved after _all_ of them have "
throw std::runtime_error("Parameters can only be retrieved after _all_ of them have "
"been registered.");
}
@@ -427,7 +427,7 @@ bool IsSet_(const std::string& paramName, bool errorIfNotRegistered)
{
if (errorIfNotRegistered) {
if (MetaData::registrationOpen()) {
throw std::runtime_error("Parameters can only checked after _all_ of them have "
throw std::runtime_error("Parameters can only be checked after _all_ of them have "
"been registered.");
}
@@ -509,7 +509,7 @@ void getLists(std::vector<Parameter>& usedParams,
unusedParams.clear();
if (MetaData::registrationOpen()) {
throw std::runtime_error("Parameter lists can only retrieved after _all_ of them have "
throw std::runtime_error("Parameter lists can only be retrieved after _all_ of them have "
"been registered.");
}
+2 -1
View File
@@ -247,7 +247,8 @@ public:
return report;
}
model_.initialLinearization(report, iteration, nonlinear_solver.minIter(), nonlinear_solver.maxIter(), timer);
model_.initialLinearization(report, iteration, model_.param().newton_min_iter_,
model_.param().newton_max_iter_, timer);
if (report.converged) {
return report;
@@ -22,6 +22,8 @@
#include <opm/models/discretization/common/fvbaseparameters.hh>
#include <opm/models/nonlinear/newtonmethodparams.hpp>
#include <opm/models/utils/parametersystem.hpp>
#include <algorithm>
@@ -92,6 +94,8 @@ BlackoilModelParameters<Scalar>::BlackoilModelParameters()
max_local_solve_iterations_ = Parameters::Get<Parameters::MaxLocalSolveIterations>();
local_tolerance_scaling_mb_ = Parameters::Get<Parameters::LocalToleranceScalingMb<Scalar>>();
local_tolerance_scaling_cnv_ = Parameters::Get<Parameters::LocalToleranceScalingCnv<Scalar>>();
newton_max_iter_ = Parameters::Get<Parameters::NewtonMaxIterations>();
newton_min_iter_ = Parameters::Get<Parameters::NewtonMinIterations>();
nldd_num_initial_newton_iter_ = Parameters::Get<Parameters::NlddNumInitialNewtonIter>();
nldd_relative_mobility_change_tol_ = Parameters::Get<Parameters::NlddRelativeMobilityChangeTol<Scalar>>();
num_local_domains_ = Parameters::Get<Parameters::NumLocalDomains>();
@@ -242,6 +246,9 @@ void BlackoilModelParameters<Scalar>::registerParameters()
("Choose nonlinear solver. Valid choices are newton or nldd.");
Parameters::Register<Parameters::LocalSolveApproach>
("Choose local solve approach. Valid choices are jacobi and gauss-seidel");
Parameters::SetDefault<Parameters::NewtonMaxIterations>(20);
Parameters::Register<Parameters::NewtonMinIterations>
("The minimum number of Newton iterations per time step");
Parameters::Register<Parameters::MaxLocalSolveIterations>
("Max iterations for local solves with NLDD nonlinear solver.");
Parameters::Register<Parameters::LocalToleranceScalingMb<Scalar>>
@@ -140,6 +140,7 @@ struct NetworkMaxPressureUpdateInBars { static constexpr Scalar value = 5.0; };
struct NonlinearSolver { static constexpr auto value = "newton"; };
struct LocalSolveApproach { static constexpr auto value = "gauss-seidel"; };
struct MaxLocalSolveIterations { static constexpr int value = 20; };
struct NewtonMinIterations { static constexpr int value = 2; };
struct WellGroupConstraintsMaxIterations { static constexpr int value = 1; };
template<class Scalar>
@@ -267,7 +268,7 @@ public:
/// Update scaling factors for mass balance equations
bool update_equations_scaling_;
/// Try to detect oscillation or stagnation.
/// Try to detect oscillation or stagnation
bool use_update_stabilization_;
/// Whether to use MultisegmentWell to handle multisegment wells
@@ -327,11 +328,18 @@ public:
/// Maximum number of status switches (open<->shut> in local well iterations
int max_well_status_switch_;
/// Nonlinear solver type: newton or nldd.
/// Nonlinear solver type: newton or nldd
std::string nonlinear_solver_;
/// 'jacobi' and 'gauss-seidel' supported.
/// 'jacobi' and 'gauss-seidel' supported
DomainSolveApproach local_solve_approach_{DomainSolveApproach::Jacobi};
/// Maximum number of Newton iterations per time step
int newton_max_iter_;
/// Minimum number of Newton iterations per time step
int newton_min_iter_;
int max_local_solve_iterations_;
Scalar local_tolerance_scaling_mb_;
+4 -9
View File
@@ -259,8 +259,8 @@ nonlinearIterationNewton(const int iteration,
this->initialLinearization(report,
iteration,
nonlinear_solver.minIter(),
nonlinear_solver.maxIter(),
this->param_.newton_min_iter_,
this->param_.newton_max_iter_,
timer);
// ----------- If not converged, solve linear system and do Newton update -----------
@@ -730,13 +730,8 @@ updateTUNING(const Tuning& tuning)
this->param_.tolerance_cnv_relaxed_ = tuning.XXXCNV;
this->param_.tolerance_mb_ = tuning.TRGMBE;
this->param_.tolerance_mb_relaxed_ = tuning.XXXMBE;
if (terminal_output_) {
const auto msg = fmt::format("Tuning BlackoilModel tolerances: "
"MB: {:.2e}, CNV: {:.2e}",
tuning.TRGMBE, tuning.TRGCNV);
OpmLog::debug(msg);
}
this->param_.newton_max_iter_ = tuning.NEWTMX;
this->param_.newton_min_iter_ = tuning.NEWTMN;
}
template <class TypeTag>
-10
View File
@@ -141,8 +141,6 @@ NonlinearSolverParameters()
// overload with given parameters
relaxMax_ = Parameters::Get<Parameters::NewtonMaxRelax<Scalar>>();
maxIter_ = Parameters::Get<Parameters::NewtonMaxIterations>();
minIter_ = Parameters::Get<Parameters::NewtonMinIterations>();
const auto& relaxationTypeString = Parameters::Get<Parameters::NewtonRelaxationType>();
if (relaxationTypeString == "dampen") {
@@ -164,8 +162,6 @@ reset()
relaxMax_ = 0.5;
relaxIncrement_ = 0.1;
relaxRelTol_ = 0.2;
maxIter_ = 10;
minIter_ = 1;
}
template<class Scalar>
@@ -174,14 +170,8 @@ registerParameters()
{
Parameters::Register<Parameters::NewtonMaxRelax<Scalar>>
("The maximum relaxation factor of a Newton iteration");
Parameters::Register<Parameters::NewtonMaxIterations>
("The maximum number of Newton iterations per time step");
Parameters::Register<Parameters::NewtonMinIterations>
("The minimum number of Newton iterations per time step");
Parameters::Register<Parameters::NewtonRelaxationType>
("The type of relaxation used by Newton method");
Parameters::SetDefault<Parameters::NewtonMaxIterations>(20);
}
template struct NonlinearSolverParameters<double>;
+7 -15
View File
@@ -44,7 +44,6 @@ namespace Opm::Parameters {
template<class Scalar>
struct NewtonMaxRelax { static constexpr Scalar value = 0.5; };
struct NewtonMinIterations { static constexpr int value = 2; };
struct NewtonRelaxationType { static constexpr auto value = "dampen"; };
} // namespace Opm::Parameters
@@ -82,8 +81,6 @@ struct NonlinearSolverParameters
Scalar relaxMax_;
Scalar relaxIncrement_;
Scalar relaxRelTol_;
int maxIter_; // max nonlinear iterations
int minIter_; // min nonlinear iterations
NonlinearSolverParameters();
@@ -150,7 +147,7 @@ struct NonlinearSolverParameters
try {
// Do the nonlinear step. If we are in a converged state, the
// model will usually do an early return without an expensive
// solve, unless the minIter() count has not been reached yet.
// solve, unless the newton_min_iter_ count has not been reached yet.
auto iterReport = model_->nonlinearIteration(iteration, timer, *this);
iterReport.global_time = timer.simulationTimeElapsed();
report += iterReport;
@@ -167,12 +164,14 @@ struct NonlinearSolverParameters
throw;
}
}
while ( (!converged && (iteration <= maxIter())) || (iteration <= minIter()));
while ( (!converged && (iteration <= this->model().param().newton_max_iter_)) ||
(iteration <= this->model().param().newton_min_iter_));
if (!converged) {
failureReport_ = report;
std::string msg = "Solver convergence failure - Failed to complete a time step within " + std::to_string(maxIter()) + " iterations.";
std::string msg = "Solver convergence failure - Failed to complete a time step within ";
msg += std::to_string(model().param().newton_max_iter_) + " iterations.";
OPM_THROW_NOLOG(TooManyIterations, msg);
}
auto relativeChange = model_->relativeChange();
@@ -181,7 +180,8 @@ struct NonlinearSolverParameters
report.time_step_rejected = true;
failureReport_ = report;
std::string msg = "Relative change in solution for time step was " + std::to_string(relativeChange) + ", which is larger than the tolerance accepted by the timestepping algorithm.";
std::string msg = "Relative change in solution for time step was " + std::to_string(relativeChange);
msg += ", which is larger than the tolerance accepted by the timestepping algorithm.";
OPM_THROW_NOLOG(TimeSteppingBreakdown, msg);
}
@@ -268,14 +268,6 @@ struct NonlinearSolverParameters
Scalar relaxRelTol() const
{ return param_.relaxRelTol_; }
/// The maximum number of nonlinear iterations allowed.
int maxIter() const
{ return param_.maxIter_; }
/// The minimum number of nonlinear iterations allowed.
int minIter() const
{ return param_.minIter_; }
/// Set parameters to override those given at construction time.
void setParameters(const SolverParameters& param)
{ param_ = param; }
@@ -312,11 +312,67 @@ public:
modelParam_.tolerance_cnv_relaxed_ = tuning.XXXCNV;
modelParam_.tolerance_mb_ = tuning.TRGMBE;
modelParam_.tolerance_mb_relaxed_ = tuning.XXXMBE;
modelParam_.newton_max_iter_ = tuning.NEWTMX;
modelParam_.newton_min_iter_ = tuning.NEWTMN;
if (terminalOutput_) {
const auto msg = fmt::format("Tuning SimulatorFullyImplicitBlackoil tolerances: "
"MB: {:.2e}, CNV: {:.2e}",
tuning.TRGMBE, tuning.TRGCNV);
const auto msg = fmt::format("Tuning values: "
"MB: {:.2e}, CNV: {:.2e}, NEWTMN: {}, NEWTMX: {}",
tuning.TRGMBE, tuning.TRGCNV, tuning.NEWTMN, tuning.NEWTMX);
OpmLog::debug(msg);
if (tuning.TRGTTE_has_value) {
OpmLog::warning("Tuning item 2-1 (TRGTTE) is not supported.");
}
if (tuning.TRGLCV_has_value) {
OpmLog::warning("Tuning item 2-4 (TRGLCV) is not supported.");
}
if (tuning.XXXTTE_has_value) {
OpmLog::warning("Tuning item 2-5 (XXXTTE) is not supported.");
}
if (tuning.XXXLCV_has_value) {
OpmLog::warning("Tuning item 2-8 (XXXLCV) is not supported.");
}
if (tuning.XXXWFL_has_value) {
OpmLog::warning("Tuning item 2-9 (XXXWFL) is not supported.");
}
if (tuning.TRGFIP_has_value) {
OpmLog::warning("Tuning item 2-10 (TRGFIP) is not supported.");
}
if (tuning.TRGSFT_has_value) {
OpmLog::warning("Tuning item 2-11 (TRGSFT) is not supported.");
}
if (tuning.THIONX_has_value) {
OpmLog::warning("Tuning item 2-12 (THIONX) is not supported.");
}
if (tuning.TRWGHT_has_value) {
OpmLog::warning("Tuning item 2-13 (TRWGHT) is not supported.");
}
if (tuning.LITMAX_has_value) {
OpmLog::warning("Tuning item 3-3 (LITMAX) is not supported.");
}
if (tuning.LITMIN_has_value) {
OpmLog::warning("Tuning item 3-4 (LITMIN) is not supported.");
}
if (tuning.MXWSIT_has_value) {
OpmLog::warning("Tuning item 3-5 (MXWSIT) is not supported.");
}
if (tuning.MXWPIT_has_value) {
OpmLog::warning("Tuning item 3-6 (MXWPIT) is not supported.");
}
if (tuning.DDPLIM_has_value) {
OpmLog::warning("Tuning item 3-7 (DDPLIM) is not supported.");
}
if (tuning.DDSLIM_has_value) {
OpmLog::warning("Tuning item 3-8 (DDSLIM) is not supported.");
}
if (tuning.TRGDPR_has_value) {
OpmLog::warning("Tuning item 3-9 (TRGDPR) is not supported.");
}
if (tuning.XXXDPR_has_value) {
OpmLog::warning("Tuning item 3-10 (XXXDPR) is not supported.");
}
if (tuning.MNWRFP_has_value) {
OpmLog::warning("Tuning item 3-11 (MNWRFP) is not supported.");
}
}
}
+2
View File
@@ -532,6 +532,8 @@ struct AquiferFixture {
"test_RestartSerialization",
"--ecl-deck-file-name=GLIFT1.DATA"
};
// Since this parameter is registered in opm/models/nonlinear/newtonmethodparams.cpp but not accessed here
Parameters::Register<Parameters::NewtonMaxIterations>("The maximum number of Newton iterations per time step");
Opm::ThreadManager::registerParameters();
AdaptiveTimeStepping<TT>::registerParameters();
BlackoilModelParameters<double>::registerParameters();
+2
View File
@@ -247,6 +247,8 @@ struct EquilFixture {
using namespace Opm;
FlowGenericVanguard::setCommunication(std::make_unique<Opm::Parallel::Communication>());
Opm::ThreadManager::registerParameters();
// Since this parameter is registered in opm/models/nonlinear/newtonmethodparams.cpp but not accessed here
Parameters::Register<Parameters::NewtonMaxIterations>("The maximum number of Newton iterations per time step");
BlackoilModelParameters<double>::registerParameters();
AdaptiveTimeStepping<TypeTag>::registerParameters();
Parameters::Register<Parameters::EnableTerminalOutput>("Dummy added for the well model to compile.");