diff --git a/opm/models/utils/parametersystem.cpp b/opm/models/utils/parametersystem.cpp index d873266577..62f2fb7577 100644 --- a/opm/models/utils/parametersystem.cpp +++ b/opm/models/utils/parametersystem.cpp @@ -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& 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."); } diff --git a/opm/simulators/flow/BlackoilModelNldd.hpp b/opm/simulators/flow/BlackoilModelNldd.hpp index 6eaed9348e..705b9d5494 100644 --- a/opm/simulators/flow/BlackoilModelNldd.hpp +++ b/opm/simulators/flow/BlackoilModelNldd.hpp @@ -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; diff --git a/opm/simulators/flow/BlackoilModelParameters.cpp b/opm/simulators/flow/BlackoilModelParameters.cpp index 2006849dd6..f7b14fa38c 100644 --- a/opm/simulators/flow/BlackoilModelParameters.cpp +++ b/opm/simulators/flow/BlackoilModelParameters.cpp @@ -22,6 +22,8 @@ #include +#include + #include #include @@ -92,6 +94,8 @@ BlackoilModelParameters::BlackoilModelParameters() max_local_solve_iterations_ = Parameters::Get(); local_tolerance_scaling_mb_ = Parameters::Get>(); local_tolerance_scaling_cnv_ = Parameters::Get>(); + newton_max_iter_ = Parameters::Get(); + newton_min_iter_ = Parameters::Get(); nldd_num_initial_newton_iter_ = Parameters::Get(); nldd_relative_mobility_change_tol_ = Parameters::Get>(); num_local_domains_ = Parameters::Get(); @@ -242,6 +246,9 @@ void BlackoilModelParameters::registerParameters() ("Choose nonlinear solver. Valid choices are newton or nldd."); Parameters::Register ("Choose local solve approach. Valid choices are jacobi and gauss-seidel"); + Parameters::SetDefault(20); + Parameters::Register + ("The minimum number of Newton iterations per time step"); Parameters::Register ("Max iterations for local solves with NLDD nonlinear solver."); Parameters::Register> diff --git a/opm/simulators/flow/BlackoilModelParameters.hpp b/opm/simulators/flow/BlackoilModelParameters.hpp index 228f5e5285..daeb2703fd 100644 --- a/opm/simulators/flow/BlackoilModelParameters.hpp +++ b/opm/simulators/flow/BlackoilModelParameters.hpp @@ -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 @@ -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_; diff --git a/opm/simulators/flow/BlackoilModel_impl.hpp b/opm/simulators/flow/BlackoilModel_impl.hpp index 4b126408a3..3ee1bb4006 100644 --- a/opm/simulators/flow/BlackoilModel_impl.hpp +++ b/opm/simulators/flow/BlackoilModel_impl.hpp @@ -262,8 +262,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 ----------- @@ -733,13 +733,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 diff --git a/opm/simulators/flow/NonlinearSolver.cpp b/opm/simulators/flow/NonlinearSolver.cpp index 585c1673be..9cb4e8da8f 100644 --- a/opm/simulators/flow/NonlinearSolver.cpp +++ b/opm/simulators/flow/NonlinearSolver.cpp @@ -141,8 +141,6 @@ NonlinearSolverParameters() // overload with given parameters relaxMax_ = Parameters::Get>(); - maxIter_ = Parameters::Get(); - minIter_ = Parameters::Get(); const auto& relaxationTypeString = Parameters::Get(); if (relaxationTypeString == "dampen") { @@ -164,8 +162,6 @@ reset() relaxMax_ = 0.5; relaxIncrement_ = 0.1; relaxRelTol_ = 0.2; - maxIter_ = 10; - minIter_ = 1; } template @@ -174,14 +170,8 @@ registerParameters() { Parameters::Register> ("The maximum relaxation factor of a Newton iteration"); - Parameters::Register - ("The maximum number of Newton iterations per time step"); - Parameters::Register - ("The minimum number of Newton iterations per time step"); Parameters::Register ("The type of relaxation used by Newton method"); - - Parameters::SetDefault(20); } template struct NonlinearSolverParameters; diff --git a/opm/simulators/flow/NonlinearSolver.hpp b/opm/simulators/flow/NonlinearSolver.hpp index 0f7e8016f3..44a8c4e195 100644 --- a/opm/simulators/flow/NonlinearSolver.hpp +++ b/opm/simulators/flow/NonlinearSolver.hpp @@ -44,7 +44,6 @@ namespace Opm::Parameters { template 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; } diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp index 79c1029463..df0b5fba00 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp @@ -313,11 +313,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."); + } } } diff --git a/tests/test_RestartSerialization.cpp b/tests/test_RestartSerialization.cpp index 57606d364d..21682df81f 100644 --- a/tests/test_RestartSerialization.cpp +++ b/tests/test_RestartSerialization.cpp @@ -526,6 +526,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("The maximum number of Newton iterations per time step"); Opm::ThreadManager::registerParameters(); AdaptiveTimeStepping::registerParameters(); BlackoilModelParameters::registerParameters(); diff --git a/tests/test_equil.cpp b/tests/test_equil.cpp index 8324940729..334e4b6964 100644 --- a/tests/test_equil.cpp +++ b/tests/test_equil.cpp @@ -247,6 +247,8 @@ struct EquilFixture { using namespace Opm; FlowGenericVanguard::setCommunication(std::make_unique()); Opm::ThreadManager::registerParameters(); + // Since this parameter is registered in opm/models/nonlinear/newtonmethodparams.cpp but not accessed here + Parameters::Register("The maximum number of Newton iterations per time step"); BlackoilModelParameters::registerParameters(); AdaptiveTimeStepping::registerParameters(); Parameters::Register("Dummy added for the well model to compile.");