GroupState.hpp
Go to the documentation of this file.
1/*
2 Copyright 2021 Equinor
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_GROUPSTATE_HEADER_INCLUDED
21#define OPM_GROUPSTATE_HEADER_INCLUDED
22
23#include <opm/input/eclipse/EclipseState/Phase.hpp>
24
25#include <opm/input/eclipse/Schedule/Group/GPMaint.hpp>
26#include <opm/input/eclipse/Schedule/Group/Group.hpp>
27
29
30#include <map>
31#include <vector>
32#include <utility>
33
34namespace Opm {
35
36 class GConSump;
37 class Schedule;
38 class SummaryState;
39
40template<class Scalar>
42public:
43 GroupState() = default;
44 explicit GroupState(std::size_t num_phases);
45
47
48 bool operator==(const GroupState& other) const;
49
50 bool has_production_rates(const std::string& gname) const;
51 void update_production_rates(const std::string& gname,
52 const std::vector<Scalar>& rates);
53 void update_network_leaf_node_injection_rates(const std::string& gname,
54 const std::vector<Scalar>& rates);
55 void update_network_leaf_node_production_rates(const std::string& gname,
56 const std::vector<Scalar>& rates);
57 const std::vector<Scalar>& production_rates(const std::string& gname) const;
58 const std::vector<Scalar>& network_leaf_node_injection_rates(const std::string& gname) const;
59 const std::vector<Scalar>& network_leaf_node_production_rates(const std::string& gname) const;
60
61 void update_well_group_thp(const std::string& gname, const double& thp);
62 Scalar well_group_thp(const std::string& gname) const;
63 bool is_autochoke_group(const std::string& gname) const;
64
65 bool has_production_reduction_rates(const std::string& gname) const;
66 void update_production_reduction_rates(const std::string& gname,
67 const std::vector<Scalar>& rates);
68 const std::vector<Scalar>& production_reduction_rates(const std::string& gname) const;
69
70 void update_prev_production_rates(const std::string& gname, const std::vector<Scalar>& rates);
71 const std::vector<Scalar>& prev_production_rates(const std::string& gname) const;
72
73 bool has_injection_reduction_rates(const std::string& gname) const;
74 void update_injection_reduction_rates(const std::string& gname,
75 const std::vector<Scalar>& rates);
76 const std::vector<Scalar>& injection_reduction_rates(const std::string& gname) const;
77
78 bool has_injection_reservoir_rates(const std::string& gname) const;
79 void update_injection_reservoir_rates(const std::string& gname,
80 const std::vector<Scalar>& rates);
81 const std::vector<Scalar>& injection_reservoir_rates(const std::string& gname) const;
82
83 bool has_injection_surface_rates(const std::string& gname) const;
84 void update_injection_surface_rates(const std::string& gname,
85 const std::vector<Scalar>& rates);
86 const std::vector<Scalar>& injection_surface_rates(const std::string& gname) const;
87
88 void update_injection_rein_rates(const std::string& gname,
89 const std::vector<Scalar>& rates);
90 const std::vector<Scalar>& injection_rein_rates(const std::string& gname) const;
91
92 void update_injection_vrep_rate(const std::string& gname, Scalar rate);
93 Scalar injection_vrep_rate(const std::string& gname) const;
94
95 void update_grat_sales_target(const std::string& gname, Scalar target);
96 Scalar grat_sales_target(const std::string& gname) const;
97 bool has_grat_sales_target(const std::string& gname) const;
98
99 void update_gpmaint_target(const std::string& gname, Scalar target);
100 Scalar gpmaint_target(const std::string& gname) const;
101 bool has_gpmaint_target(const std::string& gname) const;
102
103 bool has_field_or_none_control(const std::string& gname) const;
104 bool has_field_or_none_control(const std::string& gname, Phase injection_phase) const;
105 bool has_production_control(const std::string& gname) const;
106 void production_control(const std::string& gname, Group::ProductionCMode cmode);
107 Group::ProductionCMode production_control(const std::string& gname) const;
108 const std::map<std::string, Group::ProductionCMode>& get_production_controls() const;
109
110 bool has_injection_control(const std::string& gname, Phase phase) const;
111 void injection_control(const std::string& gname, Phase phase, Group::InjectionCMode cmode);
112 Group::InjectionCMode injection_control(const std::string& gname, Phase phase) const;
113
114 void update_number_of_wells_under_group_control(const std::string& gname, int number);
115 int number_of_wells_under_group_control(const std::string& gname) const;
116
117 void update_number_of_wells_under_inj_group_control(const std::string& gname, Phase phase, int number);
118 int number_of_wells_under_inj_group_control(const std::string& gname, Phase phase) const;
119
120
121 void update_gconsump(const Schedule& schedule, const int report_step, const SummaryState& summary_state);
122 const std::pair<Scalar, Scalar>& gconsump_rates(const std::string& gname) const;
123
125 Scalar oil_rate;
126 Scalar gas_rate;
128
129 GroupPotential(Scalar oil = 0.0, Scalar gas = 0.0, Scalar water = 0.0)
130 : oil_rate(oil), gas_rate(gas), water_rate(water) {}
131 };
132 bool has_production_group_potential(const std::string& gname) const;
134 const std::string& gname, Scalar oil_rate, Scalar gas_rate, Scalar water_rate
135 );
136 const GroupPotential& get_production_group_potential(const std::string& gname) const;
137
138 std::size_t data_size() const;
139 std::size_t collect(Scalar* data) const;
140 std::size_t distribute(const Scalar* data);
141
142 GPMaint::State& gpmaint(const std::string& gname);
143
144 template<class Comm>
145 void communicate_rates(const Comm& comm)
146 {
147 // Note that injection_group_vrep_rates is handled separate from
148 // the forAllGroupData() function, since it contains single doubles,
149 // not vectors.
150
151 // Create a function that calls some function
152 // for all the individual data items to simplify
153 // the further code.
154 auto iterateContainer = [](auto& container, const auto& func) {
155 for (auto& x : container) {
156 func(x.second);
157 }
158 };
159
160
161 auto forAllGroupData = [&](auto& func) {
162 iterateContainer(m_production_rates, func);
163 iterateContainer(m_network_leaf_node_injection_rates, func);
164 iterateContainer(m_network_leaf_node_production_rates, func);
165 iterateContainer(prod_red_rates, func);
166 iterateContainer(inj_red_rates, func);
167 iterateContainer(inj_resv_rates, func);
168 iterateContainer(inj_rein_rates, func);
169 iterateContainer(inj_surface_rates, func);
170 };
171
172 // Compute the size of the data.
173 std::size_t sz = 0;
174 auto computeSize = [&sz](const auto& v) {
175 sz += v.size();
176 };
177 forAllGroupData(computeSize);
178 sz += this->inj_vrep_rate.size();
179
180 // Make a vector and collect all data into it.
181 std::vector<Scalar> data(sz);
182 std::size_t pos = 0;
183
184 // That the collect function mutates the vector v is an artifact for
185 // testing.
186 auto doCollect = [&data, &pos](auto& v) {
187 for (auto& x : v) {
188 data[pos++] = x;
189 x = -1;
190 }
191 };
192 forAllGroupData(doCollect);
193 for (const auto& x : this->inj_vrep_rate) {
194 data[pos++] = x.second;
195 }
196 if (pos != sz)
197 throw std::logic_error("Internal size mismatch when collecting groupData");
198
199 // Communicate it with a single sum() call.
200 comm.sum(data.data(), data.size());
201
202 // Distribute the summed vector to the data items.
203 pos = 0;
204 auto doDistribute = [&data, &pos](auto& v) {
205 std::copy_n(data.begin() + pos, v.size(), v.begin());
206 pos += v.size();
207 };
208 forAllGroupData(doDistribute);
209 for (auto& x : this->inj_vrep_rate) {
210 x.second = data[pos++];
211 }
212 if (pos != sz)
213 throw std::logic_error("Internal size mismatch when distributing groupData");
214 }
215
216 template<class Serializer>
217 void serializeOp(Serializer& serializer)
218 {
219 serializer(num_phases);
220 serializer(m_production_rates);
221 serializer(m_network_leaf_node_injection_rates);
222 serializer(m_network_leaf_node_production_rates);
223 serializer(production_controls);
224 serializer(m_prev_production_rates);
225 serializer(group_thp);
226 serializer(prod_red_rates);
227 serializer(inj_red_rates);
228 serializer(inj_surface_rates);
229 serializer(inj_resv_rates);
230 serializer(inj_rein_rates);
231 serializer(inj_vrep_rate);
232 serializer(m_grat_sales_target);
233 serializer(m_gpmaint_target);
234 serializer(injection_controls);
235 serializer(gpmaint_state);
236 serializer(m_gconsump_rates);
237 serializer(m_number_of_wells_under_group_control);
238 serializer(m_number_of_wells_under_inj_group_control);
239 }
240
241private:
242 std::size_t num_phases{};
243 std::map<std::string, std::vector<Scalar>> m_production_rates;
244 std::map<std::string, std::vector<Scalar>> m_network_leaf_node_injection_rates;
245 std::map<std::string, std::vector<Scalar>> m_network_leaf_node_production_rates;
246 std::map<std::string, Group::ProductionCMode> production_controls;
247 std::map<std::string, std::vector<Scalar>> m_prev_production_rates;
248 std::map<std::string, std::vector<Scalar>> prod_red_rates;
249 std::map<std::string, std::vector<Scalar>> inj_red_rates;
250 std::map<std::string, std::vector<Scalar>> inj_surface_rates;
251 std::map<std::string, std::vector<Scalar>> inj_resv_rates;
252 std::map<std::string, std::vector<Scalar>> inj_rein_rates;
253 std::map<std::string, Scalar> inj_vrep_rate;
254 std::map<std::string, Scalar> m_grat_sales_target;
255 std::map<std::string, Scalar> m_gpmaint_target;
256 std::map<std::string, Scalar> group_thp;
257 std::map<std::string, GroupPotential> production_group_potentials;
258 std::map<std::string, int> m_number_of_wells_under_group_control;
259 std::map<std::pair<Phase, std::string>, int> m_number_of_wells_under_inj_group_control;
260
261
262 std::map<std::pair<Phase, std::string>, Group::InjectionCMode> injection_controls;
263 WellContainer<GPMaint::State> gpmaint_state;
264 std::map<std::string, std::pair<Scalar, Scalar>> m_gconsump_rates; // Pair with {consumption_rate, import_rate} for each group
265 static constexpr std::pair<Scalar, Scalar> zero_pair = {0.0, 0.0};
266};
267
268}
269
270#endif
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:325
Definition: GroupState.hpp:41
const std::vector< Scalar > & injection_reservoir_rates(const std::string &gname) const
bool has_injection_control(const std::string &gname, Phase phase) const
const std::vector< Scalar > & network_leaf_node_injection_rates(const std::string &gname) const
Scalar injection_vrep_rate(const std::string &gname) const
void update_production_reduction_rates(const std::string &gname, const std::vector< Scalar > &rates)
const std::map< std::string, Group::ProductionCMode > & get_production_controls() const
bool has_production_control(const std::string &gname) const
bool has_production_rates(const std::string &gname) const
void update_injection_rein_rates(const std::string &gname, const std::vector< Scalar > &rates)
void update_well_group_thp(const std::string &gname, const double &thp)
void serializeOp(Serializer &serializer)
Definition: GroupState.hpp:217
void update_gconsump(const Schedule &schedule, const int report_step, const SummaryState &summary_state)
GroupState()=default
const std::vector< Scalar > & injection_rein_rates(const std::string &gname) const
bool has_injection_reduction_rates(const std::string &gname) const
const std::pair< Scalar, Scalar > & gconsump_rates(const std::string &gname) const
const std::vector< Scalar > & injection_surface_rates(const std::string &gname) const
std::size_t distribute(const Scalar *data)
Scalar well_group_thp(const std::string &gname) const
const std::vector< Scalar > & production_rates(const std::string &gname) const
void injection_control(const std::string &gname, Phase phase, Group::InjectionCMode cmode)
GPMaint::State & gpmaint(const std::string &gname)
static GroupState serializationTestObject()
void update_injection_vrep_rate(const std::string &gname, Scalar rate)
void production_control(const std::string &gname, Group::ProductionCMode cmode)
int number_of_wells_under_inj_group_control(const std::string &gname, Phase phase) const
const GroupPotential & get_production_group_potential(const std::string &gname) const
void update_gpmaint_target(const std::string &gname, Scalar target)
std::size_t collect(Scalar *data) const
const std::vector< Scalar > & production_reduction_rates(const std::string &gname) const
void update_injection_reservoir_rates(const std::string &gname, const std::vector< Scalar > &rates)
bool has_field_or_none_control(const std::string &gname) const
void update_injection_surface_rates(const std::string &gname, const std::vector< Scalar > &rates)
bool has_production_group_potential(const std::string &gname) const
void update_prev_production_rates(const std::string &gname, const std::vector< Scalar > &rates)
const std::vector< Scalar > & network_leaf_node_production_rates(const std::string &gname) const
Scalar grat_sales_target(const std::string &gname) const
void update_network_leaf_node_injection_rates(const std::string &gname, const std::vector< Scalar > &rates)
int number_of_wells_under_group_control(const std::string &gname) const
bool has_field_or_none_control(const std::string &gname, Phase injection_phase) const
bool has_production_reduction_rates(const std::string &gname) const
Scalar gpmaint_target(const std::string &gname) const
bool operator==(const GroupState &other) const
void update_production_rates(const std::string &gname, const std::vector< Scalar > &rates)
void communicate_rates(const Comm &comm)
Definition: GroupState.hpp:145
void update_injection_reduction_rates(const std::string &gname, const std::vector< Scalar > &rates)
void update_group_production_potential(const std::string &gname, Scalar oil_rate, Scalar gas_rate, Scalar water_rate)
GroupState(std::size_t num_phases)
bool is_autochoke_group(const std::string &gname) const
void update_number_of_wells_under_inj_group_control(const std::string &gname, Phase phase, int number)
bool has_gpmaint_target(const std::string &gname) const
Group::InjectionCMode injection_control(const std::string &gname, Phase phase) const
void update_number_of_wells_under_group_control(const std::string &gname, int number)
Group::ProductionCMode production_control(const std::string &gname) const
const std::vector< Scalar > & prev_production_rates(const std::string &gname) const
void update_network_leaf_node_production_rates(const std::string &gname, const std::vector< Scalar > &rates)
void update_grat_sales_target(const std::string &gname, Scalar target)
const std::vector< Scalar > & injection_reduction_rates(const std::string &gname) const
bool has_injection_reservoir_rates(const std::string &gname) const
std::size_t data_size() const
bool has_injection_surface_rates(const std::string &gname) const
bool has_grat_sales_target(const std::string &gname) const
Phase
Phase indices for reservoir coupling, we currently only support black-oil phases (oil,...
Definition: ReservoirCoupling.hpp:159
Definition: blackoilbioeffectsmodules.hh:45
Definition: GroupState.hpp:124
Scalar oil_rate
Definition: GroupState.hpp:125
Scalar gas_rate
Definition: GroupState.hpp:126
Scalar water_rate
Definition: GroupState.hpp:127
GroupPotential(Scalar oil=0.0, Scalar gas=0.0, Scalar water=0.0)
Definition: GroupState.hpp:129