BlackoilWellModel: move updateWellPotentials to generic class

This commit is contained in:
Arne Morten Kvarving 2021-06-07 13:04:29 +02:00
parent 004abd942b
commit 30a59cd190
4 changed files with 88 additions and 73 deletions

View File

@ -298,7 +298,6 @@ namespace Opm {
size_t local_num_cells_{};
double gravity_{};
std::vector<double> depth_{};
bool report_step_starts_{};
bool alternative_well_rate_init_{};
std::optional<int> last_run_wellpi_{};
@ -340,14 +339,11 @@ namespace Opm {
void updateAverageFormationFactor();
// Calculating well potentials for each well
void updateWellPotentials(const int reportStepIdx, const bool onlyAfterEvent, DeferredLogger& deferred_logger);
void computePotentials(const std::size_t widx,
const WellState& well_state_copy,
std::string& exc_msg,
ExceptionType::ExcEnum& exc_type,
DeferredLogger& deferred_logger);
DeferredLogger& deferred_logger) override;
const std::vector<double>& wellPerfEfficiencyFactors() const;

View File

@ -29,9 +29,9 @@
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Group/GuideRate.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <opm/simulators/utils/DeferredLogger.hpp>
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
#include <opm/simulators/wells/GasLiftStage2.hpp>
#include <opm/simulators/wells/VFPProperties.hpp>
#include <opm/simulators/wells/WellGroupHelpers.hpp>
@ -1702,4 +1702,66 @@ gasLiftOptimizationStage2(DeferredLogger& deferred_logger,
glift.runOptimize();
}
void
BlackoilWellModelGeneric::
updateWellPotentials(const int reportStepIdx,
const bool onlyAfterEvent,
const SummaryConfig& summaryConfig,
DeferredLogger& deferred_logger)
{
auto well_state_copy = this->wellState();
const bool write_restart_file = schedule().write_rst_file(reportStepIdx);
auto exc_type = ExceptionType::NONE;
std::string exc_msg;
size_t widx = 0;
for (const auto& well : well_container_generic_) {
const bool needed_for_summary =
((summaryConfig.hasSummaryKey( "WWPI:" + well->name()) ||
summaryConfig.hasSummaryKey( "WOPI:" + well->name()) ||
summaryConfig.hasSummaryKey( "WGPI:" + well->name())) && well->isInjector()) ||
((summaryConfig.hasKeyword( "GWPI") ||
summaryConfig.hasKeyword( "GOPI") ||
summaryConfig.hasKeyword( "GGPI")) && well->isInjector()) ||
((summaryConfig.hasKeyword( "FWPI") ||
summaryConfig.hasKeyword( "FOPI") ||
summaryConfig.hasKeyword( "FGPI")) && well->isInjector()) ||
((summaryConfig.hasSummaryKey( "WWPP:" + well->name()) ||
summaryConfig.hasSummaryKey( "WOPP:" + well->name()) ||
summaryConfig.hasSummaryKey( "WGPP:" + well->name())) && well->isProducer()) ||
((summaryConfig.hasKeyword( "GWPP") ||
summaryConfig.hasKeyword( "GOPP") ||
summaryConfig.hasKeyword( "GGPP")) && well->isProducer()) ||
((summaryConfig.hasKeyword( "FWPP") ||
summaryConfig.hasKeyword( "FOPP") ||
summaryConfig.hasKeyword( "FGPP")) && well->isProducer());
// At the moment, the following events are considered
// for potentials update
const uint64_t effective_events_mask = ScheduleEvents::WELL_STATUS_CHANGE
+ ScheduleEvents::COMPLETION_CHANGE
+ ScheduleEvents::WELL_PRODUCTIVITY_INDEX
+ ScheduleEvents::WELL_WELSPECS_UPDATE
+ ScheduleEvents::WELLGROUP_EFFICIENCY_UPDATE
+ ScheduleEvents::NEW_WELL
+ ScheduleEvents::PRODUCTION_UPDATE
+ ScheduleEvents::INJECTION_UPDATE;
const auto& events = schedule()[reportStepIdx].wellgroup_events();
const bool event = events.hasEvent(well->name(), ScheduleEvents::ACTIONX_WELL_EVENT) ||
(report_step_starts_ && events.hasEvent(well->name(), effective_events_mask));
const bool needPotentialsForGuideRates = well->underPredictionMode() && (!onlyAfterEvent || event);
const bool needPotentialsForOutput = !onlyAfterEvent && (needed_for_summary || write_restart_file);
const bool compute_potential = needPotentialsForOutput || needPotentialsForGuideRates;
if (compute_potential)
{
this->computePotentials(widx, well_state_copy, exc_msg, exc_type, deferred_logger);
}
++widx;
}
logAndCheckForExceptionsAndThrow(deferred_logger, exc_type,
"computeWellPotentials() failed: " + exc_msg,
terminal_output_);
}
}

View File

@ -36,6 +36,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Group/GuideRate.hpp>
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
#include <opm/simulators/wells/ParallelWellInfo.hpp>
#include <opm/simulators/wells/PerforationData.hpp>
#include <opm/simulators/wells/WellInterfaceGeneric.hpp>
@ -58,6 +59,7 @@ class GasLiftWellState;
class Group;
class RestartValue;
class Schedule;
class SummaryConfig;
class VFPProperties;
class WellState;
@ -339,6 +341,19 @@ protected:
GLiftWellStateMap& map,
const int episodeIndex);
virtual void computePotentials(const std::size_t widx,
const WellState& well_state_copy,
std::string& exc_msg,
ExceptionType::ExcEnum& exc_type,
DeferredLogger& deferred_logger) = 0;
// Calculating well potentials for each well
void updateWellPotentials(const int reportStepIdx,
const bool onlyAfterEvent,
const SummaryConfig& summaryConfig,
DeferredLogger& deferred_logger);
const Schedule& schedule_;
const SummaryState& summaryState_;
const EclipseState& eclState_;
@ -348,6 +363,7 @@ protected:
bool terminal_output_{false};
bool wells_active_{false};
bool initial_step_{};
bool report_step_starts_{};
std::vector<Well> wells_ecl_;
std::vector<std::vector<PerforationData>> well_perf_data_;

View File

@ -284,7 +284,10 @@ namespace Opm {
// calculate the well potentials
try {
updateWellPotentials(reportStepIdx, /*onlyAfterEvent*/true, local_deferredLogger);
updateWellPotentials(reportStepIdx,
/*onlyAfterEvent*/true,
ebosSimulator_.vanguard().summaryConfig(),
local_deferredLogger);
} catch ( std::runtime_error& e ) {
const std::string msg = "A zero well potential is returned for output purposes. ";
local_deferredLogger.warning("WELL_POTENTIAL_CALCULATION_FAILED", msg);
@ -448,7 +451,10 @@ namespace Opm {
// calculate the well potentials
try {
updateWellPotentials(reportStepIdx, /*onlyAfterEvent*/false, local_deferredLogger);
updateWellPotentials(reportStepIdx,
/*onlyAfterEvent*/false,
ebosSimulator_.vanguard().summaryConfig(),
local_deferredLogger);
} catch ( std::runtime_error& e ) {
const std::string msg = "A zero well potential is returned for output purposes. ";
local_deferredLogger.warning("WELL_POTENTIAL_CALCULATION_FAILED", msg);
@ -1182,71 +1188,6 @@ namespace Opm {
template<typename TypeTag>
void
BlackoilWellModel<TypeTag>::
updateWellPotentials(const int reportStepIdx, const bool onlyAfterEvent, DeferredLogger& deferred_logger)
{
auto well_state_copy = this->wellState();
const SummaryConfig& summaryConfig = ebosSimulator_.vanguard().summaryConfig();
const bool write_restart_file = ebosSimulator_.vanguard().schedule().write_rst_file(reportStepIdx);
auto exc_type = ExceptionType::NONE;
std::string exc_msg;
size_t widx = 0;
for (const auto& well : well_container_) {
const bool needed_for_summary =
((summaryConfig.hasSummaryKey( "WWPI:" + well->name()) ||
summaryConfig.hasSummaryKey( "WOPI:" + well->name()) ||
summaryConfig.hasSummaryKey( "WGPI:" + well->name())) && well->isInjector()) ||
((summaryConfig.hasKeyword( "GWPI") ||
summaryConfig.hasKeyword( "GOPI") ||
summaryConfig.hasKeyword( "GGPI")) && well->isInjector()) ||
((summaryConfig.hasKeyword( "FWPI") ||
summaryConfig.hasKeyword( "FOPI") ||
summaryConfig.hasKeyword( "FGPI")) && well->isInjector()) ||
((summaryConfig.hasSummaryKey( "WWPP:" + well->name()) ||
summaryConfig.hasSummaryKey( "WOPP:" + well->name()) ||
summaryConfig.hasSummaryKey( "WGPP:" + well->name())) && well->isProducer()) ||
((summaryConfig.hasKeyword( "GWPP") ||
summaryConfig.hasKeyword( "GOPP") ||
summaryConfig.hasKeyword( "GGPP")) && well->isProducer()) ||
((summaryConfig.hasKeyword( "FWPP") ||
summaryConfig.hasKeyword( "FOPP") ||
summaryConfig.hasKeyword( "FGPP")) && well->isProducer());
// At the moment, the following events are considered
// for potentials update
const uint64_t effective_events_mask = ScheduleEvents::WELL_STATUS_CHANGE
+ ScheduleEvents::COMPLETION_CHANGE
+ ScheduleEvents::WELL_PRODUCTIVITY_INDEX
+ ScheduleEvents::WELL_WELSPECS_UPDATE
+ ScheduleEvents::WELLGROUP_EFFICIENCY_UPDATE
+ ScheduleEvents::NEW_WELL
+ ScheduleEvents::PRODUCTION_UPDATE
+ ScheduleEvents::INJECTION_UPDATE;
const auto& events = schedule()[reportStepIdx].wellgroup_events();
const bool event = events.hasEvent(well->name(), ScheduleEvents::ACTIONX_WELL_EVENT) || (report_step_starts_ && events.hasEvent(well->name(), effective_events_mask));
const bool needPotentialsForGuideRates = well->underPredictionMode() && (!onlyAfterEvent || event);
const bool needPotentialsForOutput = !onlyAfterEvent && (needed_for_summary || write_restart_file);
const bool compute_potential = needPotentialsForOutput || needPotentialsForGuideRates;
if (compute_potential)
{
this->computePotentials(widx, well_state_copy, exc_msg, exc_type, deferred_logger);
}
++widx;
}
logAndCheckForExceptionsAndThrow(deferred_logger, exc_type,
"computeWellPotentials() failed: " + exc_msg,
terminal_output_);
}
template <typename TypeTag>
void
BlackoilWellModel<TypeTag>::