From a7c6203a73f90eb2b8774a60dc0d4b461c8fff58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Thu, 7 Oct 2021 13:41:36 +0200 Subject: [PATCH] Initialise Guide Rate Object From Restart File This commit adds an overload set named loadRestartGuideRates which, collectively, initialises the contained GuideRate object using guide rate values from the restart file. This is necessary, but not quite sufficient, to restart models in prediction mode with group-level constraints. --- .../wells/BlackoilWellModelGeneric.cpp | 90 +++++++++++++++++++ .../wells/BlackoilWellModelGeneric.hpp | 8 ++ 2 files changed, 98 insertions(+) diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index 319e3040e..8a65872a7 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -24,10 +24,13 @@ #include +#include #include +#include #include #include +#include #include #include #include @@ -42,10 +45,43 @@ #include #include #include +#include #include #include +namespace { + Opm::data::GuideRateValue::Item + guideRateRestartItem(const Opm::GuideRateModel::Target target) + { + using Item = Opm::data::GuideRateValue::Item; + using Target = Opm::GuideRateModel::Target; + + static const auto items = std::unordered_map { + { Target::OIL, Item::Oil }, + { Target::GAS, Item::Gas }, + { Target::WAT, Item::Water }, + { Target::RES, Item::ResV }, + }; + + auto i = items.find(target); + return (i == items.end()) ? Item::NumItems : i->second; + } + + Opm::GuideRate::GuideRateValue + makeGuideRateValue(const Opm::data::GuideRateValue& restart, + const Opm::GuideRateModel::Target target) + { + const auto item = guideRateRestartItem(target); + + if (! restart.has(item)) { + return {}; + } + + return { 0.0, restart.get(item), target }; + } +} // Anonymous + namespace Opm { BlackoilWellModelGeneric:: @@ -266,6 +302,45 @@ loadRestartGroupData(const std::string& group, } } +void +BlackoilWellModelGeneric:: +loadRestartGuideRates(const int report_step, + const GuideRateModel::Target target, + const data::Wells& rst_wells) +{ + for (const auto& [well_name, rst_well] : rst_wells) { + if (! this->hasWell(well_name) || this->getWellEcl(well_name).isInjector()) { + continue; + } + + this->guideRate_.init_grvalue_SI(report_step, well_name, + makeGuideRateValue(rst_well.guide_rates, target)); + } +} + +void +BlackoilWellModelGeneric:: +loadRestartGuideRates(const int report_step, + const GuideRateConfig& config, + const std::map& rst_groups) +{ + const auto target = config.model().target(); + + for (const auto& [group_name, rst_group] : rst_groups) { + if (! config.has_production_group(group_name)) { + continue; + } + + const auto& group = config.production_group(group_name); + if ((group.guide_rate > 0.0) || (group.target != Group::GuideRateProdTarget::FORM)) { + continue; + } + + this->guideRate_.init_grvalue_SI(report_step, group_name, + makeGuideRateValue(rst_group.guideRates.production, target)); + } +} + void BlackoilWellModelGeneric:: loadRestartData(const data::Wells& rst_wells, @@ -319,6 +394,9 @@ initFromRestartFile(const RestartValue& restartValues, // will not be present in a restart file. Use the previous time step to retrieve // wells that have information written to the restart file. const int report_step = std::max(eclState_.getInitConfig().getRestartStep() - 1, 0); + + const auto& config = this->schedule()[report_step].guide_rate(); + // wells_ecl_ should only contain wells on this processor. wells_ecl_ = getLocalWells(report_step); this->local_parallel_well_info_ = createLocalParallelWellInfo(wells_ecl_); @@ -335,6 +413,18 @@ initFromRestartFile(const RestartValue& restartValues, loadRestartData(restartValues.wells, restartValues.grp_nwrk, this->phase_usage_, handle_ms_well, this->wellState()); + + if (config.has_model()) { + this->loadRestartGuideRates(report_step, + config.model().target(), + restartValues.wells); + } + } + + if (config.has_model()) { + this->loadRestartGuideRates(report_step, config, restartValues.grp_nwrk.groupData); + + this->guideRate_.updateGuideRateExpiration(this->schedule().seconds(report_step), report_step); } diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index 30c9a0278..9ca59b69c 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -307,6 +307,14 @@ protected: void loadRestartGroupData(const std::string& group, const data::GroupData& value); + void loadRestartGuideRates(const int report_step, + const GuideRateModel::Target target, + const data::Wells& rst_wells); + + void loadRestartGuideRates(const int report_step, + const GuideRateConfig& config, + const std::map& rst_groups); + std::unordered_map calculateAllGroupGuiderates(const int reportStepIdx) const;