diff --git a/opm/simulators/utils/ParallelSerialization.cpp b/opm/simulators/utils/ParallelSerialization.cpp index 949851442..494438f9f 100644 --- a/opm/simulators/utils/ParallelSerialization.cpp +++ b/opm/simulators/utils/ParallelSerialization.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index bc26f30f3..c9c3923d9 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -278,7 +278,6 @@ namespace Opm { // at the beginning of each time step (Not report step) void prepareTimeStep(DeferredLogger& deferred_logger); void initPrimaryVariablesEvaluation() const; - bool shouldBalanceNetwork(const int reportStepIndex, const int iterationIdx) const; std::tuple updateWellControls(DeferredLogger& deferred_logger); void updateAndCommunicate(const int reportStepIdx, diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index 2fd52bab1..dc6a5900e 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -1206,4 +1207,35 @@ runWellPIScaling(const int timeStepIdx, this->last_run_wellpi_ = timeStepIdx; } +bool +BlackoilWellModelGeneric:: +shouldBalanceNetwork(const int reportStepIdx, const int iterationIdx) const +{ + const auto& balance = schedule()[reportStepIdx].network_balance(); + if (balance.mode() == Network::Balance::CalcMode::TimeStepStart) { + return iterationIdx == 0; + } else if (balance.mode() == Network::Balance::CalcMode::NUPCOL) { + const int nupcol = schedule()[reportStepIdx].nupcol(); + return iterationIdx < nupcol; + } else { + // We do not support any other rebalancing modes, + // i.e. TimeInterval based rebalancing is not available. + // This should be warned about elsewhere, so we choose to + // avoid spamming with a warning here. + return false; + } +} + +bool +BlackoilWellModelGeneric:: +shouldIterateNetwork(const int reportStepIdx, + const std::size_t recursion_level, + const double network_imbalance) const +{ + const auto& balance = schedule()[reportStepIdx].network_balance(); + // Iterate if not converged, and number of iterations is not yet max (NETBALAN item 3). + return recursion_level < balance.pressure_max_iter() && + network_imbalance > balance.pressure_tolerance(); +} + } diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index 9f90d9ca9..4eee2876f 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -170,6 +170,13 @@ public: bool reportStepStarts() const { return report_step_starts_; } + bool shouldBalanceNetwork(const int reportStepIndex, + const int iterationIdx) const; + + bool shouldIterateNetwork(const int reportStepIndex, + const std::size_t recursion_level, + const double network_imbalance) const; + protected: /* diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index e3e037062..53e7412f4 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -23,6 +23,7 @@ #include #include #include + #include #include @@ -934,12 +935,9 @@ namespace Opm { // Maybe do a recursive call to iterate network and well controls. if (network_changed) { - if (shouldBalanceNetwork(reportStepIdx, iterationIdx)) { - 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()) { - well_group_control_changed = assembleImpl(iterationIdx, dt, recursion_level + 1, local_deferredLogger); - } + if (shouldBalanceNetwork(reportStepIdx, iterationIdx) && + shouldIterateNetwork(reportStepIdx, recursion_level, network_imbalance)) { + well_group_control_changed = assembleImpl(iterationIdx, dt, recursion_level + 1, local_deferredLogger); } } return well_group_control_changed; @@ -1446,30 +1444,6 @@ namespace Opm { - template - bool - BlackoilWellModel:: - shouldBalanceNetwork(const int reportStepIdx, const int iterationIdx) const - { - const auto& balance = schedule()[reportStepIdx].network_balance(); - if (balance.mode() == Network::Balance::CalcMode::TimeStepStart) { - return iterationIdx == 0; - } else if (balance.mode() == Network::Balance::CalcMode::NUPCOL) { - const int nupcol = schedule()[reportStepIdx].nupcol(); - return iterationIdx < nupcol; - } else { - // We do not support any other rebalancing modes, - // i.e. TimeInterval based rebalancing is not available. - // This should be warned about elsewhere, so we choose to - // avoid spamming with a warning here. - return false; - } - } - - - - - template std::tuple BlackoilWellModel:: diff --git a/tests/test_ParallelSerialization.cpp b/tests/test_ParallelSerialization.cpp index 6eea1b753..d89bf97b1 100644 --- a/tests/test_ParallelSerialization.cpp +++ b/tests/test_ParallelSerialization.cpp @@ -72,6 +72,7 @@ #include #include #include +#include #include #include #include