WellState.hpp
Go to the documentation of this file.
1/*
2 Copyright 2014 SINTEF ICT, Applied Mathematics.
3 Copyright 2017 IRIS AS
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
22#define OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
23
24#include <dune/common/version.hh>
25#include <dune/common/parallel/mpihelper.hh>
26
28
29#include <opm/common/ErrorMacros.hpp>
30
31#include <opm/input/eclipse/Schedule/Events.hpp>
32
33#include <opm/output/data/Wells.hpp>
34
43
44#include <functional>
45#include <map>
46#include <optional>
47#include <string>
48#include <utility>
49#include <vector>
50
51namespace Opm
52{
53
54class ParallelWellInfo;
55class Schedule;
56enum class WellStatus;
57
60template<class Scalar>
62{
63public:
64 static const uint64_t event_mask = ScheduleEvents::WELL_STATUS_CHANGE + ScheduleEvents::PRODUCTION_UPDATE + ScheduleEvents::INJECTION_UPDATE;
65 // TODO: same definition with WellInterface, eventually they should go to a common header file.
66 static const int Water = BlackoilPhases::Aqua;
67 static const int Oil = BlackoilPhases::Liquid;
68 static const int Gas = BlackoilPhases::Vapour;
69
70 // Only usable for testing purposes
71 explicit WellState(const ParallelWellInfo& pinfo);
72
73 explicit WellState(const PhaseUsage& pu)
74 : phase_usage_(pu)
75 {}
76
78
79 std::size_t size() const
80 {
81 return this->wells_.size();
82 }
83
84 std::vector<std::string> wells() const
85 {
86 return this->wells_.wells();
87 }
88
89 int numWells() const
90 {
91 return this->size();
92 }
93
94 const ParallelWellInfo& parallelWellInfo(std::size_t well_index) const;
95
99 void init(const std::vector<Scalar>& cellPressures,
100 const Schedule& schedule,
101 const std::vector<Well>& wells_ecl,
102 const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
103 const int report_step,
104 const WellState* prevState,
105 const std::vector<std::vector<PerforationData>>& well_perf_data,
106 const SummaryState& summary_state);
107
108 void resize(const std::vector<Well>& wells_ecl,
109 const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
110 const Schedule& schedule,
111 const bool handle_ms_well,
112 const std::size_t numCells,
113 const std::vector<std::vector<PerforationData>>& well_perf_data,
114 const SummaryState& summary_state);
115
116 void setCurrentWellRates(const std::string& wellName,
117 const std::vector<Scalar>& new_rates)
118 {
119 auto& [owner, rates] = this->well_rates.at(wellName);
120 if (owner)
121 rates = new_rates;
122 }
123
124 const std::vector<Scalar>& currentWellRates(const std::string& wellName) const;
125
126 bool hasWellRates(const std::string& wellName) const
127 {
128 return this->well_rates.find(wellName) != this->well_rates.end();
129 }
130
132 {
133 this->well_rates.clear();
134 }
135
136 void gatherVectorsOnRoot(const std::vector<data::Connection>& from_connections,
137 std::vector<data::Connection>& to_connections,
138 const Parallel::Communication& comm) const;
139
140 data::Wells
141 report(const int* globalCellIdxMap,
142 const std::function<bool(const int)>& wasDynamicallyClosed) const;
143
144 void reportConnections(std::vector<data::Connection>& connections,
145 const PhaseUsage &pu,
146 std::size_t well_index,
147 const int* globalCellIdxMap) const;
148
150 void initWellStateMSWell(const std::vector<Well>& wells_ecl,
151 const WellState* prev_well_state);
152
153 static void calculateSegmentRates(const std::vector<std::vector<int>>& segment_inlets, const
154 std::vector<std::vector<int>>& segment_perforations,
155 const std::vector<Scalar>& perforation_rates,
156 const int np,
157 const int segment,
158 std::vector<Scalar>& segment_rates);
159
160
162
164
165 bool isInjectionGrup(const std::string& name) const
166 {
167 return this->global_well_info.value().in_injecting_group(name);
168 }
169
170 bool isProductionGrup(const std::string& name) const
171 {
172 return this->global_well_info.value().in_producing_group(name);
173 }
174
175 Scalar getALQ(const std::string& name) const
176 {
177 return this->alq_state.get(name);
178 }
179
180 void setALQ(const std::string& name, Scalar value)
181 {
182 this->alq_state.set(name, value);
183 }
184
186 {
187 return this->alq_state.get_debug_counter();
188 }
189
190 void gliftSetDebugCounter(int value)
191 {
192 return this->alq_state.set_debug_counter(value);
193 }
194
196 {
197 return this->alq_state.update_debug_counter();
198 }
199
200 bool gliftCheckAlqOscillation(const std::string &name) const
201 {
202 return this->alq_state.oscillation(name);
203 }
204
205 int gliftGetAlqDecreaseCount(const std::string &name)
206 {
207 return this->alq_state.get_decrement_count(name);
208 }
209
210 int gliftGetAlqIncreaseCount(const std::string &name)
211 {
212 return this->alq_state.get_increment_count(name);
213 }
214
215 void gliftUpdateAlqIncreaseCount(const std::string &name, bool increase)
216 {
217 this->alq_state.update_count(name, increase);
218 }
219
221 {
222 this->alq_state.reset_count();
223 }
224
225 // If the ALQ has changed since the previous time step,
226 // reset current_alq and update default_alq. ALQ is used for
227 // constant lift gas injection and for gas lift optimization
228 // (THP controlled wells).
229 void updateWellsDefaultALQ(const std::vector<Well>& wells_ecl,
230 const SummaryState& summary_state);
231
232 int wellNameToGlobalIdx(const std::string& name)
233 {
234 return this->global_well_info.value().well_index(name);
235 }
236
237 std::string globalIdxToWellName(const int index)
238 {
239 return this->global_well_info.value().well_name(index);
240 }
241
242 bool wellIsOwned(std::size_t well_index,
243 const std::string& wellName) const;
244
245 bool wellIsOwned(const std::string& wellName) const;
246
247 void updateStatus(int well_index, WellStatus status);
248
249 void openWell(int well_index);
250 void shutWell(int well_index);
251 void stopWell(int well_index);
252
254 int numPhases() const
255 {
256 return this->phase_usage_.num_phases;
257 }
258
259 const PhaseUsage& phaseUsage() const
260 {
261 return this->phase_usage_;
262 }
263
265 std::vector<Scalar>& wellRates(std::size_t well_index)
266 { return this->wells_[well_index].surface_rates; }
267 const std::vector<Scalar>& wellRates(std::size_t well_index) const
268 { return this->wells_[well_index].surface_rates; }
269
270 const std::string& name(std::size_t well_index) const
271 {
272 return this->wells_.well_name(well_index);
273 }
274
275 std::optional<std::size_t> index(const std::string& well_name) const
276 {
277 return this->wells_.well_index(well_name);
278 }
279
280 const SingleWellState<Scalar>& operator[](std::size_t well_index) const
281 {
282 return this->wells_[well_index];
283 }
284
285 const SingleWellState<Scalar>& operator[](const std::string& well_name) const
286 {
287 return this->wells_[well_name];
288 }
289
290 SingleWellState<Scalar>& operator[](std::size_t well_index)
291 {
292 return this->wells_[well_index];
293 }
294
295 SingleWellState<Scalar>& operator[](const std::string& well_name)
296 {
297 return this->wells_[well_name];
298 }
299
300 const SingleWellState<Scalar>& well(std::size_t well_index) const
301 {
302 return this->operator[](well_index);
303 }
304
305 const SingleWellState<Scalar>& well(const std::string& well_name) const
306 {
307 return this->operator[](well_name);
308 }
309
310 SingleWellState<Scalar>& well(std::size_t well_index)
311 {
312 return this->operator[](well_index);
313 }
314
315 SingleWellState<Scalar>& well(const std::string& well_name)
316 {
317 return this->operator[](well_name);
318 }
319
320 bool has(const std::string& well_name) const
321 {
322 return this->wells_.has(well_name);
323 }
324
325 bool operator==(const WellState&) const;
326
327 template<class Serializer>
328 void serializeOp(Serializer& serializer)
329 {
330 serializer(alq_state);
331 serializer(well_rates);
332 if (serializer.isSerializing()) {
333 serializer(wells_.size());
334 } else {
335 std::size_t size = 0;
336 serializer(size);
337 if (size != wells_.size()) {
338 OPM_THROW(std::runtime_error, "Error deserializing WellState: size mismatch");
339 }
340 }
341 for (auto& w : wells_) {
342 serializer(w);
343 }
344 }
345
346private:
347 PhaseUsage phase_usage_;
348
349 // The wells_ variable is essentially a map of all the wells on the current
350 // process. Observe that since a well can be split over several processes a
351 // well might appear in the WellContainer on different processes.
353
354 // The members alq_state, global_well_info and well_rates are map like
355 // structures which will have entries for *all* the wells in the system.
356
357 // Use of std::optional<> here is a technical crutch, the
358 // WellStateFullyImplicitBlackoil class should be default constructible,
359 // whereas the GlobalWellInfo is not.
360 std::optional<GlobalWellInfo> global_well_info;
361 ALQState<Scalar> alq_state;
362
363 // The well_rates variable is defined for all wells on all processors. The
364 // bool in the value pair is whether the current process owns the well or
365 // not.
366 std::map<std::string, std::pair<bool, std::vector<Scalar>>> well_rates;
367
368 data::Segment
369 reportSegmentResults(const int well_id,
370 const int seg_ix,
371 const int seg_no) const;
372
373
379 void base_init(const std::vector<Scalar>& cellPressures,
380 const std::vector<Well>& wells_ecl,
381 const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
382 const std::vector<std::vector<PerforationData>>& well_perf_data,
383 const SummaryState& summary_state);
384
385 void initSingleWell(const std::vector<Scalar>& cellPressures,
386 const Well& well,
387 const std::vector<PerforationData>& well_perf_data,
388 const ParallelWellInfo& well_info,
389 const SummaryState& summary_state);
390
391 void initSingleProducer(const Well& well,
392 const ParallelWellInfo& well_info,
393 Scalar pressure_first_connection,
394 const std::vector<PerforationData>& well_perf_data,
395 const SummaryState& summary_state);
396
397 void initSingleInjector(const Well& well,
398 const ParallelWellInfo& well_info,
399 Scalar pressure_first_connection,
400 const std::vector<PerforationData>& well_perf_data,
401 const SummaryState& summary_state);
402};
403
404} // namespace Opm
405
406#endif // OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
Definition: ALQState.hpp:30
@ Liquid
Definition: BlackoilPhases.hpp:42
@ Aqua
Definition: BlackoilPhases.hpp:42
@ Vapour
Definition: BlackoilPhases.hpp:42
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:184
Definition: SingleWellState.hpp:41
Definition: WellContainer.hpp:46
Definition: WellState.hpp:62
data::Wells report(const int *globalCellIdxMap, const std::function< bool(const int)> &wasDynamicallyClosed) const
std::vector< std::string > wells() const
Definition: WellState.hpp:84
bool isInjectionGrup(const std::string &name) const
Definition: WellState.hpp:165
std::string globalIdxToWellName(const int index)
Definition: WellState.hpp:237
void initWellStateMSWell(const std::vector< Well > &wells_ecl, const WellState *prev_well_state)
init the MS well related.
const SingleWellState< Scalar > & well(const std::string &well_name) const
Definition: WellState.hpp:305
SingleWellState< Scalar > & well(std::size_t well_index)
Definition: WellState.hpp:310
const SingleWellState< Scalar > & well(std::size_t well_index) const
Definition: WellState.hpp:300
const SingleWellState< Scalar > & operator[](std::size_t well_index) const
Definition: WellState.hpp:280
void reportConnections(std::vector< data::Connection > &connections, const PhaseUsage &pu, std::size_t well_index, const int *globalCellIdxMap) const
const std::vector< Scalar > & currentWellRates(const std::string &wellName) const
bool operator==(const WellState &) const
int gliftGetAlqIncreaseCount(const std::string &name)
Definition: WellState.hpp:210
void setALQ(const std::string &name, Scalar value)
Definition: WellState.hpp:180
SingleWellState< Scalar > & well(const std::string &well_name)
Definition: WellState.hpp:315
bool wellIsOwned(std::size_t well_index, const std::string &wellName) const
int numPhases() const
The number of phases present.
Definition: WellState.hpp:254
static void calculateSegmentRates(const std::vector< std::vector< int > > &segment_inlets, const std::vector< std::vector< int > > &segment_perforations, const std::vector< Scalar > &perforation_rates, const int np, const int segment, std::vector< Scalar > &segment_rates)
const ParallelWellInfo & parallelWellInfo(std::size_t well_index) const
int gliftUpdateDebugCounter()
Definition: WellState.hpp:195
static WellState serializationTestObject(const ParallelWellInfo &pinfo)
void init(const std::vector< Scalar > &cellPressures, const Schedule &schedule, const std::vector< Well > &wells_ecl, const std::vector< std::reference_wrapper< ParallelWellInfo > > &parallel_well_info, const int report_step, const WellState *prevState, const std::vector< std::vector< PerforationData > > &well_perf_data, const SummaryState &summary_state)
static const uint64_t event_mask
Definition: WellState.hpp:64
void serializeOp(Serializer &serializer)
Definition: WellState.hpp:328
void updateWellsDefaultALQ(const std::vector< Well > &wells_ecl, const SummaryState &summary_state)
void openWell(int well_index)
void gliftSetDebugCounter(int value)
Definition: WellState.hpp:190
std::optional< std::size_t > index(const std::string &well_name) const
Definition: WellState.hpp:275
void gliftTimeStepInit()
Definition: WellState.hpp:220
const PhaseUsage & phaseUsage() const
Definition: WellState.hpp:259
bool wellIsOwned(const std::string &wellName) const
const std::vector< Scalar > & wellRates(std::size_t well_index) const
Definition: WellState.hpp:267
WellState(const ParallelWellInfo &pinfo)
void communicateGroupRates(const Parallel::Communication &comm)
bool has(const std::string &well_name) const
Definition: WellState.hpp:320
void clearWellRates()
Definition: WellState.hpp:131
int wellNameToGlobalIdx(const std::string &name)
Definition: WellState.hpp:232
SingleWellState< Scalar > & operator[](std::size_t well_index)
Definition: WellState.hpp:290
const std::string & name(std::size_t well_index) const
Definition: WellState.hpp:270
bool hasWellRates(const std::string &wellName) const
Definition: WellState.hpp:126
void setCurrentWellRates(const std::string &wellName, const std::vector< Scalar > &new_rates)
Definition: WellState.hpp:116
void updateStatus(int well_index, WellStatus status)
SingleWellState< Scalar > & operator[](const std::string &well_name)
Definition: WellState.hpp:295
const SingleWellState< Scalar > & operator[](const std::string &well_name) const
Definition: WellState.hpp:285
bool gliftCheckAlqOscillation(const std::string &name) const
Definition: WellState.hpp:200
bool isProductionGrup(const std::string &name) const
Definition: WellState.hpp:170
int gliftGetAlqDecreaseCount(const std::string &name)
Definition: WellState.hpp:205
void gatherVectorsOnRoot(const std::vector< data::Connection > &from_connections, std::vector< data::Connection > &to_connections, const Parallel::Communication &comm) const
void stopWell(int well_index)
void gliftUpdateAlqIncreaseCount(const std::string &name, bool increase)
Definition: WellState.hpp:215
int gliftGetDebugCounter()
Definition: WellState.hpp:185
void shutWell(int well_index)
static const int Gas
Definition: WellState.hpp:68
static const int Oil
Definition: WellState.hpp:67
WellState(const PhaseUsage &pu)
Definition: WellState.hpp:73
std::vector< Scalar > & wellRates(std::size_t well_index)
One rate per well and phase.
Definition: WellState.hpp:265
std::size_t size() const
Definition: WellState.hpp:79
int numWells() const
Definition: WellState.hpp:89
void resize(const std::vector< Well > &wells_ecl, const std::vector< std::reference_wrapper< ParallelWellInfo > > &parallel_well_info, const Schedule &schedule, const bool handle_ms_well, const std::size_t numCells, const std::vector< std::vector< PerforationData > > &well_perf_data, const SummaryState &summary_state)
void updateGlobalIsGrup(const Parallel::Communication &comm)
static const int Water
Definition: WellState.hpp:66
Scalar getALQ(const std::string &name) const
Definition: WellState.hpp:175
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: BlackoilPhases.hpp:27
Definition: BlackoilPhases.hpp:46
int num_phases
Definition: BlackoilPhases.hpp:54