BlackoilWellModelRescoup.hpp
Go to the documentation of this file.
1/*
2 Copyright 2025 Equinor ASA
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_BLACKOILWELLMODEL_RESCOUP_HEADER_INCLUDED
21#define OPM_BLACKOILWELLMODEL_RESCOUP_HEADER_INCLUDED
22
24
25#ifdef RESERVOIR_COUPLING_ENABLED
26
28
30
31#include <optional>
32
33namespace Opm {
34 class DeferredLogger;
35 enum class Phase;
36 class Schedule;
37 class SummaryState;
38 template<class TypeTag> class BlackoilWellModel;
39 template<class Scalar, class IndexTraits> class GroupStateHelper;
40 template<class Scalar, class IndexTraits> class WellState;
41 template<class Scalar> class ReservoirCouplingMaster;
42 template<class Scalar> class ReservoirCouplingSlave;
43}
44
45namespace Opm::ReservoirCoupling { class CouplingInfo; }
46
47namespace Opm {
48
60template<typename TypeTag>
61class BlackoilWellModelRescoup {
62 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
63 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
64 using IndexTraits = typename FluidSystem::IndexTraitsType;
65 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
66 using ModelParameters = BlackoilModelParameters<Scalar>;
67 using WellInterfacePtr = typename BlackoilWellModel<TypeTag>::WellInterfacePtr;
68
69public:
70 explicit BlackoilWellModelRescoup(BlackoilWellModel<TypeTag>& well_model);
71
72 // === Mode queries and rescoup-facade forwarders ===
73
74 bool isReservoirCouplingMaster() const { return well_model_.isReservoirCouplingMaster(); }
75 bool isReservoirCouplingSlave() const { return well_model_.isReservoirCouplingSlave(); }
76
77 ReservoirCouplingMaster<Scalar>& reservoirCouplingMaster()
78 { return well_model_.reservoirCouplingMaster(); }
79 const ReservoirCouplingMaster<Scalar>& reservoirCouplingMaster() const
80 { return well_model_.reservoirCouplingMaster(); }
81
82 ReservoirCouplingSlave<Scalar>& reservoirCouplingSlave()
83 { return well_model_.reservoirCouplingSlave(); }
84 const ReservoirCouplingSlave<Scalar>& reservoirCouplingSlave() const
85 { return well_model_.reservoirCouplingSlave(); }
86
87 // === Common-state accessor forwarders ===
88
89 GroupStateHelper<Scalar, IndexTraits>& groupStateHelper()
90 { return well_model_.groupStateHelper(); }
91 const GroupStateHelper<Scalar, IndexTraits>& groupStateHelper() const
92 { return well_model_.groupStateHelper(); }
93
94 WellState<Scalar, IndexTraits>& wellState()
95 { return well_model_.wellState(); }
96 const WellState<Scalar, IndexTraits>& wellState() const
97 { return well_model_.wellState(); }
98
99 const Schedule& schedule() const { return well_model_.schedule(); }
100
101 std::vector<WellInterfacePtr>& wellContainer()
102 { return well_model_.wellContainer(); }
103
104 // === Rescoup flow methods ===
105
111 void evalGroupAndFieldUDQs();
112
119 bool lastSentMasterGroupNodePressuresIsFinal() const
120 { return last_sent_master_group_node_pressures_is_final_; }
121
131 bool masterNetworkHasMasterGroupLeaves() const;
132
138 bool masterIsInCoupledNetworkIteration() const;
139
147 void receiveCoupledNetworkActiveStatus();
148
157 void receiveGroupConstraintsFromMaster();
158
162 void receiveMasterGroupNodePressuresFromMaster();
163
171 void receiveSlaveGroupData();
172
176 void receiveRefreshedGroupConstraintsFromMaster();
177
189 void refreshAndSendGroupConstraints();
190
198 void refreshSlaveGroupTargets();
199
206 void rescoupSyncSummaryData();
207
218 void sendCoupledNetworkActiveStatus();
219
227 void sendMasterGroupConstraintsToSlaves();
228
237 void sendMasterGroupNodePressuresToSlaves(bool is_final);
238
249 void maybeExchangeNetworkSubIterationWithSlaves();
250
262 void maybeExchangeNetworkOuterIterationWithSlaves(bool more_network_update);
263
270 void sendSlaveGroupDataToMaster();
271
274 std::optional<ReservoirCoupling::ScopedLoggerGuard> setupScopedLogger(DeferredLogger& local_logger);
275
281 void storeSlaveGroupInjectionTargets();
282
289 void storeSlaveGroupProductionTargets();
290
291private:
296 std::optional<Scalar>
297 effectiveSlaveGroupInjectionTarget_(const std::string& gname,
298 const Phase phase,
299 const int reportStepIdx,
300 const ReservoirCoupling::CouplingInfo& rescoup,
301 const SummaryState& summary_state) const;
302
308 std::optional<Scalar>
309 effectiveSlaveGroupProductionTarget_(const std::string& gname,
310 const Group::ProductionCMode cmode,
311 const int reportStepIdx,
312 const ReservoirCoupling::CouplingInfo& rescoup,
313 const SummaryState& summary_state) const;
314
321 bool masterNetworkHasMasterGroupLeavesForSlave_(std::size_t slave_idx) const;
322
327 Scalar scheduleInjectionTarget_(const std::string& gname,
328 const Phase phase,
329 const int reportStepIdx,
330 const SummaryState& summary_state) const;
331
335 Scalar scheduleProductionTarget_(const std::string& gname,
336 const Group::ProductionCMode cmode,
337 const int reportStepIdx,
338 const SummaryState& summary_state) const;
339
349 bool slaveGroupIsFixedPressureNodeInOwnNetwork_(const std::string& group_name) const;
350
357 bool wellIsBelowOverriddenNode_(const std::string& group_name,
358 const std::map<std::string, Scalar>& overrides) const;
359
360 BlackoilWellModel<TypeTag>& well_model_;
361 BlackoilWellModelNetwork<TypeTag>& network_;
362 Simulator& simulator_;
363 const ModelParameters& param_;
364
365 // See lastSentMasterGroupNodePressuresIsFinal().
366 bool last_sent_master_group_node_pressures_is_final_{true};
367};
368
369} // namespace Opm
370
372
373#endif // RESERVOIR_COUPLING_ENABLED
374#endif // OPM_BLACKOILWELLMODEL_RESCOUP_HEADER_INCLUDED
Defines a type tags and some fundamental properties all models.
std::unique_ptr< WellInterface< TypeTag > > WellInterfacePtr
Definition: BlackoilWellModel.hpp:195
Definition: ReservoirCoupling.hpp:40
Phase
Phase indices for reservoir coupling, we currently only support black-oil phases (oil,...
Definition: ReservoirCoupling.hpp:183
Definition: blackoilbioeffectsmodules.hh:45