ReservoirCouplingSlaveReportStep.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_RESERVOIR_COUPLING_SLAVE_REPORT_STEP_HPP
21#define OPM_RESERVOIR_COUPLING_SLAVE_REPORT_STEP_HPP
22
24#include <opm/input/eclipse/EclipseState/Phase.hpp>
25#include <opm/input/eclipse/Schedule/Group/Group.hpp>
26
27#include <map>
28#include <string>
29#include <utility>
30
31namespace Opm {
32
33// Avoid including the complete definition of ReservoirCouplingSlave here to avoid circular dependency.
34template <class Scalar> class ReservoirCouplingSlave;
35
54template <class Scalar>
56public:
63
68 );
69
72 const Parallel::Communication &comm() const { return this->slave_.getComm(); }
73
76 MPI_Comm getSlaveMasterComm() const { return this->slave_.getMasterComm(); }
77
82 bool hasMasterInjectionTarget(const std::string& gname, const Phase phase) const;
83
87 bool hasMasterProductionLimits(const std::string& gname) const;
88
92 bool hasMasterProductionTarget(const std::string& gname) const;
93
99 bool isFirstSubstepOfSyncTimestep() const { return is_first_substep_of_sync_timestep_; }
100
108 bool isLastSubstepOfSyncTimestep() const { return is_last_substep_of_sync_timestep_; }
109
112 ReservoirCoupling::Logger& logger() const { return this->slave_.logger(); }
113
119 std::pair<Scalar, Group::InjectionCMode> masterInjectionTarget(
120 const std::string& gname, const Phase phase) const;
121
126 const MasterProductionLimits& masterProductionLimits(const std::string& gname) const;
127
132 std::pair<Scalar, Group::ProductionCMode> masterProductionTarget(const std::string& gname) const;
133
136 std::pair<std::size_t, std::size_t> receiveNumGroupConstraintsFromMaster() const;
137
140 void receiveInjectionGroupTargetsFromMaster(std::size_t num_targets);
141
144 void receiveProductionGroupConstraintsFromMaster(std::size_t num_targets);
145
156 void sendProductionDataToMaster(const std::vector<SlaveGroupProductionData> &production_data) const;
157
168 void sendInjectionDataToMaster(const std::vector<SlaveGroupInjectionData> &injection_data) const;
169
172 void setFirstSubstepOfSyncTimestep(bool value) { is_first_substep_of_sync_timestep_ = value; }
173
177 void setLastSubstepOfSyncTimestep(bool value) { is_last_substep_of_sync_timestep_ = value; }
178
185 void markSlaveGroupsInSchedule(Schedule& schedule, int report_step_idx);
186
189 const std::string& slaveName() const { return this->slave_.getSlaveName(); }
190
197 const std::string& gname, const Phase phase, const Scalar target, const Group::InjectionCMode cmode);
198
202 void setMasterProductionLimits(const std::string& gname, const MasterProductionLimits& limits);
203
208 void setMasterProductionTarget(const std::string& gname, const Scalar target, const Group::ProductionCMode cmode);
209
210
211private:
228 template <class DataType>
229 void sendDataToMaster_(
230 const std::vector<DataType>& data,
231 MessageTag tag,
232 const std::string& data_type_name
233 ) const;
234
237 // Flag to track if this is the first substep within a "sync" timestep.
238 // Used to control reservoir coupling synchronization.
239 bool is_first_substep_of_sync_timestep_{true};
240 // Flag to track if this is the last substep within a "sync" timestep.
241 // Used to control reservoir coupling synchronization of summary data sent from
242 // the slave to the master process.
243 bool is_last_substep_of_sync_timestep_{false};
244
245 // Master-imposed targets and corresponding control modes, received from the master
246 // process at the beginning of each sync timestep. Cleared and repopulated on every
247 // receive cycle. Used by GroupStateHelper to override slave group targets.
248 //
249 // Key: slave group name. Value: (target rate, production control mode).
250 std::map<std::string, std::pair<Scalar, Group::ProductionCMode>> master_production_targets_;
251 // Key: (injection phase, slave group name). Value: (target rate, injection control mode).
252 std::map<std::pair<Phase, std::string>, std::pair<Scalar, Group::InjectionCMode>> master_injection_targets_;
253 // Per-rate-type production limits from master hierarchy. Key: slave group name.
254 // A limit of -1 means no limit defined in the hierarchy for that rate type.
255 std::map<std::string, MasterProductionLimits> master_production_limits_;
256};
257} // namespace Opm
258#endif // OPM_RESERVOIR_COUPLING_SLAVE_REPORT_STEP_HPP
Definition: ReservoirCoupling.hpp:42
Definition: ReservoirCouplingSlave.hpp:40
Manages slave-side reservoir coupling operations for a single report step.
Definition: ReservoirCouplingSlaveReportStep.hpp:55
MPI_Comm getSlaveMasterComm() const
Get the MPI communicator for slave-master communication.
Definition: ReservoirCouplingSlaveReportStep.hpp:76
const std::string & slaveName() const
Get the name of this slave process.
Definition: ReservoirCouplingSlaveReportStep.hpp:189
std::pair< Scalar, Group::ProductionCMode > masterProductionTarget(const std::string &gname) const
Get the master-imposed production target and control mode for a group.
void setMasterInjectionTarget(const std::string &gname, const Phase phase, const Scalar target, const Group::InjectionCMode cmode)
Store a master-imposed injection target for a group and phase.
bool hasMasterInjectionTarget(const std::string &gname, const Phase phase) const
Check if a master-imposed injection target exists for a group and phase.
void setFirstSubstepOfSyncTimestep(bool value)
Set whether this is the first substep within a "sync" timestep.
Definition: ReservoirCouplingSlaveReportStep.hpp:172
void receiveProductionGroupConstraintsFromMaster(std::size_t num_targets)
Receive production group constraints from master and store them locally.
const MasterProductionLimits & masterProductionLimits(const std::string &gname) const
Get the master-imposed per-rate-type production limits for a group.
bool hasMasterProductionLimits(const std::string &gname) const
Check if master-imposed per-rate-type production limits exist for a group.
const Parallel::Communication & comm() const
Get the MPI communicator for intra-slave communication.
Definition: ReservoirCouplingSlaveReportStep.hpp:72
void setLastSubstepOfSyncTimestep(bool value)
Set whether this is the last substep within a "sync" timestep.
Definition: ReservoirCouplingSlaveReportStep.hpp:177
void setMasterProductionTarget(const std::string &gname, const Scalar target, const Group::ProductionCMode cmode)
Store a master-imposed production target for a group.
bool isLastSubstepOfSyncTimestep() const
Check if this is the last substep within a "sync" timestep.
Definition: ReservoirCouplingSlaveReportStep.hpp:108
ReservoirCoupling::Logger & logger() const
Get the logger for reservoir coupling operations.
Definition: ReservoirCouplingSlaveReportStep.hpp:112
void sendProductionDataToMaster(const std::vector< SlaveGroupProductionData > &production_data) const
Send production data to the master process.
std::pair< Scalar, Group::InjectionCMode > masterInjectionTarget(const std::string &gname, const Phase phase) const
Get the master-imposed injection target and control mode for a group and phase.
bool hasMasterProductionTarget(const std::string &gname) const
Check if a master-imposed production target exists for a group.
std::pair< std::size_t, std::size_t > receiveNumGroupConstraintsFromMaster() const
Receive the number of injection and production constraints from master.
void sendInjectionDataToMaster(const std::vector< SlaveGroupInjectionData > &injection_data) const
Send injection data to the master process.
void receiveInjectionGroupTargetsFromMaster(std::size_t num_targets)
Receive injection group targets from master and store them locally.
ReservoirCouplingSlaveReportStep(ReservoirCouplingSlave< Scalar > &slave)
Construct a report step manager for the slave process.
bool isFirstSubstepOfSyncTimestep() const
Check if this is the first substep within a "sync" timestep.
Definition: ReservoirCouplingSlaveReportStep.hpp:99
void setMasterProductionLimits(const std::string &gname, const MasterProductionLimits &limits)
Store master-imposed per-rate-type production limits for a group.
void markSlaveGroupsInSchedule(Schedule &schedule, int report_step_idx)
Mark slave groups in the Schedule as production/injection groups.
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
MessageTag
Definition: ReservoirCoupling.hpp:134
Phase
Phase indices for reservoir coupling, we currently only support black-oil phases (oil,...
Definition: ReservoirCoupling.hpp:156
Definition: blackoilbioeffectsmodules.hh:45
Definition: ReservoirCoupling.hpp:235
Per-rate-type production limits received from master hierarchy. A value of -1 means no limit defined ...
Definition: ReservoirCoupling.hpp:263
Definition: ReservoirCoupling.hpp:245
Definition: ReservoirCoupling.hpp:229
Definition: ReservoirCoupling.hpp:211