My Project
WellState.hpp
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 <opm/simulators/wells/ALQState.hpp>
25#include <opm/simulators/wells/SingleWellState.hpp>
26#include <opm/simulators/wells/GlobalWellInfo.hpp>
27#include <opm/simulators/wells/SegmentState.hpp>
28#include <opm/simulators/wells/WellContainer.hpp>
29#include <opm/core/props/BlackoilPhases.hpp>
30#include <opm/simulators/wells/PerforationData.hpp>
31#include <opm/simulators/wells/PerfData.hpp>
32#include <opm/output/data/Wells.hpp>
33
34#include <opm/input/eclipse/Schedule/Events.hpp>
35#include <opm/input/eclipse/Schedule/Well/Well.hpp>
36
37#include <dune/common/version.hh>
38#include <dune/common/parallel/mpihelper.hh>
39
40#include <functional>
41#include <map>
42#include <optional>
43#include <string>
44#include <utility>
45#include <vector>
46
47namespace Opm
48{
49
50class ParallelWellInfo;
51class Schedule;
52
56{
57public:
58 static const uint64_t event_mask = ScheduleEvents::WELL_STATUS_CHANGE + ScheduleEvents::PRODUCTION_UPDATE + ScheduleEvents::INJECTION_UPDATE;
59
60 virtual ~WellState() = default;
61
62 // TODO: same definition with WellInterface, eventually they should go to a common header file.
63 static const int Water = BlackoilPhases::Aqua;
64 static const int Oil = BlackoilPhases::Liquid;
65 static const int Gas = BlackoilPhases::Vapour;
66
67 explicit WellState(const PhaseUsage& pu)
68 {
69 this->phase_usage_ = pu;
70 }
71
72 std::size_t size() const {
73 return this->wells_.size();
74 }
75
76 std::vector<std::string> wells() const {
77 return this->wells_.wells();
78 }
79
80
81 int numWells() const
82 {
83 return this->size();
84 }
85
86 const ParallelWellInfo& parallelWellInfo(std::size_t well_index) const;
87
88
89
93 void init(const std::vector<double>& cellPressures,
94 const Schedule& schedule,
95 const std::vector<Well>& wells_ecl,
96 const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
97 const int report_step,
98 const WellState* prevState,
99 const std::vector<std::vector<PerforationData>>& well_perf_data,
100 const SummaryState& summary_state);
101
102 void resize(const std::vector<Well>& wells_ecl,
103 const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
104 const Schedule& schedule,
105 const bool handle_ms_well,
106 const size_t numCells,
107 const std::vector<std::vector<PerforationData>>& well_perf_data,
108 const SummaryState& summary_state);
109
110 void setCurrentWellRates(const std::string& wellName, const std::vector<double>& new_rates ) {
111 auto& [owner, rates] = this->well_rates.at(wellName);
112 if (owner)
113 rates = new_rates;
114 }
115
116 const std::vector<double>& currentWellRates(const std::string& wellName) const;
117
118 bool hasWellRates(const std::string& wellName) const {
119 return this->well_rates.find(wellName) != this->well_rates.end();
120 }
121
122 template<class Communication>
123 void gatherVectorsOnRoot(const std::vector< data::Connection >& from_connections,
124 std::vector< data::Connection >& to_connections,
125 const Communication& comm) const;
126
127 data::Wells
128 report(const int* globalCellIdxMap,
129 const std::function<bool(const int)>& wasDynamicallyClosed) const;
130
131 void reportConnections(std::vector<data::Connection>& connections, const PhaseUsage &pu,
132 std::size_t well_index,
133 const int* globalCellIdxMap) const;
134
136 void initWellStateMSWell(const std::vector<Well>& wells_ecl,
137 const WellState* prev_well_state);
138
139 static void calculateSegmentRates(const std::vector<std::vector<int>>& segment_inlets, const std::vector<std::vector<int>>&segment_perforations,
140 const std::vector<double>& perforation_rates, const int np, const int segment, std::vector<double>& segment_rates);
141
142
143 template<class Comm>
144 void communicateGroupRates(const Comm& comm);
145
146 template<class Comm>
147 void updateGlobalIsGrup(const Comm& comm);
148
149 bool isInjectionGrup(const std::string& name) const {
150 return this->global_well_info.value().in_injecting_group(name);
151 }
152
153 bool isProductionGrup(const std::string& name) const {
154 return this->global_well_info.value().in_producing_group(name);
155 }
156
157 double getALQ( const std::string& name) const
158 {
159 return this->alq_state.get(name);
160 }
161
162 void setALQ( const std::string& name, double value)
163 {
164 this->alq_state.set(name, value);
165 }
166
167 int gliftGetDebugCounter() {
168 return this->alq_state.get_debug_counter();
169 }
170
171 void gliftSetDebugCounter(int value) {
172 return this->alq_state.set_debug_counter(value);
173 }
174
175 int gliftUpdateDebugCounter() {
176 return this->alq_state.update_debug_counter();
177 }
178
179 bool gliftCheckAlqOscillation(const std::string &name) const {
180 return this->alq_state.oscillation(name);
181 }
182
183 int gliftGetAlqDecreaseCount(const std::string &name) {
184 return this->alq_state.get_decrement_count(name);
185 }
186
187 int gliftGetAlqIncreaseCount(const std::string &name) {
188 return this->alq_state.get_increment_count(name);
189 }
190
191 void gliftUpdateAlqIncreaseCount(const std::string &name, bool increase) {
192 this->alq_state.update_count(name, increase);
193 }
194
195 void gliftTimeStepInit() {
196 this->alq_state.reset_count();
197 }
198
199 int wellNameToGlobalIdx(const std::string &name) {
200 return this->global_well_info.value().well_index(name);
201 }
202
203 std::string globalIdxToWellName(const int index) {
204 return this->global_well_info.value().well_name(index);
205 }
206
207 bool wellIsOwned(std::size_t well_index,
208 const std::string& wellName) const;
209
210 bool wellIsOwned(const std::string& wellName) const;
211
212 void updateStatus(int well_index, Well::Status status);
213
214 void openWell(int well_index);
215 void shutWell(int well_index);
216 void stopWell(int well_index);
217
219 int numPhases() const
220 {
221 return this->phase_usage_.num_phases;
222 }
223
224 const PhaseUsage& phaseUsage() const {
225 return this->phase_usage_;
226 }
227
229 std::vector<double>& wellRates(std::size_t well_index) { return this->wells_[well_index].surface_rates; }
230 const std::vector<double>& wellRates(std::size_t well_index) const { return this->wells_[well_index].surface_rates; }
231
232 const std::string& name(std::size_t well_index) const {
233 return this->wells_.well_name(well_index);
234 }
235
236 std::optional<std::size_t> index(const std::string& well_name) const {
237 return this->wells_.well_index(well_name);
238 }
239
240 const SingleWellState& operator[](std::size_t well_index) const {
241 return this->wells_[well_index];
242 }
243
244 const SingleWellState& operator[](const std::string& well_name) const {
245 return this->wells_[well_name];
246 }
247
248 SingleWellState& operator[](std::size_t well_index) {
249 return this->wells_[well_index];
250 }
251
252 SingleWellState& operator[](const std::string& well_name) {
253 return this->wells_[well_name];
254 }
255
256 const SingleWellState& well(std::size_t well_index) const {
257 return this->operator[](well_index);
258 }
259
260 const SingleWellState& well(const std::string& well_name) const {
261 return this->operator[](well_name);
262 }
263
264 SingleWellState& well(std::size_t well_index) {
265 return this->operator[](well_index);
266 }
267
268 SingleWellState& well(const std::string& well_name) {
269 return this->operator[](well_name);
270 }
271
272 bool has(const std::string& well_name) const {
273 return this->wells_.has(well_name);
274 }
275
276private:
277 PhaseUsage phase_usage_;
278
279 // The wells_ variable is essentially a map of all the wells on the current
280 // process. Observe that since a well can be split over several processes a
281 // well might appear in the WellContainer on different processes.
282 WellContainer<SingleWellState> wells_;
283
284 // The members alq_state, global_well_info and well_rates are map like
285 // structures which will have entries for *all* the wells in the system.
286
287 // Use of std::optional<> here is a technical crutch, the
288 // WellStateFullyImplicitBlackoil class should be default constructible,
289 // whereas the GlobalWellInfo is not.
290 std::optional<GlobalWellInfo> global_well_info;
291 ALQState alq_state;
292
293 // The well_rates variable is defined for all wells on all processors. The
294 // bool in the value pair is whether the current process owns the well or
295 // not.
296 std::map<std::string, std::pair<bool, std::vector<double>>> well_rates;
297
298 data::Segment
299 reportSegmentResults(const int well_id,
300 const int seg_ix,
301 const int seg_no) const;
302
303 // If the ALQ has changed since the previous report step,
304 // reset current_alq and update default_alq. ALQ is used for
305 // constant lift gas injection and for gas lift optimization
306 // (THP controlled wells).
307
308 void updateWellsDefaultALQ(const std::vector<Well>& wells_ecl);
309
315 void base_init(const std::vector<double>& cellPressures,
316 const std::vector<Well>& wells_ecl,
317 const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
318 const std::vector<std::vector<PerforationData>>& well_perf_data,
319 const SummaryState& summary_state);
320
321 void initSingleWell(const std::vector<double>& cellPressures,
322 const Well& well,
323 const std::vector<PerforationData>& well_perf_data,
324 const ParallelWellInfo& well_info,
325 const SummaryState& summary_state);
326
327 void initSingleProducer(const Well& well,
328 const ParallelWellInfo& well_info,
329 double pressure_first_connection,
330 const std::vector<PerforationData>& well_perf_data,
331 const SummaryState& summary_state);
332
333 void initSingleInjector(const Well& well,
334 const ParallelWellInfo& well_info,
335 double pressure_first_connection,
336 const std::vector<PerforationData>& well_perf_data,
337 const SummaryState& summary_state);
338
339};
340
341} // namespace Opm
342
343
344#endif // OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:243
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: WellState.hpp:56
void init(const std::vector< double > &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)
Allocate and initialize if wells is non-null.
Definition: WellState.cpp:122
void initWellStateMSWell(const std::vector< Well > &wells_ecl, const WellState *prev_well_state)
init the MS well related.
Definition: WellState.cpp:507
int numPhases() const
The number of phases present.
Definition: WellState.hpp:219
std::vector< double > & wellRates(std::size_t well_index)
One rate per well and phase.
Definition: WellState.hpp:229
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
Definition: BlackoilPhases.hpp:46