opm-simulators
BlackoilWellModelRescoup.hpp
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 
23 #include <opm/simulators/flow/rescoup/ReservoirCouplingEnabled.hpp>
24 
25 #ifdef RESERVOIR_COUPLING_ENABLED
26 
28 
29 #include <opm/simulators/flow/rescoup/ReservoirCoupling.hpp>
30 
31 #include <optional>
32 
33 namespace Opm {
34  class DeferredLogger;
35  class Schedule;
36  template<class TypeTag> class BlackoilWellModel;
37  template<class Scalar, class IndexTraits> class GroupStateHelper;
38  template<class Scalar, class IndexTraits> class WellState;
39  template<class Scalar> class ReservoirCouplingMaster;
40  template<class Scalar> class ReservoirCouplingSlave;
41 }
42 
43 namespace Opm {
44 
56 template<typename TypeTag>
57 class BlackoilWellModelRescoup {
58  using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
59  using Scalar = GetPropType<TypeTag, Properties::Scalar>;
60  using IndexTraits = typename FluidSystem::IndexTraitsType;
61  using Simulator = GetPropType<TypeTag, Properties::Simulator>;
62  using ModelParameters = BlackoilModelParameters<Scalar>;
63  using WellInterfacePtr = typename BlackoilWellModel<TypeTag>::WellInterfacePtr;
64 
65 public:
66  explicit BlackoilWellModelRescoup(BlackoilWellModel<TypeTag>& well_model);
67 
68  // === Mode queries and rescoup-facade forwarders ===
69 
70  bool isReservoirCouplingMaster() const { return well_model_.isReservoirCouplingMaster(); }
71  bool isReservoirCouplingSlave() const { return well_model_.isReservoirCouplingSlave(); }
72 
73  ReservoirCouplingMaster<Scalar>& reservoirCouplingMaster()
74  { return well_model_.reservoirCouplingMaster(); }
75  const ReservoirCouplingMaster<Scalar>& reservoirCouplingMaster() const
76  { return well_model_.reservoirCouplingMaster(); }
77 
78  ReservoirCouplingSlave<Scalar>& reservoirCouplingSlave()
79  { return well_model_.reservoirCouplingSlave(); }
80  const ReservoirCouplingSlave<Scalar>& reservoirCouplingSlave() const
81  { return well_model_.reservoirCouplingSlave(); }
82 
83  // === Common-state accessor forwarders ===
84 
85  GroupStateHelper<Scalar, IndexTraits>& groupStateHelper()
86  { return well_model_.groupStateHelper(); }
87  const GroupStateHelper<Scalar, IndexTraits>& groupStateHelper() const
88  { return well_model_.groupStateHelper(); }
89 
90  WellState<Scalar, IndexTraits>& wellState()
91  { return well_model_.wellState(); }
92  const WellState<Scalar, IndexTraits>& wellState() const
93  { return well_model_.wellState(); }
94 
95  const Schedule& schedule() const { return well_model_.schedule(); }
96 
97  std::vector<WellInterfacePtr>& wellContainer()
98  { return well_model_.wellContainer(); }
99 
100  // === Rescoup flow methods ===
101 
108  bool lastSentMasterGroupNodePressuresIsFinal() const
109  { return last_sent_master_group_node_pressures_is_final_; }
110 
120  bool masterNetworkHasMasterGroupLeaves() const;
121 
127  bool masterIsInCoupledNetworkIteration() const;
128 
136  void receiveCoupledNetworkActiveStatus();
137 
144  void receiveGroupConstraintsFromMaster();
145 
149  void receiveMasterGroupNodePressuresFromMaster();
150 
158  void receiveSlaveGroupData();
159 
166  void rescoupSyncSummaryData();
167 
178  void sendCoupledNetworkActiveStatus();
179 
187  void sendMasterGroupConstraintsToSlaves();
188 
197  void sendMasterGroupNodePressuresToSlaves(bool is_final);
198 
209  void maybeExchangeNetworkSubIterationWithSlaves();
210 
222  void maybeExchangeNetworkOuterIterationWithSlaves(bool more_network_update);
223 
230  void sendSlaveGroupDataToMaster();
231 
234  std::optional<ReservoirCoupling::ScopedLoggerGuard> setupScopedLogger(DeferredLogger& local_logger);
235 
236 private:
243  bool masterNetworkHasMasterGroupLeavesForSlave_(std::size_t slave_idx) const;
244 
245  BlackoilWellModel<TypeTag>& well_model_;
246  BlackoilWellModelNetwork<TypeTag>& network_;
247  Simulator& simulator_;
248  const ModelParameters& param_;
249 
250  // See lastSentMasterGroupNodePressuresIsFinal().
251  bool last_sent_master_group_node_pressures_is_final_{true};
252 };
253 
254 } // namespace Opm
255 
256 #include "BlackoilWellModelRescoup_impl.hpp"
257 
258 #endif // RESERVOIR_COUPLING_ENABLED
259 #endif // OPM_BLACKOILWELLMODEL_RESCOUP_HEADER_INCLUDED
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Defines a type tags and some fundamental properties all models.