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_production_rates(const std::string& gname,
54 const std::vector<Scalar>& rates);
55 const std::vector<Scalar>& production_rates(const std::string& gname) const;
56 const std::vector<Scalar>& network_leaf_node_production_rates(const std::string& gname) const;
57
58 void update_well_group_thp(const std::string& gname, const double& thp);
59 Scalar well_group_thp(const std::string& gname) const;
60 bool is_autochoke_group(const std::string& gname) const;
61
62 bool has_production_reduction_rates(const std::string& gname) const;
63 void update_production_reduction_rates(const std::string& gname,
64 const std::vector<Scalar>& rates);
65 const std::vector<Scalar>& production_reduction_rates(const std::string& gname) const;
66
67 bool has_injection_reduction_rates(const std::string& gname) const;
68 void update_injection_reduction_rates(const std::string& gname,
69 const std::vector<Scalar>& rates);
70 const std::vector<Scalar>& injection_reduction_rates(const std::string& gname) const;
71
72 bool has_injection_reservoir_rates(const std::string& gname) const;
73 void update_injection_reservoir_rates(const std::string& gname,
74 const std::vector<Scalar>& rates);
75 const std::vector<Scalar>& injection_reservoir_rates(const std::string& gname) const;
76
77 bool has_injection_surface_rates(const std::string& gname) const;
78 void update_injection_surface_rates(const std::string& gname,
79 const std::vector<Scalar>& rates);
80 const std::vector<Scalar>& injection_surface_rates(const std::string& gname) const;
81
82 void update_injection_rein_rates(const std::string& gname,
83 const std::vector<Scalar>& rates);
84 const std::vector<Scalar>& injection_rein_rates(const std::string& gname) const;
85
86 void update_injection_vrep_rate(const std::string& gname, Scalar rate);
87 Scalar injection_vrep_rate(const std::string& gname) const;
88
89 void update_grat_sales_target(const std::string& gname, Scalar target);
90 Scalar grat_sales_target(const std::string& gname) const;
91 bool has_grat_sales_target(const std::string& gname) const;
92
93 void update_gpmaint_target(const std::string& gname, Scalar target);
94 Scalar gpmaint_target(const std::string& gname) const;
95 bool has_gpmaint_target(const std::string& gname) const;
96
97 bool has_field_or_none_control(const std::string& gname) const;
98 bool has_field_or_none_control(const std::string& gname, Phase injection_phase) const;
99 bool has_production_control(const std::string& gname) const;
100 void production_control(const std::string& gname, Group::ProductionCMode cmode);
101 Group::ProductionCMode production_control(const std::string& gname) const;
102 const std::map<std::string, Group::ProductionCMode>& get_production_controls() const;
103
104 bool has_injection_control(const std::string& gname, Phase phase) const;
105 void injection_control(const std::string& gname, Phase phase, Group::InjectionCMode cmode);
106 Group::InjectionCMode injection_control(const std::string& gname, Phase phase) const;
107
108 void update_number_of_wells_under_group_control(const std::string& gname, int number);
109 int number_of_wells_under_group_control(const std::string& gname) const;
110
111 void update_number_of_wells_under_inj_group_control(const std::string& gname, Phase phase, int number);
112 int number_of_wells_under_inj_group_control(const std::string& gname, Phase phase) const;
113
114
115 void update_gconsump(const Schedule& schedule, const int report_step, const SummaryState& summary_state);
116 const std::pair<Scalar, Scalar>& gconsump_rates(const std::string& gname) const;
117
119 Scalar oil_rate;
120 Scalar gas_rate;
122
123 GroupPotential(Scalar oil = 0.0, Scalar gas = 0.0, Scalar water = 0.0)
124 : oil_rate(oil), gas_rate(gas), water_rate(water) {}
125 };
126 bool has_production_group_potential(const std::string& gname) const;
128 const std::string& gname, Scalar oil_rate, Scalar gas_rate, Scalar water_rate
129 );
130 const GroupPotential& get_production_group_potential(const std::string& gname) const;
131
132 std::size_t data_size() const;
133 std::size_t collect(Scalar* data) const;
134 std::size_t distribute(const Scalar* data);
135
136 GPMaint::State& gpmaint(const std::string& gname);
137
138 template<class Comm>
139 void communicate_rates(const Comm& comm)
140 {
141 // Note that injection_group_vrep_rates is handled separate from
142 // the forAllGroupData() function, since it contains single doubles,
143 // not vectors.
144
145 // Create a function that calls some function
146 // for all the individual data items to simplify
147 // the further code.
148 auto iterateContainer = [](auto& container, const auto& func) {
149 for (auto& x : container) {
150 func(x.second);
151 }
152 };
153
154
155 auto forAllGroupData = [&](auto& func) {
156 iterateContainer(m_production_rates, func);
157 iterateContainer(m_network_leaf_node_production_rates, func);
158 iterateContainer(prod_red_rates, func);
159 iterateContainer(inj_red_rates, func);
160 iterateContainer(inj_resv_rates, func);
161 iterateContainer(inj_rein_rates, func);
162 iterateContainer(inj_surface_rates, func);
163 };
164
165 // Compute the size of the data.
166 std::size_t sz = 0;
167 auto computeSize = [&sz](const auto& v) {
168 sz += v.size();
169 };
170 forAllGroupData(computeSize);
171 sz += this->inj_vrep_rate.size();
172
173 // Make a vector and collect all data into it.
174 std::vector<Scalar> data(sz);
175 std::size_t pos = 0;
176
177 // That the collect function mutates the vector v is an artifact for
178 // testing.
179 auto doCollect = [&data, &pos](auto& v) {
180 for (auto& x : v) {
181 data[pos++] = x;
182 x = -1;
183 }
184 };
185 forAllGroupData(doCollect);
186 for (const auto& x : this->inj_vrep_rate) {
187 data[pos++] = x.second;
188 }
189 if (pos != sz)
190 throw std::logic_error("Internal size mismatch when collecting groupData");
191
192 // Communicate it with a single sum() call.
193 comm.sum(data.data(), data.size());
194
195 // Distribute the summed vector to the data items.
196 pos = 0;
197 auto doDistribute = [&data, &pos](auto& v) {
198 std::copy_n(data.begin() + pos, v.size(), v.begin());
199 pos += v.size();
200 };
201 forAllGroupData(doDistribute);
202 for (auto& x : this->inj_vrep_rate) {
203 x.second = data[pos++];
204 }
205 if (pos != sz)
206 throw std::logic_error("Internal size mismatch when distributing groupData");
207 }
208
209 template<class Serializer>
210 void serializeOp(Serializer& serializer)
211 {
212 serializer(num_phases);
213 serializer(m_production_rates);
214 serializer(m_network_leaf_node_production_rates);
215 serializer(production_controls);
216 serializer(group_thp);
217 serializer(prod_red_rates);
218 serializer(inj_red_rates);
219 serializer(inj_surface_rates);
220 serializer(inj_resv_rates);
221 serializer(inj_rein_rates);
222 serializer(inj_vrep_rate);
223 serializer(m_grat_sales_target);
224 serializer(m_gpmaint_target);
225 serializer(injection_controls);
226 serializer(gpmaint_state);
227 serializer(m_gconsump_rates);
228 serializer(m_number_of_wells_under_group_control);
229 serializer(m_number_of_wells_under_inj_group_control);
230 }
231
232private:
233 std::size_t num_phases{};
234 std::map<std::string, std::vector<Scalar>> m_production_rates;
235 std::map<std::string, std::vector<Scalar>> m_network_leaf_node_production_rates;
236 std::map<std::string, Group::ProductionCMode> production_controls;
237 std::map<std::string, std::vector<Scalar>> prod_red_rates;
238 std::map<std::string, std::vector<Scalar>> inj_red_rates;
239 std::map<std::string, std::vector<Scalar>> inj_surface_rates;
240 std::map<std::string, std::vector<Scalar>> inj_resv_rates;
241 std::map<std::string, std::vector<Scalar>> inj_rein_rates;
242 std::map<std::string, Scalar> inj_vrep_rate;
243 std::map<std::string, Scalar> m_grat_sales_target;
244 std::map<std::string, Scalar> m_gpmaint_target;
245 std::map<std::string, Scalar> group_thp;
246 std::map<std::string, GroupPotential> production_group_potentials;
247 std::map<std::string, int> m_number_of_wells_under_group_control;
248 std::map<std::pair<Phase, std::string>, int> m_number_of_wells_under_inj_group_control;
249
250
251 std::map<std::pair<Phase, std::string>, Group::InjectionCMode> injection_controls;
252 WellContainer<GPMaint::State> gpmaint_state;
253 std::map<std::string, std::pair<Scalar, Scalar>> m_gconsump_rates; // Pair with {consumption_rate, import_rate} for each group
254 static constexpr std::pair<Scalar, Scalar> zero_pair = {0.0, 0.0};
255};
256
257}
258
259#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
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:210
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
const std::vector< Scalar > & network_leaf_node_production_rates(const std::string &gname) const
Scalar grat_sales_target(const std::string &gname) const
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:139
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
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:156
Definition: blackoilbioeffectsmodules.hh:43
Definition: GroupState.hpp:118
Scalar oil_rate
Definition: GroupState.hpp:119
Scalar gas_rate
Definition: GroupState.hpp:120
Scalar water_rate
Definition: GroupState.hpp:121
GroupPotential(Scalar oil=0.0, Scalar gas=0.0, Scalar water=0.0)
Definition: GroupState.hpp:123