Skip to content

Commit

Permalink
WIP fix combination with local iter
Browse files Browse the repository at this point in the history
  • Loading branch information
Tor Harald Sandve committed Sep 16, 2024
1 parent cc144f7 commit 588f627
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion opm/simulators/wells/BlackoilWellModel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,7 @@ namespace Opm {

int iter = 0;
// iterate a few times to make sure all constrains are kept
while(!changed_well_group && iter < 1) {
while(!changed_well_group && iter < 10) {
// Check group individual constraints.
const int nupcol = this->schedule()[episodeIdx].nupcol();
// don't switch group control when iterationIdx > nupcol
Expand Down
54 changes: 33 additions & 21 deletions opm/simulators/wells/WellInterface_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,22 @@ namespace Opm
} else {
from = WellProducerCMode2String(ws.production_cmode);
}
bool oscillating = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) >= param_.max_number_of_well_switches_;

bool oscillating = false;
for (const auto& key : this->well_control_log_) {
if (std::count(this->well_control_log_.begin(), this->well_control_log_.end(), key) >=3) {
oscillating = true;
break;
}
}

if (oscillating) {
// only output frist time
bool output = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) == param_.max_number_of_well_switches_;
if (from == "THP" || from == "BHP")
return false;

bool swit = false;
if (output) {

if (true) {
std::string to;
if (std::count(this->well_control_log_.begin(), this->well_control_log_.end(), "BHP") > 0) {
if (well.isInjector())
Expand All @@ -227,9 +236,6 @@ namespace Opm
ws.production_cmode = Well::ProducerCMode::BHP;

to = "BHP";
this->well_control_log_.push_back(to);
this->well_control_log_.push_back(to);
this->well_control_log_.push_back(to);
updateWellStateWithTarget(simulator, group_state, well_state, deferred_logger);
updatePrimaryVariables(simulator, well_state, deferred_logger);
swit = true;
Expand All @@ -241,10 +247,7 @@ namespace Opm
ws.production_cmode = Well::ProducerCMode::THP;

to = "THP";
this->well_control_log_.push_back(to);
this->well_control_log_.push_back(to);
this->well_control_log_.push_back(to);
updateWellStateWithTarget(simulator, group_state, well_state, deferred_logger);
ws.thp = this->getTHPConstraint(summaryState);
updatePrimaryVariables(simulator, well_state, deferred_logger);
swit = true;
} else {
Expand All @@ -260,15 +263,15 @@ namespace Opm
to = from;
}
}
std::ostringstream ss;
ss << " The control mode for well " << this->name()
<< " is oscillating.\n"
<< " We keep it at its individual control after "
<< param_.max_number_of_well_switches_
<< " switches. The control is kept at " << to;
deferred_logger.info(ss.str());
this->well_control_log_.push_back(from);
if(swit) {
if (swit) {
this->well_control_log_.push_back(from);
std::ostringstream ss;
ss << " The control mode for well " << this->name()
<< " is oscillating.\n"
<< " The individual control is fixed after "
<< param_.max_number_of_well_switches_
<< " switches. The control is kept at " << to;
deferred_logger.info(ss.str());
updateWellStateWithTarget(simulator, group_state, well_state, deferred_logger);
updatePrimaryVariables(simulator, well_state, deferred_logger);
}
Expand Down Expand Up @@ -334,7 +337,15 @@ namespace Opm
} else {
from = WellProducerCMode2String(ws.production_cmode);
}
const bool oscillating = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) >= param_.max_number_of_well_switches_;
bool oscillating = false;
for (const auto& key : this->well_control_log_) {
if (std::count(this->well_control_log_.begin(), this->well_control_log_.end(), key) >= param_.max_number_of_well_switches_) {
oscillating = true;
break;
}
}

//const bool oscillating = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) >= param_.max_number_of_well_switches_;

if (oscillating || this->wellUnderZeroRateTarget(simulator, well_state, deferred_logger) || !(this->well_ecl_.getStatus() == WellStatus::OPEN)) {
return false;
Expand All @@ -357,6 +368,7 @@ namespace Opm
}

if (changed) {
this->well_control_log_.push_back(from);
const bool thp_controlled = this->isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP :
ws.production_cmode == Well::ProducerCMode::THP;
if (!thp_controlled){
Expand Down

0 comments on commit 588f627

Please sign in to comment.