WellInterfaceGeneric.hpp
Go to the documentation of this file.
1/*
2 Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3 Copyright 2017 Statoil ASA.
4 Copyright 2017 IRIS
5 Copyright 2019 Norce
6
7 This file is part of the Open Porous Media project (OPM).
8
9 OPM is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OPM is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OPM. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23
24#ifndef OPM_WELLINTERFACE_GENERIC_HEADER_INCLUDED
25#define OPM_WELLINTERFACE_GENERIC_HEADER_INCLUDED
26
27#include <opm/input/eclipse/Schedule/Well/Well.hpp>
30
31#include <ctime>
32#include <map>
33#include <optional>
34#include <string>
35#include <vector>
36
37namespace Opm
38{
39
40class DeferredLogger;
41class GuideRate;
42class UnitSystem;
43template<class Scalar> class ParallelWellInfo;
44template<class Scalar> struct PerforationData;
45class SummaryState;
46template<typename Scalar, typename IndexTraits> class VFPProperties;
47class WellTestState;
48template<typename Scalar, typename IndexTraits> class WellState;
49template<typename Scalar, typename IndexTraits> class SingleWellState;
50class Group;
51class Schedule;
52template<typename IndexTraits> class PhaseUsageInfo;
53
54template<typename Scalar, typename IndexTraits>
56public:
58
60
61 WellInterfaceGeneric(const Well& well,
62 const ParallelWellInfo<Scalar>& parallel_well_info,
63 const int time_step,
64 const ModelParameters& param,
65 const int pvtRegionIdx,
66 const int num_conservation_quantities,
67 const int num_phases,
68 const int index_of_well,
69 const PhaseUsageInfo<IndexTraits>& phase_usage,
70 const std::vector<PerforationData<Scalar>>& perf_data);
71
72 virtual ~WellInterfaceGeneric() = default;
73
75 const std::vector<PerforationData<Scalar>>& perforationData() const;
76
78 const std::string& name() const;
79
81 bool isInjector() const;
82
84 bool isProducer() const;
85
87 const std::vector<int>& cells() const { return well_cells_; }
88
90 int indexOfWell() const;
91
92 void adaptRatesForVFP(std::vector<Scalar>& rates) const;
93
94 const Well& wellEcl() const;
95 Well& wellEcl();
97
99 bool underPredictionMode() const;
100
101 // whether the well is operable
103 bool useVfpExplicit () const;
105
107 void closeCompletions(const WellTestState& wellTestState);
108
111 const WellStateType& prev_well_state) const;
112 void setGuideRate(const GuideRate* guide_rate_arg);
113 void setWellEfficiencyFactor(const Scalar efficiency_factor);
115 void setWsolvent(const Scalar wsolvent);
116 void setDynamicThpLimit(const Scalar thp_limit);
117 std::optional<Scalar> getDynamicThpLimit() const;
118 void setDynamicThpLimit(const std::optional<Scalar> thp_limit);
119 void updatePerforatedCell(std::vector<bool>& is_cell_perforated);
120
122 bool wellHasTHPConstraints(const SummaryState& summaryState) const;
123
124 void stopWell() { this->wellStatus_ = Well::Status::STOP; }
125 void openWell() { this->wellStatus_ = Well::Status::OPEN; }
126 Well::Status wellStatus() { return this->wellStatus_;}
127
128 bool wellIsStopped() const { return this->wellStatus_ == Well::Status::STOP; }
129
130 int currentStep() const { return this->current_step_; }
131
132 int pvtRegionIdx() const { return pvtRegionIdx_; }
133
134 const GuideRate* guideRate() const { return guide_rate_; }
135
137
138 int numPhases() const { return number_of_phases_; }
139
141
142 Scalar refDepth() const { return ref_depth_; }
143
144 Scalar gravity() const { return gravity_; }
145
147
149
150 const std::vector<Scalar>& perfDepth() const { return perf_depth_; }
151
152 std::vector<Scalar>& perfDepth() { return perf_depth_; }
153
154 const std::vector<Scalar>& wellIndex() const { return well_index_; }
155
160 std::vector<Scalar>& wellIndex() { return well_index_; }
161
162 const std::map<int,std::vector<int>>& getCompletions() const { return completions_; }
163
164 Scalar getTHPConstraint(const SummaryState& summaryState) const;
165 Scalar getALQ(const WellStateType& well_state) const;
166 Scalar wsolvent() const;
167 Scalar rsRvInj() const;
168
169 // at the beginning of the time step, we check what inj_multiplier from the previous running
170 void initInjMult(const std::vector<Scalar>& max_inj_mult);
171
172 // update the InjMult information at the end of the time step, so it can be used for later.
173 void updateInjMult(std::vector<Scalar>& inj_multipliers,
174 DeferredLogger& deferred_logger) const;
175
176 // Note:: for multisegment wells, bhp is actually segment pressure in practice based on observation
177 // it might change in the future
178 Scalar getInjMult(const int local_perf_index, const Scalar bhp, const Scalar perf_pres, DeferredLogger& dlogger) const;
179
180 // whether a well is specified with a non-zero and valid VFP table number
181 bool isVFPActive(DeferredLogger& deferred_logger) const;
182
184 DeferredLogger& deferred_logger) const;
185
187
201 const double& simulationTime,
202 const bool& writeMessageToOPMLog,
203 const bool during_well_test,
204 const bool zero_group_target,
205 WellTestState& wellTestState,
206 const UnitSystem& unit_system,
207 const std::time_t start_time,
208 DeferredLogger& deferred_logger) const;
209
210 bool isPressureControlled(const WellStateType& well_state) const;
211
213
215 void updateFilterCakeMultipliers(const std::vector<Scalar>& inj_fc_multiplier)
216 {
217 inj_fc_multiplier_ = inj_fc_multiplier;
218 }
219
221
222 virtual std::vector<Scalar> getPrimaryVars() const
223 {
224 return {};
225 }
226
227 virtual int setPrimaryVars(typename std::vector<Scalar>::const_iterator)
228 {
229 return 0;
230 }
231
232 virtual Scalar connectionDensity(const int globalConnIdx,
233 const int openConnIdx) const = 0;
234
235 void addPerforations(const std::vector<RuntimePerforation>& perfs);
236
237protected:
238 bool getAllowCrossFlow() const;
239
240 Scalar wmicrobes_() const;
241 Scalar wfoam_() const;
242 Scalar woxygen_() const;
243 Scalar wpolymer_() const;
244 Scalar wsalt_() const;
245 Scalar wurea_() const;
246
247 int polymerTable_() const;
248 int polymerInjTable_() const;
250
251 bool wellUnderZeroRateTargetIndividual(const SummaryState& summary_state,
252 const WellState<Scalar, IndexTraits>& well_state) const;
253
255
256 std::pair<bool,bool>
257 computeWellPotentials(std::vector<Scalar>& well_potentials,
258 const WellStateType& well_state);
259
260 void checkNegativeWellPotentials(std::vector<Scalar>& well_potentials,
261 const bool checkOperability,
262 DeferredLogger& deferred_logger);
263
264 // Remove all other controls than THP and BHP
265 void onlyKeepBHPandTHPcontrols(const SummaryState& summary_state,
266 WellStateType& well_state,
267 Well::InjectionControls& inj_controls,
268 Well::ProductionControls& prod_controls) const;
269
271 {
272 std::ranges::fill(this->inj_multiplier_damp_factor_, 1.0);
273 }
274
276 const std::vector<Scalar>& scaled_well_fractions,
277 DeferredLogger& deferred_logger) const;
278
279 // definition of the struct OperabilityStatus
281 {
283 {
285 return false;
286 }
287
289 }
290
292 {
294 }
295
297 {
299 }
300
302 {
307 }
308
309 // whether the well can be operated under bhp limit
310 // without considering other limits.
311 // if it is false, then the well is not operable for sure.
313 // if the well can be operated under bhp limit, will it obey(not violate)
314 // the thp limit when operated under bhp limit
316 // whether the well operate under the thp limit only
318 // whether the well obey bhp limit when operated under thp limit
320 // the well is solveable
321 bool solvable = true;
322 // the well have non positive potentials
324 //thp limit violated but not switched
326
327 bool use_vfpexplicit = false;
328 };
329
331
333
335 const int current_step_;
337
338 // The pvt region of the well. We assume
339 // We assume a well to not penetrate more than one pvt region.
340 const int pvtRegionIdx_;
341
342 // TODO: with energy conservation joins, we probably should change this to be num_mass_conservation_quantities_
343 // or something like that. Energy term calculate somehow differently from the mass term
345
346 // number of phases
348
349 // the index of well in Wells struct
351
353
354 const std::vector<PerforationData<Scalar>>* perf_data_;
355
356 // the vectors used to describe the inflow performance relationship (IPR)
357 // Q = IPR_A - BHP * IPR_B
358 // TODO: it minght need to go to WellInterface, let us implement it in StandardWell first
359 // it is only updated and used for producers for now
360 mutable std::vector<Scalar> ipr_a_;
361 mutable std::vector<Scalar> ipr_b_;
362
363 // cell index for each well perforation
364 std::vector<int> well_cells_;
365
366 // well index for each perforation
367 std::vector<Scalar> well_index_;
368
369 // number of the perforations for this well on this process
371
372 // depth for each perforation
373 std::vector<Scalar> perf_depth_;
374
375 // representative radius of the perforations, used in shear calculation
376 std::vector<Scalar> perf_rep_radius_;
377
378 // length of the perforations, use in shear calculation
379 std::vector<Scalar> perf_length_;
380
381 // well bore diameter
382 std::vector<Scalar> bore_diameters_;
383
384 /*
385 * completions_ contains the mapping from completion id to connection indices
386 * {
387 * 2 : [ConnectionIndex, ConnectionIndex],
388 * 1 : [ConnectionIndex, ConnectionIndex, ConnectionIndex],
389 * 5 : [ConnectionIndex],
390 * 7 : [ConnectionIndex]
391 * ...
392 * }
393 * The integer IDs correspond to the COMPLETION id given by the COMPLUMP keyword.
394 * When there is no COMPLUMP keyword used, a default completion number will be assigned
395 * based on the order of the declaration of the connections.
396 * Since the connections not OPEN is not included in the Wells, so they will not be considered
397 * in this mapping relation.
398 */
399 std::map<int, std::vector<int>> completions_;
400
401 // reference depth for the BHP
403
404 // saturation table nubmer for each well perforation
405 std::vector<int> saturation_table_number_;
406
407 Well::Status wellStatus_;
408
409 Scalar gravity_;
410 Scalar wsolvent_;
411 std::optional<Scalar> dynamic_thp_limit_;
412
413 // recording the multiplier calculate from the keyword WINJMULT during the time step
414 mutable std::vector<Scalar> inj_multiplier_;
415
416 // the injection multiplier from the previous running, it is mostly used for CIRR mode
417 // which intends to keep the fracturing open
418 std::vector<Scalar> prev_inj_multiplier_;
419
420 // WINJMULT multipliers for previous iteration (used for oscillation detection)
421 mutable std::vector<Scalar> inj_multiplier_previter_;
422 // WINJMULT dampening factors (used in case of oscillations)
423 mutable std::vector<Scalar> inj_multiplier_damp_factor_;
424
425 // the multiplier due to injection filtration cake
426 std::vector<Scalar> inj_fc_multiplier_;
427
430 const GuideRate* guide_rate_;
431
432 std::vector<std::string> well_control_log_;
433
435};
436
437}
438
439#endif // OPM_WELLINTERFACE_GENERIC_HEADER_INCLUDED
Definition: DeferredLogger.hpp:57
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
Definition: GasLiftGroupInfo.hpp:38
Definition: SingleWellState.hpp:44
Definition: VFPProperties.hpp:40
Definition: WellInterfaceGeneric.hpp:55
int pvtRegionIdx() const
Definition: WellInterfaceGeneric.hpp:132
WellInterfaceGeneric(const Well &well, const ParallelWellInfo< Scalar > &parallel_well_info, const int time_step, const ModelParameters &param, const int pvtRegionIdx, const int num_conservation_quantities, const int num_phases, const int index_of_well, const PhaseUsageInfo< IndexTraits > &phase_usage, const std::vector< PerforationData< Scalar > > &perf_data)
void updateGroupTargetFallbackFlag(WellState< Scalar, IndexTraits > &well_state, const std::vector< Scalar > &scaled_well_fractions, DeferredLogger &deferred_logger) const
const std::map< int, std::vector< int > > & getCompletions() const
Definition: WellInterfaceGeneric.hpp:162
const int num_conservation_quantities_
Definition: WellInterfaceGeneric.hpp:344
bool isVFPActive(DeferredLogger &deferred_logger) const
void openWell()
Definition: WellInterfaceGeneric.hpp:125
std::vector< int > saturation_table_number_
Definition: WellInterfaceGeneric.hpp:405
bool isOperableAndSolvable() const
std::vector< int > well_cells_
Definition: WellInterfaceGeneric.hpp:364
void updatePerforatedCell(std::vector< bool > &is_cell_perforated)
int index_of_well_
Definition: WellInterfaceGeneric.hpp:350
std::optional< Scalar > dynamic_thp_limit_
Definition: WellInterfaceGeneric.hpp:411
std::vector< Scalar > perf_depth_
Definition: WellInterfaceGeneric.hpp:373
int numPhases() const
Definition: WellInterfaceGeneric.hpp:138
Scalar gravity() const
Definition: WellInterfaceGeneric.hpp:144
const GuideRate * guideRate() const
Definition: WellInterfaceGeneric.hpp:134
std::vector< Scalar > prev_inj_multiplier_
Definition: WellInterfaceGeneric.hpp:418
Well::Status wellStatus()
Definition: WellInterfaceGeneric.hpp:126
int polymerWaterTable_() const
int number_of_phases_
Definition: WellInterfaceGeneric.hpp:347
void setWsolvent(const Scalar wsolvent)
std::vector< Scalar > & perfDepth()
Definition: WellInterfaceGeneric.hpp:152
const PhaseUsageInfo< IndexTraits > & phase_usage_
Definition: WellInterfaceGeneric.hpp:352
Scalar wpolymer_() const
const int current_step_
Definition: WellInterfaceGeneric.hpp:335
std::vector< Scalar > ipr_a_
Definition: WellInterfaceGeneric.hpp:360
Well well_ecl_
Definition: WellInterfaceGeneric.hpp:332
const std::vector< Scalar > & perfDepth() const
Definition: WellInterfaceGeneric.hpp:150
bool wellUnderGroupControl(const SingleWellState< Scalar, IndexTraits > &ws) const
void updateWellTestState(const SingleWellState< Scalar, IndexTraits > &ws, const double &simulationTime, const bool &writeMessageToOPMLog, const bool during_well_test, const bool zero_group_target, WellTestState &wellTestState, const UnitSystem &unit_system, const std::time_t start_time, DeferredLogger &deferred_logger) const
const Well & wellEcl() const
const ParallelWellInfo< Scalar > & parallel_well_info_
Definition: WellInterfaceGeneric.hpp:334
Scalar wmicrobes_() const
const PhaseUsageInfo< IndexTraits > & phaseUsage() const
std::vector< Scalar > ipr_b_
Definition: WellInterfaceGeneric.hpp:361
const int pvtRegionIdx_
Definition: WellInterfaceGeneric.hpp:340
std::vector< Scalar > inj_multiplier_damp_factor_
Definition: WellInterfaceGeneric.hpp:423
bool underPredictionMode() const
Returns true if the well is currently in prediction mode (i.e. not history mode).
const GuideRate * guide_rate_
Definition: WellInterfaceGeneric.hpp:430
OperabilityStatus operability_status_
Definition: WellInterfaceGeneric.hpp:330
bool wellUnderZeroRateTargetIndividual(const SummaryState &summary_state, const WellState< Scalar, IndexTraits > &well_state) const
Well::Status wellStatus_
Definition: WellInterfaceGeneric.hpp:407
int numLocalPerfs() const
Definition: WellInterfaceGeneric.hpp:140
Scalar getTHPConstraint(const SummaryState &summaryState) const
bool isPressureControlled(const WellStateType &well_state) const
void setDynamicThpLimit(const Scalar thp_limit)
void updateInjMult(std::vector< Scalar > &inj_multipliers, DeferredLogger &deferred_logger) const
void updateFilterCakeMultipliers(const std::vector< Scalar > &inj_fc_multiplier)
Update filter cake multipliers.
Definition: WellInterfaceGeneric.hpp:215
Scalar well_efficiency_factor_
Definition: WellInterfaceGeneric.hpp:428
void closeCompletions(const WellTestState &wellTestState)
bool isProducer() const
True if the well is a producer.
void checkNegativeWellPotentials(std::vector< Scalar > &well_potentials, const bool checkOperability, DeferredLogger &deferred_logger)
void setPrevSurfaceRates(WellStateType &well_state, const WellStateType &prev_well_state) const
void addPerforations(const std::vector< RuntimePerforation > &perfs)
std::vector< Scalar > inj_multiplier_previter_
Definition: WellInterfaceGeneric.hpp:421
std::vector< Scalar > inj_fc_multiplier_
Definition: WellInterfaceGeneric.hpp:426
virtual Scalar connectionDensity(const int globalConnIdx, const int openConnIdx) const =0
Scalar getInjMult(const int local_perf_index, const Scalar bhp, const Scalar perf_pres, DeferredLogger &dlogger) const
void adaptRatesForVFP(std::vector< Scalar > &rates) const
void onlyKeepBHPandTHPcontrols(const SummaryState &summary_state, WellStateType &well_state, Well::InjectionControls &inj_controls, Well::ProductionControls &prod_controls) const
bool changedToOpenThisStep() const
Definition: WellInterfaceGeneric.hpp:186
void setGuideRate(const GuideRate *guide_rate_arg)
const std::vector< PerforationData< Scalar > > * perf_data_
Definition: WellInterfaceGeneric.hpp:354
bool isInjector() const
True if the well is an injector.
int numConservationQuantities() const
Definition: WellInterfaceGeneric.hpp:136
const VFPProperties< Scalar, IndexTraits > * vfpProperties() const
Definition: WellInterfaceGeneric.hpp:146
Scalar refDepth() const
Definition: WellInterfaceGeneric.hpp:142
std::vector< Scalar > & wellIndex()
Mutable per-perforation well indices (connection transmissibility factors). Adjoint hook: the dJ/dper...
Definition: WellInterfaceGeneric.hpp:160
Scalar getALQ(const WellStateType &well_state) const
void stopWell()
Definition: WellInterfaceGeneric.hpp:124
Scalar wellEfficiencyFactor() const
Definition: WellInterfaceGeneric.hpp:212
std::vector< std::string > well_control_log_
Definition: WellInterfaceGeneric.hpp:432
void resetDampening()
Definition: WellInterfaceGeneric.hpp:270
int indexOfWell() const
Index of well in the wells struct and wellState.
virtual std::vector< Scalar > getPrimaryVars() const
Definition: WellInterfaceGeneric.hpp:222
const std::vector< PerforationData< Scalar > > & perforationData() const
Get the perforations of the well.
std::vector< Scalar > perf_length_
Definition: WellInterfaceGeneric.hpp:379
const std::vector< int > & cells() const
Well cells.
Definition: WellInterfaceGeneric.hpp:87
int number_of_local_perforations_
Definition: WellInterfaceGeneric.hpp:370
std::vector< Scalar > well_index_
Definition: WellInterfaceGeneric.hpp:367
virtual int setPrimaryVars(typename std::vector< Scalar >::const_iterator)
Definition: WellInterfaceGeneric.hpp:227
void setVFPProperties(const VFPProperties< Scalar, IndexTraits > *vfp_properties_arg)
const std::string & name() const
Well name.
const ModelParameters & param_
Definition: WellInterfaceGeneric.hpp:336
std::pair< bool, bool > computeWellPotentials(std::vector< Scalar > &well_potentials, const WellStateType &well_state)
bool changed_to_open_this_step_
Definition: WellInterfaceGeneric.hpp:434
void setWellEfficiencyFactor(const Scalar efficiency_factor)
const VFPProperties< Scalar, IndexTraits > * vfp_properties_
Definition: WellInterfaceGeneric.hpp:429
virtual ~WellInterfaceGeneric()=default
void initInjMult(const std::vector< Scalar > &max_inj_mult)
Scalar wsolvent_
Definition: WellInterfaceGeneric.hpp:410
std::map< int, std::vector< int > > completions_
Definition: WellInterfaceGeneric.hpp:399
void setDynamicThpLimit(const std::optional< Scalar > thp_limit)
std::vector< Scalar > perf_rep_radius_
Definition: WellInterfaceGeneric.hpp:376
void reportWellSwitching(const SingleWellState< Scalar, IndexTraits > &ws, DeferredLogger &deferred_logger) const
std::optional< Scalar > getDynamicThpLimit() const
const std::vector< Scalar > & wellIndex() const
Definition: WellInterfaceGeneric.hpp:154
Scalar gravity_
Definition: WellInterfaceGeneric.hpp:409
bool wellHasTHPConstraints(const SummaryState &summaryState) const
Returns true if the well has one or more THP limits/constraints.
std::vector< Scalar > bore_diameters_
Definition: WellInterfaceGeneric.hpp:382
bool wellIsStopped() const
Definition: WellInterfaceGeneric.hpp:128
Scalar ref_depth_
Definition: WellInterfaceGeneric.hpp:402
bool thpLimitViolatedButNotSwitched() const
bool getAllowCrossFlow() const
std::vector< Scalar > inj_multiplier_
Definition: WellInterfaceGeneric.hpp:414
int currentStep() const
Definition: WellInterfaceGeneric.hpp:130
const ParallelWellInfo< Scalar > & parallelWellInfo() const
Definition: WellInterfaceGeneric.hpp:148
Definition: WellState.hpp:68
Definition: blackoilbioeffectsmodules.hh:45
Solver parameters for the NonlinearSystemBlackOilReservoir.
Definition: BlackoilModelParameters.hpp:207
Static data associated with a well perforation.
Definition: PerforationData.hpp:30
Definition: WellInterfaceGeneric.hpp:281
void resetOperability()
Definition: WellInterfaceGeneric.hpp:301
bool thp_limit_violated_but_not_switched
Definition: WellInterfaceGeneric.hpp:325
bool can_obtain_bhp_with_thp_limit
Definition: WellInterfaceGeneric.hpp:317
bool has_negative_potentials
Definition: WellInterfaceGeneric.hpp:323
bool isOperableUnderTHPLimit() const
Definition: WellInterfaceGeneric.hpp:296
bool obey_bhp_limit_with_thp_limit
Definition: WellInterfaceGeneric.hpp:319
bool solvable
Definition: WellInterfaceGeneric.hpp:321
bool operable_under_only_bhp_limit
Definition: WellInterfaceGeneric.hpp:312
bool use_vfpexplicit
Definition: WellInterfaceGeneric.hpp:327
bool isOperableUnderBHPLimit() const
Definition: WellInterfaceGeneric.hpp:291
bool obey_thp_limit_under_bhp_limit
Definition: WellInterfaceGeneric.hpp:315
bool isOperableAndSolvable() const
Definition: WellInterfaceGeneric.hpp:282