My Project
Loading...
Searching...
No Matches
GroupState.hpp
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
28#include <opm/simulators/wells/WellContainer.hpp>
29
30#include <opm/simulators/utils/BlackoilPhases.hpp>
31
32#include <map>
33#include <vector>
34#include <utility>
35
36namespace Opm {
37
38 class GConSump;
39 class Schedule;
40 class SummaryState;
41
42template<class Scalar>
44public:
45 GroupState() = default;
46 explicit GroupState(std::size_t num_phases);
47
48 static GroupState serializationTestObject();
49
50 bool operator==(const GroupState& other) const;
51
52 bool has_production_rates(const std::string& gname) const;
53 void update_production_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_production_rates(const std::string& gname) const;
59
60 void update_well_group_thp(const std::string& gname, const double& thp);
61 Scalar well_group_thp(const std::string& gname) const;
62 bool is_autochoke_group(const std::string& gname) const;
63
64 bool has_production_reduction_rates(const std::string& gname) const;
65 void update_production_reduction_rates(const std::string& gname,
66 const std::vector<Scalar>& rates);
67 const std::vector<Scalar>& production_reduction_rates(const std::string& gname) const;
68
69 bool has_injection_reduction_rates(const std::string& gname) const;
70 void update_injection_reduction_rates(const std::string& gname,
71 const std::vector<Scalar>& rates);
72 const std::vector<Scalar>& injection_reduction_rates(const std::string& gname) const;
73
74 bool has_injection_reservoir_rates(const std::string& gname) const;
75 void update_injection_reservoir_rates(const std::string& gname,
76 const std::vector<Scalar>& rates);
77 const std::vector<Scalar>& injection_reservoir_rates(const std::string& gname) const;
78
79 bool has_injection_surface_rates(const std::string& gname) const;
80 void update_injection_surface_rates(const std::string& gname,
81 const std::vector<Scalar>& rates);
82 const std::vector<Scalar>& injection_surface_rates(const std::string& gname) const;
83
84 void update_injection_rein_rates(const std::string& gname,
85 const std::vector<Scalar>& rates);
86 const std::vector<Scalar>& injection_rein_rates(const std::string& gname) const;
87
88 void update_injection_vrep_rate(const std::string& gname, Scalar rate);
89 Scalar injection_vrep_rate(const std::string& gname) const;
90
91 void update_grat_sales_target(const std::string& gname, Scalar target);
92 Scalar grat_sales_target(const std::string& gname) const;
93 bool has_grat_sales_target(const std::string& gname) const;
94
95 void update_gpmaint_target(const std::string& gname, Scalar target);
96 Scalar gpmaint_target(const std::string& gname) const;
97 bool has_gpmaint_target(const std::string& gname) const;
98
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
103 bool has_injection_control(const std::string& gname, Phase phase) const;
104 void injection_control(const std::string& gname, Phase phase, Group::InjectionCMode cmode);
105 Group::InjectionCMode injection_control(const std::string& gname, Phase phase) const;
106
107 void update_gconsump(const Schedule& schedule, const int report_step, const SummaryState& summary_state);
108 const std::pair<Scalar, Scalar>& gconsump_rates(const std::string& gname) const;
109
110
111 std::size_t data_size() const;
112 std::size_t collect(Scalar* data) const;
113 std::size_t distribute(const Scalar* data);
114
115 GPMaint::State& gpmaint(const std::string& gname);
116
117 template<class Comm>
118 void communicate_rates(const Comm& comm)
119 {
120 // Note that injection_group_vrep_rates is handled separate from
121 // the forAllGroupData() function, since it contains single doubles,
122 // not vectors.
123
124 // Create a function that calls some function
125 // for all the individual data items to simplify
126 // the further code.
127 auto iterateContainer = [](auto& container, const auto& func) {
128 for (auto& x : container) {
129 func(x.second);
130 }
131 };
132
133
134 auto forAllGroupData = [&](auto& func) {
135 iterateContainer(m_production_rates, func);
136 iterateContainer(m_network_leaf_node_production_rates, func);
137 iterateContainer(prod_red_rates, func);
138 iterateContainer(inj_red_rates, func);
139 iterateContainer(inj_resv_rates, func);
140 iterateContainer(inj_rein_rates, func);
141 iterateContainer(inj_surface_rates, func);
142 };
143
144 // Compute the size of the data.
145 std::size_t sz = 0;
146 auto computeSize = [&sz](const auto& v) {
147 sz += v.size();
148 };
150 sz += this->inj_vrep_rate.size();
151
152 // Make a vector and collect all data into it.
153 std::vector<Scalar> data(sz);
154 std::size_t pos = 0;
155
156 // That the collect function mutates the vector v is an artifact for
157 // testing.
158 auto collect = [&data, &pos](auto& v) {
159 for (auto& x : v) {
160 data[pos++] = x;
161 x = -1;
162 }
163 };
164 forAllGroupData(collect);
165 for (const auto& x : this->inj_vrep_rate) {
166 data[pos++] = x.second;
167 }
168 if (pos != sz)
169 throw std::logic_error("Internal size mismatch when collecting groupData");
170
171 // Communicate it with a single sum() call.
172 comm.sum(data.data(), data.size());
173
174 // Distribute the summed vector to the data items.
175 pos = 0;
176 auto distribute = [&data, &pos](auto& v) {
177 for (auto& x : v) {
178 x = data[pos++];
179 }
180 };
181 forAllGroupData(distribute);
182 for (auto& x : this->inj_vrep_rate) {
183 x.second = data[pos++];
184 }
185 if (pos != sz)
186 throw std::logic_error("Internal size mismatch when distributing groupData");
187 }
188
189 template<class Serializer>
190 void serializeOp(Serializer& serializer)
191 {
192 serializer(num_phases);
193 serializer(m_production_rates);
194 serializer(m_network_leaf_node_production_rates);
195 serializer(production_controls);
196 serializer(group_thp);
197 serializer(prod_red_rates);
198 serializer(inj_red_rates);
199 serializer(inj_surface_rates);
200 serializer(inj_resv_rates);
201 serializer(inj_rein_rates);
202 serializer(inj_vrep_rate);
203 serializer(m_grat_sales_target);
204 serializer(m_gpmaint_target);
205 serializer(injection_controls);
206 serializer(gpmaint_state);
207 serializer(m_gconsump_rates);
208 }
209
210private:
211 std::size_t num_phases{};
212 std::map<std::string, std::vector<Scalar>> m_production_rates;
213 std::map<std::string, std::vector<Scalar>> m_network_leaf_node_production_rates;
214 std::map<std::string, Group::ProductionCMode> production_controls;
215 std::map<std::string, std::vector<Scalar>> prod_red_rates;
216 std::map<std::string, std::vector<Scalar>> inj_red_rates;
217 std::map<std::string, std::vector<Scalar>> inj_surface_rates;
218 std::map<std::string, std::vector<Scalar>> inj_resv_rates;
219 std::map<std::string, std::vector<Scalar>> inj_rein_rates;
220 std::map<std::string, Scalar> inj_vrep_rate;
221 std::map<std::string, Scalar> m_grat_sales_target;
222 std::map<std::string, Scalar> m_gpmaint_target;
223 std::map<std::string, Scalar> group_thp;
224
225 std::map<std::pair<Phase, std::string>, Group::InjectionCMode> injection_controls;
226 WellContainer<GPMaint::State> gpmaint_state;
227 std::map<std::string, std::pair<Scalar, Scalar>> m_gconsump_rates; // Pair with {consumption_rate, import_rate} for each group
228 static constexpr std::pair<Scalar, Scalar> zero_pair = {0.0, 0.0};
229};
230
231}
232
233#endif
Definition GroupState.hpp:43
Definition WellContainer.hpp:46
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242