opm-simulators
Loading...
Searching...
No Matches
ReservoirCouplingSlaveReportStep.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_RESERVOIR_COUPLING_SLAVE_REPORT_STEP_HPP
21#define OPM_RESERVOIR_COUPLING_SLAVE_REPORT_STEP_HPP
22
23#include <opm/simulators/flow/rescoup/ReservoirCoupling.hpp>
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:
57 using InjectionGroupTarget = ReservoirCoupling::InjectionGroupTarget<Scalar>;
58 using ProductionGroupConstraints = ReservoirCoupling::ProductionGroupConstraints<Scalar>;
59 using MessageTag = ReservoirCoupling::MessageTag;
60 using MasterProductionLimits = ReservoirCoupling::MasterProductionLimits<Scalar>;
61 using SlaveGroupInjectionData = ReservoirCoupling::SlaveGroupInjectionData<Scalar>;
62 using SlaveGroupProductionData = ReservoirCoupling::SlaveGroupProductionData<Scalar>;
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
181 const std::string& slaveName() const { return this->slave_.getSlaveName(); }
182
189 const std::string& gname, const Phase phase, const Scalar target, const Group::InjectionCMode cmode);
190
194 void setMasterProductionLimits(const std::string& gname, const MasterProductionLimits& limits);
195
200 void setMasterProductionTarget(const std::string& gname, const Scalar target, const Group::ProductionCMode cmode);
201
202
203private:
220 template <class DataType>
221 void sendDataToMaster_(
222 const std::vector<DataType>& data,
223 MessageTag tag,
224 const std::string& data_type_name
225 ) const;
226
229 // Flag to track if this is the first substep within a "sync" timestep.
230 // Used to control reservoir coupling synchronization.
231 bool is_first_substep_of_sync_timestep_{true};
232 // Flag to track if this is the last substep within a "sync" timestep.
233 // Used to control reservoir coupling synchronization of summary data sent from
234 // the slave to the master process.
235 bool is_last_substep_of_sync_timestep_{false};
236
237 // Master-imposed targets and corresponding control modes, received from the master
238 // process at the beginning of each sync timestep. Cleared and repopulated on every
239 // receive cycle. Used by GroupStateHelper to override slave group targets.
240 //
241 // Key: slave group name. Value: (target rate, production control mode).
242 std::map<std::string, std::pair<Scalar, Group::ProductionCMode>> master_production_targets_;
243 // Key: (injection phase, slave group name). Value: (target rate, injection control mode).
244 std::map<std::pair<Phase, std::string>, std::pair<Scalar, Group::InjectionCMode>> master_injection_targets_;
245 // Per-rate-type production limits from master hierarchy. Key: slave group name.
246 // A limit of -1 means no limit defined in the hierarchy for that rate type.
247 std::map<std::string, MasterProductionLimits> master_production_limits_;
248};
249} // namespace Opm
250#endif // OPM_RESERVOIR_COUPLING_SLAVE_REPORT_STEP_HPP
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:181
std::pair< Scalar, Group::ProductionCMode > masterProductionTarget(const std::string &gname) const
Get the master-imposed production target and control mode for a group.
Definition ReservoirCouplingSlaveReportStep.cpp:95
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.
Definition ReservoirCouplingSlaveReportStep.cpp:239
bool hasMasterInjectionTarget(const std::string &gname, const Phase phase) const
Check if a master-imposed injection target exists for a group and phase.
Definition ReservoirCouplingSlaveReportStep.cpp:55
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.
Definition ReservoirCouplingSlaveReportStep.cpp:172
const MasterProductionLimits & masterProductionLimits(const std::string &gname) const
Get the master-imposed per-rate-type production limits for a group.
Definition ReservoirCouplingSlaveReportStep.cpp:87
bool hasMasterProductionLimits(const std::string &gname) const
Check if master-imposed per-rate-type production limits exist for a group.
Definition ReservoirCouplingSlaveReportStep.cpp:63
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.
Definition ReservoirCouplingSlaveReportStep.cpp:257
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.
Definition ReservoirCouplingSlaveReportStep.cpp:229
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.
Definition ReservoirCouplingSlaveReportStep.cpp:79
bool hasMasterProductionTarget(const std::string &gname) const
Check if a master-imposed production target exists for a group.
Definition ReservoirCouplingSlaveReportStep.cpp:71
std::pair< std::size_t, std::size_t > receiveNumGroupConstraintsFromMaster() const
Receive the number of injection and production constraints from master.
Definition ReservoirCouplingSlaveReportStep.cpp:144
void sendInjectionDataToMaster(const std::vector< SlaveGroupInjectionData > &injection_data) const
Send injection data to the master process.
Definition ReservoirCouplingSlaveReportStep.cpp:219
void receiveInjectionGroupTargetsFromMaster(std::size_t num_targets)
Receive injection group targets from master and store them locally.
Definition ReservoirCouplingSlaveReportStep.cpp:103
ReservoirCouplingSlaveReportStep(ReservoirCouplingSlave< Scalar > &slave)
Construct a report step manager for the slave process.
Definition ReservoirCouplingSlaveReportStep.cpp:41
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.
Definition ReservoirCouplingSlaveReportStep.cpp:249
Definition ReservoirCouplingSlave.hpp:40
Definition ReservoirCoupling.hpp:42
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:45
Definition ReservoirCoupling.hpp:235
Per-rate-type production limits received from master hierarchy.
Definition ReservoirCoupling.hpp:263
Definition ReservoirCoupling.hpp:245
Definition ReservoirCoupling.hpp:229
Definition ReservoirCoupling.hpp:211