diff --git a/src/opm/input/eclipse/Schedule/KeywordHandlers.cpp b/src/opm/input/eclipse/Schedule/KeywordHandlers.cpp index 88ccdff28..4bac591eb 100644 --- a/src/opm/input/eclipse/Schedule/KeywordHandlers.cpp +++ b/src/opm/input/eclipse/Schedule/KeywordHandlers.cpp @@ -1245,23 +1245,39 @@ File {} line {}.)", wname, location.keyword, location.filename, location.lineno) /* if all records are defaulted or just the status is set, only * well status is updated */ - if (conn_defaulted( record )) { - const auto well_status = Well::StatusFromString( status_str ); + if (conn_defaulted(record)) { + const auto new_well_status = Well::StatusFromString(status_str); + for (const auto& wname : well_names) { - { - const auto& well = this->getWell(wname, currentStep); - if( well_status == open && !well.canOpen() ) { - auto elapsed = this->snapshots[currentStep].start_time() - this->snapshots[0].start_time(); - auto days = std::chrono::duration_cast(elapsed).count() / 24; - std::string msg = "Well " + wname - + " where crossflow is banned has zero total rate." - + " This well is prevented from opening at " - + std::to_string( days ) + " days"; - OpmLog::note(msg); - } else { - this->updateWellStatus( wname, currentStep, well_status); - if (handlerContext.sim_update) - handlerContext.sim_update->affected_wells.insert(wname); + if ((new_well_status == open) && !this->getWell(wname, currentStep).canOpen()) { + auto elapsed = this->snapshots[currentStep].start_time() - this->snapshots[0].start_time(); + auto days = std::chrono::duration_cast(elapsed).count() / 24; + std::string msg = "Well " + wname + + " where crossflow is banned has zero total rate." + + " This well is prevented from opening at " + + std::to_string( days ) + " days"; + OpmLog::note(msg); + } + else { + const auto did_update_well_status = + this->updateWellStatus(wname, currentStep, new_well_status); + + if (handlerContext.sim_update) { + handlerContext.sim_update->affected_wells.insert(wname); + } + + if (did_update_well_status && (new_well_status == open)) { + // Record possible well injection/production status change + auto well2 = this->snapshots[currentStep].wells.get(wname); + + const auto did_flow_update = + (well2.isProducer() && well2.updateHasProduced()) + || + (well2.isInjector() && well2.updateHasInjected()); + + if (did_flow_update) { + this->snapshots[currentStep].wells.update(std::move(well2)); + } } } }