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;
51 class GuideRateConfig;
52 class ParallelWellInfo;
57 class WellInterfaceGeneric;
61 namespace Opm {
namespace data {
63 struct GroupGuideRates;
64 class GroupAndNetworkValues;
75 using GLiftOptWells = std::map<std::string, std::unique_ptr<GasLiftSingleWellGeneric>>;
76 using GLiftProdWells = std::map<std::string, const WellInterfaceGeneric*>;
77 using GLiftWellStateMap = std::map<std::string, std::unique_ptr<GasLiftWellState>>;
80 const SummaryState& summaryState,
81 const EclipseState& eclState,
83 const Parallel::Communication& comm);
87 int numLocalWells()
const;
88 int numPhases()
const;
92 bool hasWell(
const std::string& wname);
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; }
109 return this->active_wgstate_.well_state;
117 return this->active_wgstate_.well_state;
120 GroupState& groupState() {
return this->active_wgstate_.group_state; }
122 WellTestState& wellTestState() {
return this->active_wgstate_.well_test_state; }
124 const WellTestState& wellTestState()
const {
return this->active_wgstate_.well_test_state; }
127 double wellPI(
const int well_index)
const;
128 double wellPI(
const std::string& well_name)
const;
130 void updateEclWells(
const int timeStepIdx,
131 const std::unordered_set<std::string>& wells,
132 const SummaryState& st);
135 void loadRestartData(
const data::Wells& rst_wells,
136 const data::GroupAndNetworkValues& grpNwrkValues,
138 const bool handle_ms_well,
141 void initFromRestartFile(
const RestartValue& restartValues,
142 WellTestState wtestState,
143 const size_t numCells,
144 bool handle_ms_well);
146 void setWellsActive(
const bool wells_active);
156 this->last_valid_wgstate_ = this->active_wgstate_;
159 data::GroupAndNetworkValues groupAndNetworkData(
const int reportStepIdx)
const;
167 const double simulation_time);
201 return this->last_valid_wgstate_.well_state;
204 const WGState& prevWGState()
const
206 return this->last_valid_wgstate_;
214 return this->nupcol_wgstate_.well_state;
222 void commitWGState(
WGState wgstate)
224 this->last_valid_wgstate_ = std::move(wgstate);
234 this->active_wgstate_ = this->last_valid_wgstate_;
242 void updateNupcolWGState()
244 this->nupcol_wgstate_ = this->active_wgstate_;
251 void initializeWellProdIndCalculators();
252 void initializeWellPerfData();
254 bool wasDynamicallyShutThisTimeStep(
const int well_index)
const;
256 void updateNetworkPressures(
const int reportStepIdx);
258 void updateWsolvent(
const Group& group,
259 const int reportStepIdx,
261 void setWsolvent(
const Group& group,
262 const int reportStepIdx,
264 virtual void calcRates(
const int fipnum,
266 std::vector<double>& resv_coeff) = 0;
267 virtual void calcInjRates(
const int fipnum,
269 std::vector<double>& resv_coeff) = 0;
271 data::GuideRateValue getGuideRateValues(
const Group& group)
const;
272 data::GuideRateValue getGuideRateValues(
const Well& well)
const;
273 data::GuideRateValue getGuideRateInjectionGroupValues(
const Group& group)
const;
274 void getGuideRateValues(
const GuideRate::RateVector& qs,
276 const std::string& wgname,
277 data::GuideRateValue& grval)
const;
279 void assignWellGuideRates(data::Wells& wsrpt,
280 const int reportStepIdx)
const;
281 void assignShutConnections(data::Wells& wsrpt,
282 const int reportStepIndex)
const;
283 void assignGroupControl(
const Group& group,
284 data::GroupData& gdata)
const;
285 void assignGroupGuideRates(
const Group& group,
286 const std::unordered_map<std::string, data::GroupGuideRates>& groupGuideRates,
287 data::GroupData& gdata)
const;
288 void assignGroupValues(
const int reportStepIdx,
289 std::map<std::string, data::GroupData>& gvalues)
const;
290 void assignNodeValues(std::map<std::string, data::NodeData>& nodevalues)
const;
292 void loadRestartConnectionData(
const std::vector<data::Rates::opt>& phs,
293 const data::Well& rst_well,
294 const std::vector<PerforationData>& old_perf_data,
297 void loadRestartSegmentData(
const std::string& well_name,
298 const std::vector<data::Rates::opt>& phs,
299 const data::Well& rst_well,
302 void loadRestartWellData(
const std::string& well_name,
303 const bool handle_ms_well,
304 const std::vector<data::Rates::opt>& phs,
305 const data::Well& rst_well,
306 const std::vector<PerforationData>& old_perf_data,
309 void loadRestartGroupData(
const std::string& group,
310 const data::GroupData& value);
312 void loadRestartGuideRates(
const int report_step,
313 const GuideRateModel::Target target,
314 const data::Wells& rst_wells);
316 void loadRestartGuideRates(
const int report_step,
317 const GuideRateConfig& config,
318 const std::map<std::string, data::GroupData>& rst_groups);
320 std::unordered_map<std::string, data::GroupGuideRates>
321 calculateAllGroupGuiderates(
const int reportStepIdx)
const;
323 void calculateEfficiencyFactors(
const int reportStepIdx);
325 bool checkGroupConstraints(
const Group& group,
326 const int reportStepIdx,
329 std::pair<Group::InjectionCMode, double> checkGroupInjectionConstraints(
const Group& group,
330 const int reportStepIdx,
331 const Phase& phase)
const;
332 std::pair<Group::ProductionCMode, double> checkGroupProductionConstraints(
const Group& group,
333 const int reportStepIdx,
336 void checkGconsaleLimits(
const Group& group,
338 const int reportStepIdx,
341 bool checkGroupHigherConstraints(
const Group& group,
343 const int reportStepIdx,
344 std::set<std::string>& switched_groups);
346 bool updateGroupIndividualControl(
const Group& group,
348 const int reportStepIdx,
349 std::set<std::string>& switched_groups);
351 bool updateGroupIndividualControls(
DeferredLogger& deferred_logger,
352 std::set<std::string>& switched_groups,
353 const int reportStepIdx,
354 const int iterationIdx);
357 const int reportStepIdx,
358 std::set<std::string>& switched_groups);
360 void actionOnBrokenConstraints(
const Group& group,
361 const Group::ExceedAction& exceed_action,
362 const Group::ProductionCMode& newControl,
364 void actionOnBrokenConstraints(
const Group& group,
365 const Group::InjectionCMode& newControl,
366 const Phase& controlPhase,
369 void updateAndCommunicateGroupData(
const int reportStepIdx,
370 const int iterationIdx);
372 void inferLocalShutWells();
374 void setRepRadiusPerfLength();
376 void gliftDebug(
const std::string& msg,
382 GLiftProdWells& prod_wells,
383 GLiftOptWells& glift_wells,
384 GLiftWellStateMap& map,
385 const int episodeIndex);
387 virtual void computePotentials(
const std::size_t widx,
389 std::string& exc_msg,
390 ExceptionType::ExcEnum& exc_type,
394 void updateWellPotentials(
const int reportStepIdx,
395 const bool onlyAfterEvent,
396 const SummaryConfig& summaryConfig,
399 bool guideRateUpdateIsNeeded(
const int reportStepIdx)
const;
402 virtual void createWellContainer(
const int time_step) = 0;
403 virtual void initWellContainer() = 0;
405 virtual void calculateProductivityIndexValuesShutWells(
const int reportStepIdx,
407 virtual void calculateProductivityIndexValues(
DeferredLogger& deferred_logger) = 0;
409 void runWellPIScaling(
const int timeStepIdx,
417 const SummaryState& summaryState_;
418 const EclipseState& eclState_;
419 const Parallel::Communication& comm_;
422 bool terminal_output_{
false};
423 bool wells_active_{
false};
424 bool initial_step_{};
425 bool report_step_starts_{};
427 std::optional<int> last_run_wellpi_{};
429 std::vector<Well> wells_ecl_;
430 std::vector<std::vector<PerforationData>> well_perf_data_;
431 std::function<bool(
const Well&)> not_on_process_{};
434 std::vector<WellInterfaceGeneric*> well_container_generic_{};
436 std::vector<int> local_shut_wells_{};
438 std::vector<ParallelWellInfo> parallel_well_info_;
439 std::vector<std::reference_wrapper<ParallelWellInfo>> local_parallel_well_info_;
441 std::vector<WellProdIndexCalculator> prod_index_calc_;
443 std::vector<int> pvt_region_idx_;
445 mutable std::unordered_set<std::string> closed_this_step_;
447 GuideRate guideRate_;
448 std::unique_ptr<VFPProperties> vfp_properties_{};
449 std::map<std::string, double> node_pressures_;
457 WGState active_wgstate_;
458 WGState last_valid_wgstate_;
459 WGState nupcol_wgstate_;
461 bool glift_debug =
false;
463 double last_glift_opt_time_ = -1.0;
466 WellInterfaceGeneric* getGenWell(
const std::string& well_name);
Class for handling the blackoil well model.
Definition: BlackoilWellModelGeneric.hpp:72
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:691
bool wellsActive() const
return true if wells are available in the reservoir
Definition: BlackoilWellModelGeneric.cpp:384
bool hasTHPConstraints() const
Return true if any well has a THP constraint.
Definition: BlackoilWellModelGeneric.cpp:2050
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:2063
bool localWellsActive() const
return true if wells are available on this process
Definition: BlackoilWellModelGeneric.cpp:391
Definition: DeferredLogger.hpp:57
Definition: GroupState.hpp:34
Definition: SingleWellState.hpp:38
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: WellState.hpp:56
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
Definition: BlackoilPhases.hpp:46
Definition: WGState.hpp:35