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
103 ReservoirCoupling::Logger& logger() const { return this->slave_.logger(); }
104
110 std::pair<Scalar, Group::InjectionCMode> masterInjectionTarget(
111 const std::string& gname, const Phase phase) const;
112
117 const MasterProductionLimits& masterProductionLimits(const std::string& gname) const;
118
123 std::pair<Scalar, Group::ProductionCMode> masterProductionTarget(const std::string& gname) const;
124
127 std::pair<std::size_t, std::size_t> receiveNumGroupConstraintsFromMaster() const;
128
131 void receiveInjectionGroupTargetsFromMaster(std::size_t num_targets);
132
135 void receiveProductionGroupConstraintsFromMaster(std::size_t num_targets);
136
147 void sendProductionDataToMaster(const std::vector<SlaveGroupProductionData> &production_data) const;
148
159 void sendInjectionDataToMaster(const std::vector<SlaveGroupInjectionData> &injection_data) const;
160
163 void setFirstSubstepOfSyncTimestep(bool value) { is_first_substep_of_sync_timestep_ = value; }
164
167 const std::string& slaveName() const { return this->slave_.getSlaveName(); }
168
175 const std::string& gname, const Phase phase, const Scalar target, const Group::InjectionCMode cmode);
176
180 void setMasterProductionLimits(const std::string& gname, const MasterProductionLimits& limits);
181
186 void setMasterProductionTarget(const std::string& gname, const Scalar target, const Group::ProductionCMode cmode);
187
188
189private:
206 template <class DataType>
207 void sendDataToMaster_(
208 const std::vector<DataType>& data,
209 MessageTag tag,
210 const std::string& data_type_name
211 ) const;
212
215 // Flag to track if this is the first substep within a "sync" timestep.
216 // Used to control reservoir coupling synchronization.
217 bool is_first_substep_of_sync_timestep_{true};
218
219 // Master-imposed targets and corresponding control modes, received from the master
220 // process at the beginning of each sync timestep. Cleared and repopulated on every
221 // receive cycle. Used by GroupStateHelper to override slave group targets.
222 //
223 // Key: slave group name. Value: (target rate, production control mode).
224 std::map<std::string, std::pair<Scalar, Group::ProductionCMode>> master_production_targets_;
225 // Key: (injection phase, slave group name). Value: (target rate, injection control mode).
226 std::map<std::pair<Phase, std::string>, std::pair<Scalar, Group::InjectionCMode>> master_injection_targets_;
227 // Per-rate-type production limits from master hierarchy. Key: slave group name.
228 // A limit of -1 means no limit defined in the hierarchy for that rate type.
229 std::map<std::string, MasterProductionLimits> master_production_limits_;
230};
231} // namespace Opm
232#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:167
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:163
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 setMasterProductionTarget(const std::string &gname, const Scalar target, const Group::ProductionCMode cmode)
Store a master-imposed production target for a group.
ReservoirCoupling::Logger & logger() const
Get the logger for reservoir coupling operations.
Definition: ReservoirCouplingSlaveReportStep.hpp:103
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.
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