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