diff --git a/opm/autodiff/BlackoilWellModel_impl.hpp b/opm/autodiff/BlackoilWellModel_impl.hpp index bfc71c2dd..0809ef7a8 100644 --- a/opm/autodiff/BlackoilWellModel_impl.hpp +++ b/opm/autodiff/BlackoilWellModel_impl.hpp @@ -313,15 +313,14 @@ namespace Opm { return; } - const auto& wellsForTesting = wellTestState_.updateWell(wtest_config, simulationTime); - if (wellsForTesting.size() == 0) { // there is no well available for WTEST at the moment - return; - } - // average B factors are required for the convergence checking of well equations + // Note: this must be done on all processes, even those with + // no wells needing testing, otherwise we will have locking. std::vector< Scalar > B_avg(numComponents(), Scalar() ); computeAverageFormationFactor(B_avg); + wellhelpers::WellSwitchingLogger logger; + const auto& wellsForTesting = wellTestState_.updateWell(wtest_config, simulationTime); for (const auto& testWell : wellsForTesting) { const std::string& well_name = testWell.first; @@ -338,7 +337,7 @@ namespace Opm { const WellTestConfig::Reason testing_reason = testWell.second; well->wellTesting(ebosSimulator_, B_avg, simulationTime, timeStepIdx, terminal_output_, - testing_reason, well_state_, wellTestState_); + testing_reason, well_state_, wellTestState_, logger); } } diff --git a/opm/autodiff/MultisegmentWell.hpp b/opm/autodiff/MultisegmentWell.hpp index 4f3d2f9f9..e911a9e99 100644 --- a/opm/autodiff/MultisegmentWell.hpp +++ b/opm/autodiff/MultisegmentWell.hpp @@ -353,7 +353,7 @@ namespace Opm virtual void wellTestingPhysical(Simulator& simulator, const std::vector& B_avg, const double simulation_time, const int report_step, const bool terminal_output, - WellState& well_state, WellTestState& welltest_state) override; + WellState& well_state, WellTestState& welltest_state, wellhelpers::WellSwitchingLogger& logger) override; }; } diff --git a/opm/autodiff/MultisegmentWell_impl.hpp b/opm/autodiff/MultisegmentWell_impl.hpp index f3cc3730e..35b7fe1e6 100644 --- a/opm/autodiff/MultisegmentWell_impl.hpp +++ b/opm/autodiff/MultisegmentWell_impl.hpp @@ -1897,7 +1897,7 @@ namespace Opm MultisegmentWell:: wellTestingPhysical(Simulator& simulator, const std::vector& B_avg, const double simulation_time, const int report_step, const bool terminal_output, - WellState& well_state, WellTestState& welltest_state) + WellState& well_state, WellTestState& welltest_state, wellhelpers::WellSwitchingLogger& logger) { const std::string msg = "Support of well testing for physical limits for multisegment wells is not " "implemented yet, wellTestingPhysical() for " + name() + " will do nothing"; diff --git a/opm/autodiff/StandardWell.hpp b/opm/autodiff/StandardWell.hpp index 36bcc3d5d..ae342eac1 100644 --- a/opm/autodiff/StandardWell.hpp +++ b/opm/autodiff/StandardWell.hpp @@ -406,7 +406,7 @@ namespace Opm virtual void wellTestingPhysical(Simulator& simulator, const std::vector& B_avg, const double simulation_time, const int report_step, const bool terminal_output, - WellState& well_state, WellTestState& welltest_state); + WellState& well_state, WellTestState& welltest_state, wellhelpers::WellSwitchingLogger& logger) override; }; } diff --git a/opm/autodiff/StandardWell_impl.hpp b/opm/autodiff/StandardWell_impl.hpp index 2566d4021..9a280fbc0 100644 --- a/opm/autodiff/StandardWell_impl.hpp +++ b/opm/autodiff/StandardWell_impl.hpp @@ -2724,7 +2724,7 @@ namespace Opm StandardWell:: wellTestingPhysical(Simulator& ebos_simulator, const std::vector& B_avg, const double simulation_time, const int report_step, const bool terminal_output, - WellState& well_state, WellTestState& welltest_state) + WellState& well_state, WellTestState& welltest_state, wellhelpers::WellSwitchingLogger& logger) { OpmLog::debug(" well " + name() + " is being tested for physical limits"); @@ -2759,7 +2759,7 @@ namespace Opm updatePrimaryVariables(well_state_copy); initPrimaryVariablesEvaluation(); - const bool converged = this->solveWellEqUntilConverged(ebos_simulator, B_avg, well_state_copy); + const bool converged = this->solveWellEqUntilConverged(ebos_simulator, B_avg, well_state_copy, logger); if (!converged) { const std::string msg = " well " + name() + " did not get converged during well testing for physical reason"; diff --git a/opm/autodiff/WellInterface.hpp b/opm/autodiff/WellInterface.hpp index e4710a789..8d056e84e 100644 --- a/opm/autodiff/WellInterface.hpp +++ b/opm/autodiff/WellInterface.hpp @@ -219,7 +219,8 @@ namespace Opm void wellTesting(Simulator& simulator, const std::vector& B_avg, const double simulation_time, const int report_step, const bool terminal_output, const WellTestConfig::Reason testing_reason, - /* const */ WellState& well_state, WellTestState& welltest_state); + /* const */ WellState& well_state, WellTestState& welltest_state, + wellhelpers::WellSwitchingLogger& logger); void updatePerforatedCell(std::vector& is_cell_perforated); @@ -362,11 +363,11 @@ namespace Opm void wellTestingEconomic(Simulator& simulator, const std::vector& B_avg, const double simulation_time, const int report_step, const bool terminal_output, - const WellState& well_state, WellTestState& welltest_state); + const WellState& well_state, WellTestState& welltest_state, wellhelpers::WellSwitchingLogger& logger); virtual void wellTestingPhysical(Simulator& simulator, const std::vector& B_avg, const double simulation_time, const int report_step, const bool terminal_output, - WellState& well_state, WellTestState& welltest_state) = 0; + WellState& well_state, WellTestState& welltest_state, wellhelpers::WellSwitchingLogger& logger) = 0; void updateWellTestStateEconomic(const WellState& well_state, const double simulation_time, @@ -379,11 +380,13 @@ namespace Opm WellTestState& well_test_state) const; void solveWellForTesting(Simulator& ebosSimulator, WellState& well_state, - const std::vector& B_avg, bool terminal_output); + const std::vector& B_avg, bool terminal_output, + wellhelpers::WellSwitchingLogger& logger); bool solveWellEqUntilConverged(Simulator& ebosSimulator, - const std::vector& B_avg, - WellState& well_state); + const std::vector& B_avg, + WellState& well_state, + wellhelpers::WellSwitchingLogger& logger); void scaleProductivityIndex(const int perfIdx, double& productivity_index) const; diff --git a/opm/autodiff/WellInterface_impl.hpp b/opm/autodiff/WellInterface_impl.hpp index bafd0a42e..14e95d165 100644 --- a/opm/autodiff/WellInterface_impl.hpp +++ b/opm/autodiff/WellInterface_impl.hpp @@ -925,16 +925,17 @@ namespace Opm const double simulation_time, const int report_step, const bool terminal_output, const WellTestConfig::Reason testing_reason, /* const */ WellState& well_state, - WellTestState& well_test_state) + WellTestState& well_test_state, + wellhelpers::WellSwitchingLogger& logger) { if (testing_reason == WellTestConfig::Reason::PHYSICAL) { wellTestingPhysical(simulator, B_avg, simulation_time, report_step, - terminal_output, well_state, well_test_state); + terminal_output, well_state, well_test_state, logger); } if (testing_reason == WellTestConfig::Reason::ECONOMIC) { wellTestingEconomic(simulator, B_avg, simulation_time, report_step, - terminal_output, well_state, well_test_state); + terminal_output, well_state, well_test_state, logger); } } @@ -947,7 +948,7 @@ namespace Opm WellInterface:: wellTestingEconomic(Simulator& simulator, const std::vector& B_avg, const double simulation_time, const int report_step, const bool terminal_output, - const WellState& well_state, WellTestState& welltest_state) + const WellState& well_state, WellTestState& welltest_state, wellhelpers::WellSwitchingLogger& logger) { OpmLog::debug(" well " + name() + " is being tested for economic limits"); @@ -965,7 +966,7 @@ namespace Opm // untill the number of closed completions do not increase anymore. while (testWell) { const size_t original_number_closed_completions = welltest_state_temp.sizeCompletions(); - solveWellForTesting(simulator, well_state_copy, B_avg, terminal_output); + solveWellForTesting(simulator, well_state_copy, B_avg, terminal_output, logger); updateWellTestState(well_state_copy, simulation_time, /*writeMessageToOPMLog=*/ false, welltest_state_temp); closeCompletions(welltest_state_temp); @@ -1152,7 +1153,8 @@ namespace Opm WellInterface:: solveWellEqUntilConverged(Simulator& ebosSimulator, const std::vector& B_avg, - WellState& well_state) + WellState& well_state, + wellhelpers::WellSwitchingLogger& logger) { const int max_iter = param_.max_welleq_iter_; int it = 0; @@ -1171,7 +1173,6 @@ namespace Opm ++it; solveEqAndUpdateWellState(well_state); - wellhelpers::WellSwitchingLogger logger; updateWellControl(ebosSimulator, well_state, logger); initPrimaryVariablesEvaluation(); } while (it < max_iter); @@ -1222,13 +1223,12 @@ namespace Opm void WellInterface:: solveWellForTesting(Simulator& ebosSimulator, WellState& well_state, - const std::vector& B_avg, bool terminal_output) + const std::vector& B_avg, bool terminal_output, + wellhelpers::WellSwitchingLogger& logger) { // keep a copy of the original well state const WellState well_state0 = well_state; - - const bool converged = solveWellEqUntilConverged(ebosSimulator, B_avg, well_state); - + const bool converged = solveWellEqUntilConverged(ebosSimulator, B_avg, well_state, logger); if (converged) { if ( terminal_output ) { OpmLog::debug("WellTest: Well equation for well " + name() + " solution gets converged");