From 7b90d35f21191f5be83025d432554d37ac031871 Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Mon, 17 Oct 2022 15:22:04 +0200 Subject: [PATCH] fixup from PR comments --- .../timestepping/SimulatorReport.cpp | 1 + .../timestepping/SimulatorReport.hpp | 1 + opm/simulators/wells/BlackoilWellModel.hpp | 4 ++-- .../wells/BlackoilWellModel_impl.hpp | 24 ++++++++++--------- opm/simulators/wells/MultisegmentWellEval.cpp | 6 ++--- opm/simulators/wells/StandardWellEval.cpp | 7 +++--- opm/simulators/wells/WellInterface_impl.hpp | 8 +++---- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/opm/simulators/timestepping/SimulatorReport.cpp b/opm/simulators/timestepping/SimulatorReport.cpp index 7aef68b8c..6b63104cf 100644 --- a/opm/simulators/timestepping/SimulatorReport.cpp +++ b/opm/simulators/timestepping/SimulatorReport.cpp @@ -50,6 +50,7 @@ namespace Opm min_linear_iterations ( std::numeric_limits::max() ), max_linear_iterations ( 0 ), converged(false), + well_group_control_changed(false), exit_status(EXIT_SUCCESS), global_time(0), timestep_length(0.0) diff --git a/opm/simulators/timestepping/SimulatorReport.hpp b/opm/simulators/timestepping/SimulatorReport.hpp index 699dd2f0a..41b2edad2 100644 --- a/opm/simulators/timestepping/SimulatorReport.hpp +++ b/opm/simulators/timestepping/SimulatorReport.hpp @@ -50,6 +50,7 @@ namespace Opm bool converged; + bool well_group_control_changed; int exit_status; double global_time; diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index df9ddffa9..e25ff5ab3 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -260,7 +260,7 @@ namespace Opm { void applyScaleAdd(const Scalar alpha, const BVector& x, BVector& Ax) const; // Check if well equations is converged. - ConvergenceReport getWellConvergence(const std::vector& B_avg, const bool checkWellGroupControls = false); + ConvergenceReport getWellConvergence(const std::vector& B_avg, const bool checkWellGroupControls = false) const; const SimulatorReportSingle& lastReport() const; @@ -373,7 +373,7 @@ namespace Opm { // and in the well equations. void assemble(const int iterationIdx, const double dt); - void assembleImpl(const int iterationIdx, + bool assembleImpl(const int iterationIdx, const double dt, const std::size_t recursion_level, DeferredLogger& local_deferredLogger); diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index edb08b79d..cf06ab035 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -880,9 +880,11 @@ namespace Opm { terminal_output_, grid().comm()); } - assembleImpl(iterationIdx, dt, 0, local_deferredLogger); + const bool well_group_control_changed = assembleImpl(iterationIdx, dt, 0, local_deferredLogger); - last_report_.converged = true; + // if group or well control changes we don't consider the + // case converged + last_report_.well_group_control_changed = well_group_control_changed; last_report_.assemble_time_well += perfTimer.stop(); } @@ -891,7 +893,7 @@ namespace Opm { template - void + bool BlackoilWellModel:: assembleImpl(const int iterationIdx, const double dt, @@ -899,7 +901,7 @@ namespace Opm { DeferredLogger& local_deferredLogger) { - const auto [group_well_changed, network_changed, network_imbalance] = updateWellControls(local_deferredLogger); + auto [well_group_control_changed, network_changed, network_imbalance] = updateWellControls(local_deferredLogger); bool alq_updated = false; OPM_BEGIN_PARALLEL_TRY_CATCH(); @@ -931,10 +933,11 @@ namespace Opm { const auto& balance = schedule()[reportStepIdx].network_balance(); // Iterate if not converged, and number of iterations is not yet max (NETBALAN item 3). if (recursion_level < balance.pressure_max_iter() && network_imbalance > balance.pressure_tolerance()) { - assembleImpl(iterationIdx, dt, recursion_level + 1, local_deferredLogger); + well_group_control_changed = assembleImpl(iterationIdx, dt, recursion_level + 1, local_deferredLogger); } } } + return well_group_control_changed; } @@ -1389,7 +1392,7 @@ namespace Opm { template ConvergenceReport BlackoilWellModel:: - getWellConvergence(const std::vector& B_avg, bool checkWellGroupControls) + getWellConvergence(const std::vector& B_avg, bool checkWellGroupControls) const { DeferredLogger local_deferredLogger; @@ -1409,14 +1412,13 @@ namespace Opm { const Opm::Parallel::Communication comm = grid().comm(); DeferredLogger global_deferredLogger = gatherDeferredLogger(local_deferredLogger, comm); - - ConvergenceReport report = gatherConvergenceReport(local_report, comm); - if (report.converged() && checkWellGroupControls) { - const auto [group_well_changed, network_changed, network_imbalance] = updateWellControls(global_deferredLogger); - report.setWellGroupTargetsViolated(group_well_changed); + // the well_group_control_changed info is already communicated + if (checkWellGroupControls) { + report.setWellGroupTargetsViolated(this->lastReport().well_group_control_changed); } + if (terminal_output_) { global_deferredLogger.logMessages(); } diff --git a/opm/simulators/wells/MultisegmentWellEval.cpp b/opm/simulators/wells/MultisegmentWellEval.cpp index 009c135d1..85a1483bb 100644 --- a/opm/simulators/wells/MultisegmentWellEval.cpp +++ b/opm/simulators/wells/MultisegmentWellEval.cpp @@ -1363,10 +1363,10 @@ updateThp(WellState& well_state, ws.thp = 0; return; } - // For THP controled wells, we know the thp value - bool thp_controled = baseif_.isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP: + // For THP controlled wells, we know the thp value + bool thp_controlled = baseif_.isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP: ws.production_cmode == Well::ProducerCMode::THP; - if (thp_controled) { + if (thp_controlled) { return; } diff --git a/opm/simulators/wells/StandardWellEval.cpp b/opm/simulators/wells/StandardWellEval.cpp index 6cbc1291a..5e2dbbc58 100644 --- a/opm/simulators/wells/StandardWellEval.cpp +++ b/opm/simulators/wells/StandardWellEval.cpp @@ -573,14 +573,13 @@ updateThp(WellState& well_state, return; } - // For THP controled wells, we know the thp value - bool thp_controled = baseif_.isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP: + // For THP controlled wells, we know the thp value + bool thp_controlled = baseif_.isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP: ws.production_cmode == Well::ProducerCMode::THP; - if (thp_controled) { + if (thp_controlled) { return; } - // the well is under other control types, we calculate the thp based on bhp and rates std::vector rates(3, 0.0); diff --git a/opm/simulators/wells/WellInterface_impl.hpp b/opm/simulators/wells/WellInterface_impl.hpp index 3f44f361d..b553d4cfe 100644 --- a/opm/simulators/wells/WellInterface_impl.hpp +++ b/opm/simulators/wells/WellInterface_impl.hpp @@ -710,15 +710,15 @@ namespace Opm { this->operability_status_.resetOperability(); - bool thp_controled = this->isInjector() ? well_state.well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP: + bool thp_controlled = this->isInjector() ? well_state.well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP: well_state.well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP; - bool bhp_controled = this->isInjector() ? well_state.well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP: + bool bhp_controlled = this->isInjector() ? well_state.well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP: well_state.well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP; // Operability checking is not free // Only check wells under BHP and THP control - bool check_thp = thp_controled || this->operability_status_.thp_limit_violated_but_not_switched; - if (check_thp || bhp_controled) { + bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched; + if (check_thp || bhp_controlled) { updateIPR(ebos_simulator, deferred_logger); checkOperabilityUnderBHPLimit(well_state, ebos_simulator, deferred_logger); }