BlackoilWellModelNetworkGeneric.hpp
Go to the documentation of this file.
1/*
2 Copyright 2016 SINTEF ICT, Applied Mathematics.
3 Copyright 2016 - 2017 Statoil ASA.
4 Copyright 2017 Dr. Blatt - HPC-Simulation-Software & Services
5 Copyright 2016 - 2018 IRIS AS
6
7 This file is part of the Open Porous Media project (OPM).
8
9 OPM is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OPM is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OPM. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#ifndef OPM_BLACKOILWELLMODEL_NETWORK_GENERIC_HEADER_INCLUDED
24#define OPM_BLACKOILWELLMODEL_NETWORK_GENERIC_HEADER_INCLUDED
25
26#include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
27#include <opm/input/eclipse/Schedule/ScheduleTypes.hpp>
28
29#include <opm/output/data/Groups.hpp>
30
33
34#include <array>
35#include <map>
36#include <optional>
37#include <set>
38#include <string>
39
40namespace Opm {
41 class Schedule;
42 class UnitSystem;
43 template<class Scalar, class IndexTraits> class BlackoilWellModelGeneric;
44 template<typename Scalar, typename IndexTraits> class WellInterfaceGeneric;
45 template<typename Scalar> class VFPInjProperties;
46 template<typename Scalar> class VFPProdProperties;
47}
48
49namespace Opm {
50
51namespace details {
52
53 enum class NetworkDomain : std::size_t {
54 Production = 0,
57 Count
58 };
59
60 constexpr std::size_t domainIndex(const NetworkDomain domain)
61 {
62 return static_cast<std::size_t>(domain);
63 }
64
67 std::reference_wrapper<const Network::ExtNetwork> network;
68 };
69
72 template<class Well>
73 std::optional<NetworkDomain> domainForWell(const Well& well)
74 {
75 if (well.isProducer()) {
77 }
78 if (well.isInjector()) {
79 if (well.wellEcl().injectorType() == InjectorType::GAS) {
81 }
82 if (well.wellEcl().injectorType() == InjectorType::WATER) {
84 }
85 }
86 return std::nullopt;
87 }
88
90 bool anyNetworkActive(const Schedule& schedule, const int timeStepIdx);
91
93 std::vector<NetworkDescriptor>
94 activeNetworks(const Schedule& schedule, const int timeStepIdx);
95
98 std::vector<NetworkDescriptor>
99 networks(const Schedule& schedule, const int timeStepIdx);
100
101} // namespace details
102
103
105template<typename Scalar, typename IndexTraits>
107{
108public:
110
112
114 bool active() const
115 { return active_; }
116
117 const std::map<std::string, Scalar>&
118 nodePressures() const { return node_pressures_; }
119
120 // do not use, only needed for serialization testing
121 void setNodePressures(const std::map<std::string, Scalar>& values)
122 { node_pressures_ = values; }
123
124 void setFromRestart(const std::optional<std::map<std::string, double>>& restart_pressures);
125
127 void initialize(const int report_step);
128
131
133 void updateActiveState(const int report_step);
134
138 bool needPreStepRebalance(const int report_step) const;
139
142 bool shouldBalance(const int reportStepIndex) const;
144 bool willBalanceOnNextIteration(const int reportStepIndex) const;
145
146 Scalar updatePressures(const int reportStepIdx,
147 const Scalar damping_factor,
148 const Scalar update_upper_bound);
149
150 void assignNodeAndBranchValues(std::map<std::string, data::NodeData>& nodevalues,
151 std::map<std::string, data::BranchData>& branchvalues,
152 std::map<std::string, data::BranchData>& converged_branchvalues,
153 const int reportStepIdx) const;
154
156 {
161 }
162
164 {
169 }
170
171 template<class Serializer>
172 void serializeOp(Serializer& serializer)
173 {
174 serializer(node_pressures_);
175 serializer(last_valid_node_pressures_);
176 serializer(branch_data_);
177 serializer(last_valid_branch_data_);
178 serializer(domain_node_pressures_);
180 serializer(domain_branch_data_);
182 serializer(well_group_thp_calc_);
183 }
184
186
187protected:
191 const Scalar limit);
192
195 {
196 std::map<std::string, Scalar> node_pressures;
197 std::map<std::string, data::BranchData> branch_data;
198 // Nodes (and their descendants) whose VFP lookup has no solution; their
199 // node_pressures entries are placeholders and must not be used.
200 std::set<std::string> invalid_nodes;
201 };
202
204 computePressures(const Network::ExtNetwork& network,
205 const VFPProdProperties<Scalar>& vfp_prod_props,
206 const UnitSystem& unit_system,
207 const int reportStepIdx,
208 const Parallel::Communication& comm) const;
209
211 computePressures(const Network::ExtNetwork& network,
212 const VFPInjProperties<Scalar>& vfp_inj_props,
213 const UnitSystem& unit_system,
214 const int reportStepIdx,
215 const Parallel::Communication& comm) const;
216
217 void updateActiveStateImpl(const Network::ExtNetwork& network);
218
220 {
222 }
223
224 const std::map<std::string, Scalar>& nodePressures(const details::NetworkDomain domain) const
225 {
227 }
228
229 std::map<std::string, Scalar>& nodePressures(const details::NetworkDomain domain)
230 {
232 }
233
234 const std::map<std::string, data::BranchData>& branchData(const details::NetworkDomain domain) const
235 {
237 }
238
239 std::map<std::string, data::BranchData>& branchData(const details::NetworkDomain domain)
240 {
242 }
243
244 const std::set<std::string>& invalidNodes(const details::NetworkDomain domain) const
245 {
247 }
248
249 std::set<std::string>& invalidNodes(const details::NetworkDomain domain)
250 {
252 }
253
255 {
258 }
259
261 {
264 }
265
266 bool active_{false};
268
269 // Network pressures for output and initialization
270 std::map<std::string, Scalar> node_pressures_;
271 // Network branch pressure drops and flow rates for output (outlet branch for production network, inlet branch for injection network)
272 std::map<std::string, data::BranchData> branch_data_;
273 // Domain-scoped pressure state to avoid collisions between production and injection networks.
275 std::array<std::map<std::string, data::BranchData>, details::domainIndex(details::NetworkDomain::Count)> domain_branch_data_;
276 // Nodes without a valid VFP solution in the last evaluation (per domain); not serialized,
277 // recomputed on every updatePressures().
280 // Valid network pressures for output and initialization for safe restart after failed iterations
281 std::map<std::string, Scalar> last_valid_node_pressures_;
282 // Valid network branch pressure drops and flow rates for output (outlet branch for production network, inlet branch for injection network) for safe restart after failed iterations
283 std::map<std::string, data::BranchData> last_valid_branch_data_;
285 std::array<std::map<std::string, data::BranchData>, details::domainIndex(details::NetworkDomain::Count)> last_valid_domain_branch_data_;
286 // Cached auto-choke THP values used when balancing network groups.
287 std::map<std::string, Scalar> well_group_thp_calc_;
288};
289
290} // namespace Opm
291
292#endif
Class for handling the blackoil well network model.
Definition: BlackoilWellModelNetworkGeneric.hpp:107
std::map< std::string, Scalar > node_pressures_
Definition: BlackoilWellModelNetworkGeneric.hpp:270
bool shouldBalance(const int reportStepIndex) const
virtual ~BlackoilWellModelNetworkGeneric()=default
std::array< std::map< std::string, data::BranchData >, details::domainIndex(details::NetworkDomain::Count)> last_valid_domain_branch_data_
Definition: BlackoilWellModelNetworkGeneric.hpp:285
bool willBalanceOnNextIteration(const int reportStepIndex) const
Checks if we will perform a network re-balance on the next Newton iteration.
void commitState()
Definition: BlackoilWellModelNetworkGeneric.hpp:155
void assignNodeAndBranchValues(std::map< std::string, data::NodeData > &nodevalues, std::map< std::string, data::BranchData > &branchvalues, std::map< std::string, data::BranchData > &converged_branchvalues, const int reportStepIdx) const
bool active_
Definition: BlackoilWellModelNetworkGeneric.hpp:266
void setNodePressures(const std::map< std::string, Scalar > &values)
Definition: BlackoilWellModelNetworkGeneric.hpp:121
void initialize(const int report_step)
Initialize wells according to network configuration.
int invalid_nodes_report_step_
Definition: BlackoilWellModelNetworkGeneric.hpp:279
std::set< std::string > & invalidNodes(const details::NetworkDomain domain)
Definition: BlackoilWellModelNetworkGeneric.hpp:249
BlackoilWellModelGeneric< Scalar, IndexTraits > & well_model_
Definition: BlackoilWellModelNetworkGeneric.hpp:267
Scalar updatePressures(const int reportStepIdx, const Scalar damping_factor, const Scalar update_upper_bound)
void syncProductionDomainState_()
Definition: BlackoilWellModelNetworkGeneric.hpp:260
const std::map< std::string, data::BranchData > & branchData(const details::NetworkDomain domain) const
Definition: BlackoilWellModelNetworkGeneric.hpp:234
std::map< std::string, data::BranchData > branch_data_
Definition: BlackoilWellModelNetworkGeneric.hpp:272
std::array< std::map< std::string, data::BranchData >, details::domainIndex(details::NetworkDomain::Count)> domain_branch_data_
Definition: BlackoilWellModelNetworkGeneric.hpp:275
void updateActiveStateImpl(const Network::ExtNetwork &network)
std::map< std::string, Scalar > last_valid_node_pressures_
Definition: BlackoilWellModelNetworkGeneric.hpp:281
const std::map< std::string, Scalar > & nodePressures(const details::NetworkDomain domain) const
Definition: BlackoilWellModelNetworkGeneric.hpp:224
bool needPreStepRebalance(const int report_step) const
NetworkPressures computePressures(const Network::ExtNetwork &network, const VFPInjProperties< Scalar > &vfp_inj_props, const UnitSystem &unit_system, const int reportStepIdx, const Parallel::Communication &comm) const
bool operator==(const BlackoilWellModelNetworkGeneric< Scalar, IndexTraits > &rhs) const
void updateActiveState(const int report_step)
Checks if network is active (at least one network well on prediction).
std::array< std::map< std::string, Scalar >, details::domainIndex(details::NetworkDomain::Count)> last_valid_domain_node_pressures_
Definition: BlackoilWellModelNetworkGeneric.hpp:284
BlackoilWellModelNetworkGeneric(BlackoilWellModelGeneric< Scalar, IndexTraits > &well_model)
std::map< std::string, data::BranchData > last_valid_branch_data_
Definition: BlackoilWellModelNetworkGeneric.hpp:283
std::map< std::string, data::BranchData > & branchData(const details::NetworkDomain domain)
Definition: BlackoilWellModelNetworkGeneric.hpp:239
static constexpr details::NetworkDomain productionNetworkDomain()
Definition: BlackoilWellModelNetworkGeneric.hpp:219
const std::set< std::string > & invalidNodes(const details::NetworkDomain domain) const
Definition: BlackoilWellModelNetworkGeneric.hpp:244
std::map< std::string, Scalar > well_group_thp_calc_
Definition: BlackoilWellModelNetworkGeneric.hpp:287
void serializeOp(Serializer &serializer)
Definition: BlackoilWellModelNetworkGeneric.hpp:172
void syncLegacyProductionState_()
Definition: BlackoilWellModelNetworkGeneric.hpp:254
void imposeWellThpLimit(WellInterfaceGeneric< Scalar, IndexTraits > &well, const Scalar limit)
Apply a network THP limit and retain it across well reconstruction or network detachment.
bool active() const
return true if network is active (at least one network well in prediction mode)
Definition: BlackoilWellModelNetworkGeneric.hpp:114
void setFromRestart(const std::optional< std::map< std::string, double > > &restart_pressures)
std::array< std::map< std::string, Scalar >, details::domainIndex(details::NetworkDomain::Count)> domain_node_pressures_
Definition: BlackoilWellModelNetworkGeneric.hpp:274
void initializeWell(WellInterfaceGeneric< Scalar, IndexTraits > &well)
Initialize a single well according to network configuration.
std::array< std::set< std::string >, details::domainIndex(details::NetworkDomain::Count)> domain_invalid_nodes_
Definition: BlackoilWellModelNetworkGeneric.hpp:278
std::map< std::string, Scalar > & nodePressures(const details::NetworkDomain domain)
Definition: BlackoilWellModelNetworkGeneric.hpp:229
void resetState()
Definition: BlackoilWellModelNetworkGeneric.hpp:163
NetworkPressures computePressures(const Network::ExtNetwork &network, const VFPProdProperties< Scalar > &vfp_prod_props, const UnitSystem &unit_system, const int reportStepIdx, const Parallel::Communication &comm) const
const std::map< std::string, Scalar > & nodePressures() const
Definition: BlackoilWellModelNetworkGeneric.hpp:118
Definition: VFPInjProperties.hpp:34
Definition: VFPProdProperties.hpp:38
Definition: WellInterfaceGeneric.hpp:59
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
std::optional< NetworkDomain > domainForWell(const Well &well)
Definition: BlackoilWellModelNetworkGeneric.hpp:73
std::vector< NetworkDescriptor > activeNetworks(const Schedule &schedule, const int timeStepIdx)
Helper to get all active networks (production, gas injection, water injection) at a given time step.
constexpr std::size_t domainIndex(const NetworkDomain domain)
Definition: BlackoilWellModelNetworkGeneric.hpp:60
NetworkDomain
Definition: BlackoilWellModelNetworkGeneric.hpp:53
std::vector< NetworkDescriptor > networks(const Schedule &schedule, const int timeStepIdx)
bool anyNetworkActive(const Schedule &schedule, const int timeStepIdx)
Helper to check if any network (production, gas injection, water injection) is active at a given time...
Definition: blackoilbioeffectsmodules.hh:45
Result of one network pressure evaluation for one network (domain).
Definition: BlackoilWellModelNetworkGeneric.hpp:195
std::map< std::string, data::BranchData > branch_data
Definition: BlackoilWellModelNetworkGeneric.hpp:197
std::set< std::string > invalid_nodes
Definition: BlackoilWellModelNetworkGeneric.hpp:200
std::map< std::string, Scalar > node_pressures
Definition: BlackoilWellModelNetworkGeneric.hpp:196
Definition: BlackoilWellModelNetworkGeneric.hpp:65
NetworkDomain domain
Definition: BlackoilWellModelNetworkGeneric.hpp:66
std::reference_wrapper< const Network::ExtNetwork > network
Definition: BlackoilWellModelNetworkGeneric.hpp:67