23#ifndef OPM_BLACKOILWELLMODEL_GENERIC_HEADER_INCLUDED
24#define OPM_BLACKOILWELLMODEL_GENERIC_HEADER_INCLUDED
26#include <opm/output/data/GuideRateValue.hpp>
28#include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>
29#include <opm/input/eclipse/Schedule/Group/GuideRate.hpp>
31#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
33#include <opm/simulators/wells/PerforationData.hpp>
34#include <opm/simulators/wells/WellProdIndexCalculator.hpp>
35#include <opm/simulators/wells/WGState.hpp>
41#include <unordered_map>
42#include <unordered_set>
48 class GasLiftSingleWellGeneric;
49 class GasLiftWellState;
50 class GasLiftGroupInfo;
52 class GuideRateConfig;
53 class ParallelWellInfo;
58 class WellInterfaceGeneric;
62namespace Opm {
namespace data {
64 struct GroupGuideRates;
65 class GroupAndNetworkValues;
76 using GLiftOptWells = std::map<std::string, std::unique_ptr<GasLiftSingleWellGeneric>>;
77 using GLiftProdWells = std::map<std::string, const WellInterfaceGeneric*>;
78 using GLiftWellStateMap = std::map<std::string, std::unique_ptr<GasLiftWellState>>;
81 const SummaryState& summaryState,
82 const EclipseState& eclState,
84 const Parallel::Communication& comm);
88 int numLocalWells()
const;
89 int numPhases()
const;
93 bool hasWell(
const std::string& wname)
const;
96 bool anyMSWellOpenLocal()
const;
98 const Well& getWellEcl(
const std::string& well_name)
const;
99 std::vector<Well> getLocalWells(
const int timeStepIdx)
const;
100 const Schedule& schedule()
const {
return schedule_; }
101 const PhaseUsage& phaseUsage()
const {
return phase_usage_; }
102 const GroupState& groupState()
const {
return this->active_wgstate_.group_state; }
103 std::vector<const WellInterfaceGeneric*> genericWells()
const
104 {
return {well_container_generic_.begin(), well_container_generic_.end()}; }
111 return this->active_wgstate_.well_state;
119 return this->active_wgstate_.well_state;
122 GroupState& groupState() {
return this->active_wgstate_.group_state; }
124 WellTestState& wellTestState() {
return this->active_wgstate_.well_test_state; }
126 const WellTestState& wellTestState()
const {
return this->active_wgstate_.well_test_state; }
129 double wellPI(
const int well_index)
const;
130 double wellPI(
const std::string& well_name)
const;
132 void updateEclWells(
const int timeStepIdx,
133 const std::unordered_set<std::string>& wells,
134 const SummaryState& st);
136 void initFromRestartFile(
const RestartValue& restartValues,
137 WellTestState wtestState,
138 const size_t numCells,
139 bool handle_ms_well);
141 void prepareDeserialize(
int report_step,
142 const size_t numCells,
143 bool handle_ms_well);
153 this->last_valid_wgstate_ = this->active_wgstate_;
156 data::GroupAndNetworkValues groupAndNetworkData(
const int reportStepIdx)
const;
164 const double simulation_time);
166 const std::vector<PerforationData>& perfData(
const int well_idx)
const
167 {
return well_perf_data_[well_idx]; }
169 const Parallel::Communication& comm()
const {
return comm_; }
171 const SummaryState& summaryState()
const {
return summaryState_; }
173 const GuideRate& guideRate()
const {
return guideRate_; }
175 bool reportStepStarts()
const {
return report_step_starts_; }
177 bool shouldBalanceNetwork(
const int reportStepIndex,
178 const int iterationIdx)
const;
180 bool shouldIterateNetwork(
const int reportStepIndex,
181 const std::size_t recursion_level,
182 const double network_imbalance)
const;
184 template<
class Serializer>
185 void serializeOp(Serializer& serializer)
187 serializer(initial_step_);
188 serializer(report_step_starts_);
189 serializer(last_run_wellpi_);
190 serializer(local_shut_wells_);
191 serializer(closed_this_step_);
192 serializer(guideRate_);
193 serializer(node_pressures_);
194 serializer(active_wgstate_);
195 serializer(last_valid_wgstate_);
196 serializer(nupcol_wgstate_);
197 serializer(last_glift_opt_time_);
198 serializer(switched_prod_groups_);
199 serializer(switched_inj_groups_);
204 return this->initial_step_ == rhs.initial_step_ &&
205 this->report_step_starts_ == rhs.report_step_starts_ &&
206 this->last_run_wellpi_ == rhs.last_run_wellpi_ &&
207 this->local_shut_wells_ == rhs.local_shut_wells_ &&
208 this->closed_this_step_ == rhs.closed_this_step_ &&
209 this->node_pressures_ == rhs.node_pressures_ &&
210 this->active_wgstate_ == rhs.active_wgstate_ &&
211 this->last_valid_wgstate_ == rhs.last_valid_wgstate_ &&
212 this->nupcol_wgstate_ == rhs.nupcol_wgstate_ &&
213 this->last_glift_opt_time_ == rhs.last_glift_opt_time_ &&
214 this->switched_prod_groups_ == rhs.switched_prod_groups_ &&
215 this->switched_inj_groups_ == rhs.switched_inj_groups_;
250 return this->last_valid_wgstate_.well_state;
253 const WGState& prevWGState()
const
255 return this->last_valid_wgstate_;
263 return this->nupcol_wgstate_.well_state;
271 void commitWGState(
WGState wgstate)
273 this->last_valid_wgstate_ = std::move(wgstate);
283 this->active_wgstate_ = this->last_valid_wgstate_;
291 void updateNupcolWGState()
293 this->nupcol_wgstate_ = this->active_wgstate_;
300 void initializeWellProdIndCalculators();
301 void initializeWellPerfData();
303 bool wasDynamicallyShutThisTimeStep(
const int well_index)
const;
305 std::pair<bool, double> updateNetworkPressures(
const int reportStepIdx);
307 void updateWsolvent(
const Group& group,
308 const int reportStepIdx,
310 void setWsolvent(
const Group& group,
311 const int reportStepIdx,
313 virtual void calcRates(
const int fipnum,
315 const std::vector<double>& production_rates,
316 std::vector<double>& resv_coeff) = 0;
317 virtual void calcInjRates(
const int fipnum,
319 std::vector<double>& resv_coeff) = 0;
321 void assignShutConnections(data::Wells& wsrpt,
322 const int reportStepIndex)
const;
323 void assignGroupControl(
const Group& group,
324 data::GroupData& gdata)
const;
325 void assignGroupValues(
const int reportStepIdx,
326 std::map<std::string, data::GroupData>& gvalues)
const;
327 void assignNodeValues(std::map<std::string, data::NodeData>& nodevalues)
const;
329 void calculateEfficiencyFactors(
const int reportStepIdx);
331 void checkGconsaleLimits(
const Group& group,
333 const int reportStepIdx,
336 bool checkGroupHigherConstraints(
const Group& group,
338 const int reportStepIdx);
340 void updateAndCommunicateGroupData(
const int reportStepIdx,
341 const int iterationIdx);
343 void inferLocalShutWells();
345 void setRepRadiusPerfLength();
347 void gliftDebug(
const std::string& msg,
353 GLiftProdWells& prod_wells,
354 GLiftOptWells& glift_wells,
356 GLiftWellStateMap& map,
357 const int episodeIndex);
359 virtual void computePotentials(
const std::size_t widx,
361 std::string& exc_msg,
362 ExceptionType::ExcEnum& exc_type,
366 void updateWellPotentials(
const int reportStepIdx,
367 const bool onlyAfterEvent,
368 const SummaryConfig& summaryConfig,
372 virtual void createWellContainer(
const int time_step) = 0;
373 virtual void initWellContainer(
const int reportStepIdx) = 0;
375 virtual void calculateProductivityIndexValuesShutWells(
const int reportStepIdx,
377 virtual void calculateProductivityIndexValues(
DeferredLogger& deferred_logger) = 0;
379 void runWellPIScaling(
const int timeStepIdx,
385 std::vector<int> getCellsForConnections(
const Well& well)
const;
387 std::vector<std::string> getWellsForTesting(
const int timeStepIdx,
388 const double simulationTime);
391 const SummaryState& summaryState_;
392 const EclipseState& eclState_;
393 const Parallel::Communication& comm_;
396 bool terminal_output_{
false};
397 bool wells_active_{
false};
398 bool initial_step_{};
399 bool report_step_starts_{};
401 std::optional<int> last_run_wellpi_{};
403 std::vector<Well> wells_ecl_;
404 std::vector<std::vector<PerforationData>> well_perf_data_;
405 std::function<bool(
const Well&)> not_on_process_{};
408 std::vector<WellInterfaceGeneric*> well_container_generic_{};
410 std::vector<int> local_shut_wells_{};
412 std::vector<ParallelWellInfo> parallel_well_info_;
413 std::vector<std::reference_wrapper<ParallelWellInfo>> local_parallel_well_info_;
415 std::vector<WellProdIndexCalculator> prod_index_calc_;
417 std::vector<int> pvt_region_idx_;
419 mutable std::unordered_set<std::string> closed_this_step_;
421 GuideRate guideRate_;
422 std::unique_ptr<VFPProperties> vfp_properties_{};
423 std::map<std::string, double> node_pressures_;
431 WGState active_wgstate_;
432 WGState last_valid_wgstate_;
433 WGState nupcol_wgstate_;
435 bool glift_debug =
false;
437 double last_glift_opt_time_ = -1.0;
439 std::map<std::string, std::string> switched_prod_groups_;
440 std::map<std::pair<std::string, Opm::Phase>, std::string> switched_inj_groups_;
444 WellInterfaceGeneric* getGenWell(
const std::string& well_name);
Class for handling the blackoil well model.
Definition: BlackoilWellModelGeneric.hpp:73
virtual int compressedIndexForInterior(int cartesian_cell_idx) const =0
get compressed index for interior cells (-1, otherwise
std::vector< std::reference_wrapper< ParallelWellInfo > > createLocalParallelWellInfo(const std::vector< Well > &wells)
Create the parallel well information.
Definition: BlackoilWellModelGeneric.cpp:255
bool wellsActive() const
return true if wells are available in the reservoir
Definition: BlackoilWellModelGeneric.cpp:131
bool hasTHPConstraints() const
Return true if any well has a THP constraint.
Definition: BlackoilWellModelGeneric.cpp:903
bool forceShutWellByName(const std::string &wellname, const double simulation_time)
Shut down any single well Returns true if the well was actually found and shut.
Definition: BlackoilWellModelGeneric.cpp:910
Definition: DeferredLogger.hpp:57
Definition: GasLiftGroupInfo.hpp:50
Definition: GroupState.hpp:34
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: WellState.hpp:60
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
Definition: BlackoilPhases.hpp:46
Definition: WGState.hpp:37