make group constrain check conditional

This commit is contained in:
Tor Harald Sandve
2020-01-16 09:52:03 +01:00
parent 91167ad405
commit f5c6bafd90
2 changed files with 110 additions and 95 deletions

View File

@@ -306,7 +306,7 @@ namespace Opm {
// xw to update Well State
void recoverWellSolutionAndUpdateWellState(const BVector& x);
void updateWellControls(Opm::DeferredLogger& deferred_logger, const bool checkGroupControl);
void updateWellControls(Opm::DeferredLogger& deferred_logger, const bool checkGroupControl, const bool checkCurrentGroupControl);
// setting the well_solutions_ based on well_state.
void updatePrimaryVariables(Opm::DeferredLogger& deferred_logger);
@@ -379,7 +379,7 @@ namespace Opm {
const Well& getWellEcl(const std::string& well_name) const;
void checkGroupConstraints(const Group& group, Opm::DeferredLogger& deferred_logger);
void checkGroupConstraints(const Group& group, const bool checkCurrentControl, Opm::DeferredLogger& deferred_logger);
void actionOnBrokenConstraints(const Group& group, const Group::ExceedAction& exceed_action, const Group::ProductionCMode& newControl, const int reportStepIdx, Opm::DeferredLogger& deferred_logger);

View File

@@ -834,7 +834,11 @@ namespace Opm {
calculateExplicitQuantities(local_deferredLogger);
prepareTimeStep(local_deferredLogger);
}
updateWellControls(local_deferredLogger, /*allow for switching to group controls*/true);
// also check the current group control the first two iterations. The first itertion is needed for changes in group/well controls and closing of wells etc.
// a second check is needed for REIN and VREP controls since they depend on results from other wells.
// This check can probably be made more sofisticated, but this simple rule seems to work
bool checkCurrentGroupControls = (iterationIdx < 2);
updateWellControls(local_deferredLogger, /*allow for switching to group controls*/true, checkCurrentGroupControls);
// Set the well primary variables based on the value of well solutions
initPrimaryVariablesEvaluation();
@@ -1052,7 +1056,7 @@ namespace Opm {
// are active wells anywhere in the global domain.
if( wellsActive() )
{
updateWellControls(deferred_logger, /*don't switch group controls*/false);
updateWellControls(deferred_logger, /*don't switch group controls*/false, /*don't check current group controls*/false);
initPrimaryVariablesEvaluation();
}
} catch (std::exception& e) {
@@ -1149,7 +1153,7 @@ namespace Opm {
template<typename TypeTag>
void
BlackoilWellModel<TypeTag>::
updateWellControls(Opm::DeferredLogger& deferred_logger, const bool checkGroupControl)
updateWellControls(Opm::DeferredLogger& deferred_logger, const bool checkGroupControl, const bool checkCurrentGroupControl)
{
// Even if there are no wells active locally, we cannot
// return as the DeferredLogger uses global communication.
@@ -1161,7 +1165,7 @@ namespace Opm {
// update group controls
if (checkGroupControl) {
checkGroupConstraints(fieldGroup, deferred_logger);
checkGroupConstraints(fieldGroup, checkCurrentGroupControl, deferred_logger);
}
for (const auto& well : well_container_) {
@@ -1676,7 +1680,7 @@ namespace Opm {
template<typename TypeTag>
void
BlackoilWellModel<TypeTag>::
checkGroupConstraints(const Group& group, Opm::DeferredLogger& deferred_logger) {
checkGroupConstraints(const Group& group, const bool checkCurrentControl, Opm::DeferredLogger& deferred_logger) {
const int reportStepIdx = ebosSimulator_.episodeIndex();
const auto& summaryState = ebosSimulator_.vanguard().summaryState();
@@ -1685,6 +1689,7 @@ namespace Opm {
if (group.isInjectionGroup())
{
const Group::InjectionCMode& currentControl = well_state.currentInjectionGroupControl(group.name());
const auto controls = group.injectionControls(summaryState);
int phasePos;
switch (controls.phase) {
@@ -1707,12 +1712,9 @@ namespace Opm {
throw("Expected WATER, OIL or GAS as type for group injector: " + group.name());
}
if (group.has_control(Group::InjectionCMode::NONE))
{
// do nothing??
}
if (group.has_control(Group::InjectionCMode::RATE))
{
if (checkCurrentControl || currentControl != Group::InjectionCMode::RATE)
{
double current_rate = 0.0;
current_rate += wellGroupHelpers::sumWellRates(group, schedule(), well_state, reportStepIdx, phasePos, /*isInjector*/true);
@@ -1724,7 +1726,10 @@ namespace Opm {
actionOnBrokenConstraints(group, Group::InjectionCMode::RATE, reportStepIdx, deferred_logger);
}
}
}
if (group.has_control(Group::InjectionCMode::RESV))
{
if (checkCurrentControl || currentControl != Group::InjectionCMode::RESV)
{
double current_rate = 0.0;
current_rate += wellGroupHelpers::sumWellResRates(group, schedule(), well_state, reportStepIdx, phasePos, /*isInjector*/true);
@@ -1733,8 +1738,11 @@ namespace Opm {
if (controls.resv_max_rate < current_rate) {
actionOnBrokenConstraints(group, Group::InjectionCMode::RESV, reportStepIdx, deferred_logger);
} }
}
}}
if (group.has_control(Group::InjectionCMode::REIN))
{
if (checkCurrentControl || currentControl != Group::InjectionCMode::REIN)
{
double production_Rate = 0.0;
const Group& groupRein = schedule().getGroup(controls.reinj_group, reportStepIdx);
@@ -1751,8 +1759,11 @@ namespace Opm {
if (controls.target_reinj_fraction*production_Rate < current_rate) {
actionOnBrokenConstraints(group, Group::InjectionCMode::REIN, reportStepIdx, deferred_logger);
} }
}
}}
if (group.has_control(Group::InjectionCMode::VREP))
{
if (checkCurrentControl || currentControl != Group::InjectionCMode::VREP)
{
double voidage_rate = 0.0;
const Group& groupVoidage = schedule().getGroup(controls.voidage_group, reportStepIdx);
@@ -1775,12 +1786,7 @@ namespace Opm {
actionOnBrokenConstraints(group, Group::InjectionCMode::VREP, reportStepIdx, deferred_logger);
}
}
if (group.has_control(Group::InjectionCMode::FLD))
{
// do nothing???
//OPM_THROW(std::runtime_error, "Group " + group.name() + "FLD control for injecting groups not implemented" );
}
// Handle GCONSALE
if (schedule().gConSale(reportStepIdx).has(group.name())) {
@@ -1820,12 +1826,11 @@ namespace Opm {
if (group.isProductionGroup()) {
const auto controls = group.productionControls(summaryState);
const Group::ProductionCMode& currentControl = well_state.currentProductionGroupControl(group.name());
if (group.has_control(Group::ProductionCMode::NONE))
{
}
if (group.has_control(Group::ProductionCMode::ORAT))
{
if (checkCurrentControl || currentControl != Group::ProductionCMode::ORAT)
{
double current_rate = 0.0;
current_rate += wellGroupHelpers::sumWellRates(group, schedule(), well_state, reportStepIdx, phase_usage_.phase_pos[BlackoilPhases::Liquid], false);
@@ -1837,8 +1842,11 @@ namespace Opm {
actionOnBrokenConstraints(group, controls.exceed_action, Group::ProductionCMode::ORAT, reportStepIdx, deferred_logger);
}
}
}
if (group.has_control(Group::ProductionCMode::WRAT))
{
if (checkCurrentControl || currentControl != Group::ProductionCMode::WRAT)
{
double current_rate = 0.0;
current_rate += wellGroupHelpers::sumWellRates(group, schedule(), well_state, reportStepIdx, phase_usage_.phase_pos[BlackoilPhases::Aqua], false);
@@ -1850,7 +1858,10 @@ namespace Opm {
actionOnBrokenConstraints(group, controls.exceed_action, Group::ProductionCMode::WRAT, reportStepIdx, deferred_logger);
}
}
}
if (group.has_control(Group::ProductionCMode::GRAT))
{
if (checkCurrentControl || currentControl != Group::ProductionCMode::GRAT)
{
double current_rate = 0.0;
current_rate += wellGroupHelpers::sumWellRates(group, schedule(), well_state, reportStepIdx, phase_usage_.phase_pos[BlackoilPhases::Vapour], false);
@@ -1861,7 +1872,10 @@ namespace Opm {
actionOnBrokenConstraints(group, controls.exceed_action, Group::ProductionCMode::GRAT, reportStepIdx, deferred_logger);
}
}
}
if (group.has_control(Group::ProductionCMode::LRAT))
{
if (checkCurrentControl || currentControl != Group::ProductionCMode::LRAT)
{
double current_rate = 0.0;
current_rate += wellGroupHelpers::sumWellRates(group, schedule(), well_state, reportStepIdx, phase_usage_.phase_pos[BlackoilPhases::Liquid], false);
@@ -1874,6 +1888,7 @@ namespace Opm {
actionOnBrokenConstraints(group, controls.exceed_action, Group::ProductionCMode::LRAT, reportStepIdx, deferred_logger);
}
}
}
if (group.has_control(Group::ProductionCMode::CRAT))
{
@@ -1881,6 +1896,8 @@ namespace Opm {
}
if (group.has_control(Group::ProductionCMode::RESV))
{
if (checkCurrentControl || currentControl != Group::ProductionCMode::RESV)
{
double current_rate = 0.0;
current_rate += wellGroupHelpers::sumWellResRates(group, schedule(), well_state, reportStepIdx, phase_usage_.phase_pos[BlackoilPhases::Aqua], true);
@@ -1893,16 +1910,14 @@ namespace Opm {
if (controls.resv_target < current_rate ) {
actionOnBrokenConstraints(group, controls.exceed_action, Group::ProductionCMode::RESV, reportStepIdx, deferred_logger);
}
}
}
if (group.has_control(Group::ProductionCMode::PRBL))
{
OPM_DEFLOG_THROW(std::runtime_error, "Group " + group.name() + "PRBL control for production groups not implemented", deferred_logger);
}
if (group.has_control(Group::ProductionCMode::FLD))
{
// do nothing???
}
} else {
//neither production or injecting group FIELD?
@@ -1910,7 +1925,7 @@ namespace Opm {
// call recursively down the group hiearchy
for (const std::string& groupName : group.groups()) {
checkGroupConstraints( schedule().getGroup(groupName, reportStepIdx), deferred_logger);
checkGroupConstraints( schedule().getGroup(groupName, reportStepIdx), checkCurrentControl, deferred_logger);
}