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 <map>
32#include <optional>
33#include <string>
34#include <vector>
35
36namespace Opm
37{
38
39class DeferredLogger;
40class GuideRate;
41template<class Scalar> class ParallelWellInfo;
42template<class Scalar> struct PerforationData;
43class SummaryState;
44template<typename Scalar, typename IndexTraits> class VFPProperties;
45class WellTestState;
46template<typename Scalar, typename IndexTraits> class WellState;
47template<typename Scalar, typename IndexTraits> class SingleWellState;
48class Group;
49class Schedule;
50template<typename IndexTraits> class PhaseUsageInfo;
51
52template<typename Scalar, typename IndexTraits>
54public:
56
58
59 WellInterfaceGeneric(const Well& well,
60 const ParallelWellInfo<Scalar>& parallel_well_info,
61 const int time_step,
62 const ModelParameters& param,
63 const int pvtRegionIdx,
64 const int num_conservation_quantities,
65 const int num_phases,
66 const int index_of_well,
67 const PhaseUsageInfo<IndexTraits>& phase_usage,
68 const std::vector<PerforationData<Scalar>>& perf_data);
69
71 const std::vector<PerforationData<Scalar>>& perforationData() const;
72
74 const std::string& name() const;
75
77 bool isInjector() const;
78
80 bool isProducer() const;
81
83 const std::vector<int>& cells() const { return well_cells_; }
84
86 int indexOfWell() const;
87
88 void adaptRatesForVFP(std::vector<Scalar>& rates) const;
89
90 const Well& wellEcl() const;
91 Well& wellEcl();
93
95 bool underPredictionMode() const;
96
97 // whether the well is operable
99 bool useVfpExplicit () const;
101
103 void closeCompletions(const WellTestState& wellTestState);
104
107 const WellStateType& prev_well_state) const;
108 void setGuideRate(const GuideRate* guide_rate_arg);
109 void setWellEfficiencyFactor(const Scalar efficiency_factor);
111 void setWsolvent(const Scalar wsolvent);
112 void setDynamicThpLimit(const Scalar thp_limit);
113 std::optional<Scalar> getDynamicThpLimit() const;
114 void setDynamicThpLimit(const std::optional<Scalar> thp_limit);
115 void updatePerforatedCell(std::vector<bool>& is_cell_perforated);
116
118 bool wellHasTHPConstraints(const SummaryState& summaryState) const;
119
120 void stopWell() { this->wellStatus_ = Well::Status::STOP; }
121 void openWell() { this->wellStatus_ = Well::Status::OPEN; }
122
123 bool wellIsStopped() const { return this->wellStatus_ == Well::Status::STOP; }
124
125 int currentStep() const { return this->current_step_; }
126
127 int pvtRegionIdx() const { return pvtRegionIdx_; }
128
129 const GuideRate* guideRate() const { return guide_rate_; }
130
132
133 int numPhases() const { return number_of_phases_; }
134
136
137 Scalar refDepth() const { return ref_depth_; }
138
139 Scalar gravity() const { return gravity_; }
140
142
144
145 const std::vector<Scalar>& perfDepth() const { return perf_depth_; }
146
147 std::vector<Scalar>& perfDepth() { return perf_depth_; }
148
149 const std::vector<Scalar>& wellIndex() const { return well_index_; }
150
151 const std::map<int,std::vector<int>>& getCompletions() const { return completions_; }
152
153 Scalar getTHPConstraint(const SummaryState& summaryState) const;
154 Scalar getALQ(const WellStateType& well_state) const;
155 Scalar wsolvent() const;
156 Scalar rsRvInj() const;
157
158 // at the beginning of the time step, we check what inj_multiplier from the previous running
159 void initInjMult(const std::vector<Scalar>& max_inj_mult);
160
161 // update the InjMult information at the end of the time step, so it can be used for later.
162 void updateInjMult(std::vector<Scalar>& inj_multipliers,
163 DeferredLogger& deferred_logger) const;
164
165 // Note:: for multisegment wells, bhp is actually segment pressure in practice based on observation
166 // it might change in the future
167 Scalar getInjMult(const int local_perf_index, const Scalar bhp, const Scalar perf_pres, DeferredLogger& dlogger) const;
168
169 // whether a well is specified with a non-zero and valid VFP table number
170 bool isVFPActive(DeferredLogger& deferred_logger) const;
171
173 DeferredLogger& deferred_logger) const;
174
176
178 const double& simulationTime,
179 const bool& writeMessageToOPMLog,
180 const bool zero_group_target,
181 WellTestState& wellTestState,
182 DeferredLogger& deferred_logger) const;
183
184 bool isPressureControlled(const WellStateType& well_state) const;
185
187
189 void updateFilterCakeMultipliers(const std::vector<Scalar>& inj_fc_multiplier)
190 {
191 inj_fc_multiplier_ = inj_fc_multiplier;
192 }
193
195
196 virtual std::vector<Scalar> getPrimaryVars() const
197 {
198 return {};
199 }
200
201 virtual int setPrimaryVars(typename std::vector<Scalar>::const_iterator)
202 {
203 return 0;
204 }
205
206 virtual Scalar connectionDensity(const int globalConnIdx,
207 const int openConnIdx) const = 0;
208
209 void addPerforations(const std::vector<RuntimePerforation>& perfs);
210
211protected:
212 bool getAllowCrossFlow() const;
213
214 Scalar wmicrobes_() const;
215 Scalar wfoam_() const;
216 Scalar woxygen_() const;
217 Scalar wpolymer_() const;
218 Scalar wsalt_() const;
219 Scalar wurea_() const;
220
221 int polymerTable_() const;
222 int polymerInjTable_() const;
224
225 bool wellUnderZeroRateTargetIndividual(const SummaryState& summary_state,
226 const WellState<Scalar, IndexTraits>& well_state) const;
227
229
230 std::pair<bool,bool>
231 computeWellPotentials(std::vector<Scalar>& well_potentials,
232 const WellStateType& well_state);
233
234 void checkNegativeWellPotentials(std::vector<Scalar>& well_potentials,
235 const bool checkOperability,
236 DeferredLogger& deferred_logger);
237
238 void prepareForPotentialCalculations(const SummaryState& summary_state,
239 WellStateType& well_state,
240 Well::InjectionControls& inj_controls,
241 Well::ProductionControls& prod_controls) const;
242
244 std::fill(this->inj_multiplier_damp_factor_.begin(), this->inj_multiplier_damp_factor_.end(), 1.0);
245 }
246
247 // definition of the struct OperabilityStatus
249 {
251 {
253 return false;
254 } else {
256 }
257 }
258
260 {
262 }
263
265 {
267 }
268
270 {
275 }
276
277 // whether the well can be operated under bhp limit
278 // without considering other limits.
279 // if it is false, then the well is not operable for sure.
281 // if the well can be operated under bhp limit, will it obey(not violate)
282 // the thp limit when operated under bhp limit
284 // whether the well operate under the thp limit only
286 // whether the well obey bhp limit when operated under thp limit
288 // the well is solveable
289 bool solvable = true;
290 // the well have non positive potentials
292 //thp limit violated but not switched
294
295 bool use_vfpexplicit = false;
296 };
297
299
301
303 const int current_step_;
305
306 // The pvt region of the well. We assume
307 // We assume a well to not penetrate more than one pvt region.
308 const int pvtRegionIdx_;
309
311
312 // number of phases
314
315 // the index of well in Wells struct
317
319
320 const std::vector<PerforationData<Scalar>>* perf_data_;
321
322 // the vectors used to describe the inflow performance relationship (IPR)
323 // Q = IPR_A - BHP * IPR_B
324 // TODO: it minght need to go to WellInterface, let us implement it in StandardWell first
325 // it is only updated and used for producers for now
326 mutable std::vector<Scalar> ipr_a_;
327 mutable std::vector<Scalar> ipr_b_;
328
329 // cell index for each well perforation
330 std::vector<int> well_cells_;
331
332 // well index for each perforation
333 std::vector<Scalar> well_index_;
334
335 // number of the perforations for this well on this process
337
338 // depth for each perforation
339 std::vector<Scalar> perf_depth_;
340
341 // representative radius of the perforations, used in shear calculation
342 std::vector<Scalar> perf_rep_radius_;
343
344 // length of the perforations, use in shear calculation
345 std::vector<Scalar> perf_length_;
346
347 // well bore diameter
348 std::vector<Scalar> bore_diameters_;
349
350 /*
351 * completions_ contains the mapping from completion id to connection indices
352 * {
353 * 2 : [ConnectionIndex, ConnectionIndex],
354 * 1 : [ConnectionIndex, ConnectionIndex, ConnectionIndex],
355 * 5 : [ConnectionIndex],
356 * 7 : [ConnectionIndex]
357 * ...
358 * }
359 * The integer IDs correspond to the COMPLETION id given by the COMPLUMP keyword.
360 * When there is no COMPLUMP keyword used, a default completion number will be assigned
361 * based on the order of the declaration of the connections.
362 * Since the connections not OPEN is not included in the Wells, so they will not be considered
363 * in this mapping relation.
364 */
365 std::map<int, std::vector<int>> completions_;
366
367 // reference depth for the BHP
369
370 // saturation table nubmer for each well perforation
371 std::vector<int> saturation_table_number_;
372
373 Well::Status wellStatus_;
374
375 Scalar gravity_;
376 Scalar wsolvent_;
377 std::optional<Scalar> dynamic_thp_limit_;
378
379 // recording the multiplier calculate from the keyword WINJMULT during the time step
380 mutable std::vector<Scalar> inj_multiplier_;
381
382 // the injection multiplier from the previous running, it is mostly used for CIRR mode
383 // which intends to keep the fracturing open
384 std::vector<Scalar> prev_inj_multiplier_;
385
386 // WINJMULT multipliers for previous iteration (used for oscillation detection)
387 mutable std::vector<Scalar> inj_multiplier_previter_;
388 // WINJMULT dampening factors (used in case of oscillations)
389 mutable std::vector<Scalar> inj_multiplier_damp_factor_;
390
391 // the multiplier due to injection filtration cake
392 std::vector<Scalar> inj_fc_multiplier_;
393
396 const GuideRate* guide_rate_;
397
398 std::vector<std::string> well_control_log_;
399
401};
402
403}
404
405#endif // OPM_WELLINTERFACE_GENERIC_HEADER_INCLUDED
Definition: DeferredLogger.hpp:57
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
Definition: GasLiftGroupInfo.hpp:37
Definition: SingleWellState.hpp:43
Definition: VFPProperties.hpp:40
Definition: WellInterfaceGeneric.hpp:53
int pvtRegionIdx() const
Definition: WellInterfaceGeneric.hpp:127
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)
const std::map< int, std::vector< int > > & getCompletions() const
Definition: WellInterfaceGeneric.hpp:151
const int num_conservation_quantities_
Definition: WellInterfaceGeneric.hpp:310
bool isVFPActive(DeferredLogger &deferred_logger) const
void openWell()
Definition: WellInterfaceGeneric.hpp:121
std::vector< int > saturation_table_number_
Definition: WellInterfaceGeneric.hpp:371
bool isOperableAndSolvable() const
std::vector< int > well_cells_
Definition: WellInterfaceGeneric.hpp:330
void updatePerforatedCell(std::vector< bool > &is_cell_perforated)
int index_of_well_
Definition: WellInterfaceGeneric.hpp:316
std::optional< Scalar > dynamic_thp_limit_
Definition: WellInterfaceGeneric.hpp:377
std::vector< Scalar > perf_depth_
Definition: WellInterfaceGeneric.hpp:339
int numPhases() const
Definition: WellInterfaceGeneric.hpp:133
Scalar gravity() const
Definition: WellInterfaceGeneric.hpp:139
const GuideRate * guideRate() const
Definition: WellInterfaceGeneric.hpp:129
std::vector< Scalar > prev_inj_multiplier_
Definition: WellInterfaceGeneric.hpp:384
int polymerWaterTable_() const
int number_of_phases_
Definition: WellInterfaceGeneric.hpp:313
void setWsolvent(const Scalar wsolvent)
std::vector< Scalar > & perfDepth()
Definition: WellInterfaceGeneric.hpp:147
const PhaseUsageInfo< IndexTraits > & phase_usage_
Definition: WellInterfaceGeneric.hpp:318
Scalar wpolymer_() const
const int current_step_
Definition: WellInterfaceGeneric.hpp:303
std::vector< Scalar > ipr_a_
Definition: WellInterfaceGeneric.hpp:326
Well well_ecl_
Definition: WellInterfaceGeneric.hpp:300
const std::vector< Scalar > & perfDepth() const
Definition: WellInterfaceGeneric.hpp:145
bool wellUnderGroupControl(const SingleWellState< Scalar, IndexTraits > &ws) const
const Well & wellEcl() const
const ParallelWellInfo< Scalar > & parallel_well_info_
Definition: WellInterfaceGeneric.hpp:302
Scalar wmicrobes_() const
const PhaseUsageInfo< IndexTraits > & phaseUsage() const
std::vector< Scalar > ipr_b_
Definition: WellInterfaceGeneric.hpp:327
const int pvtRegionIdx_
Definition: WellInterfaceGeneric.hpp:308
std::vector< Scalar > inj_multiplier_damp_factor_
Definition: WellInterfaceGeneric.hpp:389
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:396
OperabilityStatus operability_status_
Definition: WellInterfaceGeneric.hpp:298
bool wellUnderZeroRateTargetIndividual(const SummaryState &summary_state, const WellState< Scalar, IndexTraits > &well_state) const
Well::Status wellStatus_
Definition: WellInterfaceGeneric.hpp:373
int numLocalPerfs() const
Definition: WellInterfaceGeneric.hpp:135
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:189
Scalar well_efficiency_factor_
Definition: WellInterfaceGeneric.hpp:394
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:387
std::vector< Scalar > inj_fc_multiplier_
Definition: WellInterfaceGeneric.hpp:392
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
bool changedToOpenThisStep() const
Definition: WellInterfaceGeneric.hpp:175
void setGuideRate(const GuideRate *guide_rate_arg)
const std::vector< PerforationData< Scalar > > * perf_data_
Definition: WellInterfaceGeneric.hpp:320
bool isInjector() const
True if the well is an injector.
int numConservationQuantities() const
Definition: WellInterfaceGeneric.hpp:131
const VFPProperties< Scalar, IndexTraits > * vfpProperties() const
Definition: WellInterfaceGeneric.hpp:141
Scalar refDepth() const
Definition: WellInterfaceGeneric.hpp:137
Scalar getALQ(const WellStateType &well_state) const
void stopWell()
Definition: WellInterfaceGeneric.hpp:120
Scalar wellEfficiencyFactor() const
Definition: WellInterfaceGeneric.hpp:186
std::vector< std::string > well_control_log_
Definition: WellInterfaceGeneric.hpp:398
void resetDampening()
Definition: WellInterfaceGeneric.hpp:243
int indexOfWell() const
Index of well in the wells struct and wellState.
virtual std::vector< Scalar > getPrimaryVars() const
Definition: WellInterfaceGeneric.hpp:196
const std::vector< PerforationData< Scalar > > & perforationData() const
Get the perforations of the well.
std::vector< Scalar > perf_length_
Definition: WellInterfaceGeneric.hpp:345
const std::vector< int > & cells() const
Well cells.
Definition: WellInterfaceGeneric.hpp:83
int number_of_local_perforations_
Definition: WellInterfaceGeneric.hpp:336
std::vector< Scalar > well_index_
Definition: WellInterfaceGeneric.hpp:333
virtual int setPrimaryVars(typename std::vector< Scalar >::const_iterator)
Definition: WellInterfaceGeneric.hpp:201
void updateWellTestState(const SingleWellState< Scalar, IndexTraits > &ws, const double &simulationTime, const bool &writeMessageToOPMLog, const bool zero_group_target, WellTestState &wellTestState, DeferredLogger &deferred_logger) const
void setVFPProperties(const VFPProperties< Scalar, IndexTraits > *vfp_properties_arg)
const std::string & name() const
Well name.
const ModelParameters & param_
Definition: WellInterfaceGeneric.hpp:304
std::pair< bool, bool > computeWellPotentials(std::vector< Scalar > &well_potentials, const WellStateType &well_state)
bool changed_to_open_this_step_
Definition: WellInterfaceGeneric.hpp:400
void setWellEfficiencyFactor(const Scalar efficiency_factor)
const VFPProperties< Scalar, IndexTraits > * vfp_properties_
Definition: WellInterfaceGeneric.hpp:395
void initInjMult(const std::vector< Scalar > &max_inj_mult)
Scalar wsolvent_
Definition: WellInterfaceGeneric.hpp:376
std::map< int, std::vector< int > > completions_
Definition: WellInterfaceGeneric.hpp:365
void setDynamicThpLimit(const std::optional< Scalar > thp_limit)
std::vector< Scalar > perf_rep_radius_
Definition: WellInterfaceGeneric.hpp:342
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:149
void prepareForPotentialCalculations(const SummaryState &summary_state, WellStateType &well_state, Well::InjectionControls &inj_controls, Well::ProductionControls &prod_controls) const
Scalar gravity_
Definition: WellInterfaceGeneric.hpp:375
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:348
bool wellIsStopped() const
Definition: WellInterfaceGeneric.hpp:123
Scalar ref_depth_
Definition: WellInterfaceGeneric.hpp:368
bool thpLimitViolatedButNotSwitched() const
bool getAllowCrossFlow() const
std::vector< Scalar > inj_multiplier_
Definition: WellInterfaceGeneric.hpp:380
int currentStep() const
Definition: WellInterfaceGeneric.hpp:125
const ParallelWellInfo< Scalar > & parallelWellInfo() const
Definition: WellInterfaceGeneric.hpp:143
Definition: WellState.hpp:66
Definition: blackoilboundaryratevector.hh:39
Solver parameters for the BlackoilModel.
Definition: BlackoilModelParameters.hpp:179
Static data associated with a well perforation.
Definition: PerforationData.hpp:30
Definition: WellInterfaceGeneric.hpp:249
void resetOperability()
Definition: WellInterfaceGeneric.hpp:269
bool thp_limit_violated_but_not_switched
Definition: WellInterfaceGeneric.hpp:293
bool can_obtain_bhp_with_thp_limit
Definition: WellInterfaceGeneric.hpp:285
bool has_negative_potentials
Definition: WellInterfaceGeneric.hpp:291
bool isOperableUnderTHPLimit() const
Definition: WellInterfaceGeneric.hpp:264
bool obey_bhp_limit_with_thp_limit
Definition: WellInterfaceGeneric.hpp:287
bool solvable
Definition: WellInterfaceGeneric.hpp:289
bool operable_under_only_bhp_limit
Definition: WellInterfaceGeneric.hpp:280
bool use_vfpexplicit
Definition: WellInterfaceGeneric.hpp:295
bool isOperableUnderBHPLimit() const
Definition: WellInterfaceGeneric.hpp:259
bool obey_thp_limit_under_bhp_limit
Definition: WellInterfaceGeneric.hpp:283
bool isOperableAndSolvable() const
Definition: WellInterfaceGeneric.hpp:250