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
179 void refreshSlaveGroupInjectionTargets();
180
187 void rescoupSyncSummaryData();
188
199 void sendCoupledNetworkActiveStatus();
200
208 void sendMasterGroupConstraintsToSlaves();
209
218 void sendMasterGroupNodePressuresToSlaves(bool is_final);
219
230 void maybeExchangeNetworkSubIterationWithSlaves();
231
243 void maybeExchangeNetworkOuterIterationWithSlaves(bool more_network_update);
244
251 void sendSlaveGroupDataToMaster();
252
255 std::optional<ReservoirCoupling::ScopedLoggerGuard> setupScopedLogger(DeferredLogger& local_logger);
256
262 void storeSlaveGroupInjectionTargets();
263
264private:
269 std::optional<Scalar>
270 effectiveSlaveGroupInjectionTarget_(const std::string& gname,
271 const Phase phase,
272 const int reportStepIdx,
273 const ReservoirCoupling::CouplingInfo& rescoup,
274 const SummaryState& summary_state) const;
275
282 bool masterNetworkHasMasterGroupLeavesForSlave_(std::size_t slave_idx) const;
283
293 void refreshAndSendInjectionTargets_();
294
299 Scalar scheduleInjectionTarget_(const std::string& gname,
300 const Phase phase,
301 const int reportStepIdx,
302 const SummaryState& summary_state) const;
303
307 void sendMasterGroupInjectionTargetsToSlaves_();
308
318 bool slaveGroupIsFixedPressureNodeInOwnNetwork_(const std::string& group_name) const;
319
320 BlackoilWellModel<TypeTag>& well_model_;
321 BlackoilWellModelNetwork<TypeTag>& network_;
322 Simulator& simulator_;
323 const ModelParameters& param_;
324
325 // See lastSentMasterGroupNodePressuresIsFinal().
326 bool last_sent_master_group_node_pressures_is_final_{true};
327};
328
329} // namespace Opm
330
332
333#endif // RESERVOIR_COUPLING_ENABLED
334#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