20#ifndef OPM_RESERVOIR_COUPLING_SLAVE_HPP
21#define OPM_RESERVOIR_COUPLING_SLAVE_HPP
23#include <opm/simulators/flow/rescoup/ReservoirCoupling.hpp>
24#include <opm/simulators/flow/rescoup/ReservoirCouplingSlaveReportStep.hpp>
25#include <opm/input/eclipse/Schedule/Schedule.hpp>
26#include <opm/simulators/utils/ParallelCommunication.hpp>
27#include <opm/simulators/timestepping/SimulatorTimer.hpp>
28#include <opm/common/OpmLog/OpmLog.hpp>
36template <
class Scalar>
39template <
class Scalar>
40class ReservoirCouplingSlave {
42 using MessageTag = ReservoirCoupling::MessageTag;
50 ReservoirCouplingSlave(
51 const Parallel::Communication &comm,
const Schedule &schedule,
const SimulatorTimer &timer
53 bool activated()
const {
return activated_; }
54 void clearDeferredLogger() { logger_.clearDeferredLogger(); }
55 const Parallel::Communication& getComm()
const {
return comm_; }
56 MPI_Comm getMasterComm()
const {
return slave_master_comm_; }
57 const std::string& getSlaveName()
const {
return slave_name_; }
58 const std::map<std::string, std::string>& getSlaveToMasterGroupNameMap()
const {
59 return slave_to_master_group_map_; }
71 void initTimeStepping();
72 bool isFirstSubstepOfSyncTimestep()
const;
81 bool isSlaveGroup(
const std::string& group_name)
const;
87 const std::string& gname,
const Phase phase)
const;
96 void maybeActivate(
int report_step);
97 std::size_t numSlaveGroups()
const {
return this->slave_group_order_.size(); }
98 double receiveNextTimeStepFromMaster();
99 std::pair<std::size_t, std::size_t> receiveNumGroupConstraintsFromMaster()
const;
108 void sendAndReceiveInitialData();
109 void sendInjectionDataToMaster(
const std::vector<SlaveGroupInjectionData> &injection_data)
const;
110 void sendNextReportDateToMasterProcess()
const;
111 void sendProductionDataToMaster(
const std::vector<SlaveGroupProductionData> &production_data)
const;
113 this->logger_.setDeferredLogger(deferred_logger);
115 void setFirstSubstepOfSyncTimestep(
bool value);
120 const std::string& slaveGroupIdxToGroupName(std::size_t group_idx)
const {
121 return this->slave_group_order_.at(group_idx);
123 bool terminated()
const {
return this->terminated_; }
147 void checkGrupSlavGroupNames_();
148 std::pair<double, bool> getGrupSlavActivationDateAndCheckHistoryMatchingMode_()
const;
149 bool historyMatchingMode_()
const {
return this->history_matching_mode_; }
150 std::size_t numMasterGroups_()
const {
return this->slave_to_master_group_map_.size(); }
151 void receiveMasterGroupNamesFromMasterProcess_();
152 void receiveSlaveNameFromMasterProcess_();
153 void saveMasterGroupNamesAsMapAndEstablishOrder_(
const std::vector<char>& group_names);
154 void sendActivationDateToMasterProcess_();
155 void sendActivationHandshakeToMasterProcess_()
const;
156 void sendSimulationStartDateToMasterProcess_()
const;
158 const Parallel::Communication &comm_;
159 const Schedule& schedule_;
162 MPI_Comm slave_master_comm_{MPI_COMM_NULL};
163 std::map<std::string, std::string> slave_to_master_group_map_;
164 bool activated_{
false};
166 bool terminated_{
false};
168 bool history_matching_mode_{
false};
169 std::string slave_name_;
176 std::map<std::size_t, std::string> slave_group_order_;
178 std::unique_ptr<ReservoirCouplingSlaveReportStep<Scalar>> report_step_data_{
nullptr};
Definition DeferredLogger.hpp:57
Manages slave-side reservoir coupling operations for a single report step.
Definition ReservoirCouplingSlaveReportStep.hpp:55
std::pair< Scalar, Group::ProductionCMode > masterProductionTarget(const std::string &gname) const
Get the master-imposed production target and control mode for a group.
Definition ReservoirCouplingSlave.cpp:147
const MasterProductionLimits & masterProductionLimits(const std::string &gname) const
Get the master-imposed per-rate-type production limits for a group.
Definition ReservoirCouplingSlave.cpp:138
void receiveInjectionGroupTargetsFromMaster(std::size_t num_targets)
Receive injection group targets from master and store them locally.
Definition ReservoirCouplingSlave.cpp:215
void receiveProductionGroupConstraintsFromMaster(std::size_t num_targets)
Receive production group constraints from master and store them locally.
Definition ReservoirCouplingSlave.cpp:258
bool isLastSubstepOfSyncTimestep() const
Check if this is the last substep within a "sync" timestep.
Definition ReservoirCouplingSlave.cpp:113
bool hasMasterInjectionTarget(const std::string &gname, const Phase phase) const
Check if a master-imposed injection target exists for a group and phase.
Definition ReservoirCouplingSlave.cpp:68
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 ReservoirCouplingSlave.cpp:129
bool maybeReceiveTerminateSignalFromMaster()
Blocking receive for terminate/continue signal from master.
Definition ReservoirCouplingSlave.cpp:181
bool hasMasterProductionTarget(const std::string &gname) const
Check if a master-imposed production target exists for a group.
Definition ReservoirCouplingSlave.cpp:86
void setLastSubstepOfSyncTimestep(bool value)
Set whether this is the last substep within a "sync" timestep.
Definition ReservoirCouplingSlave.cpp:366
bool hasMasterProductionLimits(const std::string &gname) const
Check if master-imposed per-rate-type production limits exist for a group.
Definition ReservoirCouplingSlave.cpp:77
void receiveTerminateAndDisconnect()
Receive terminate signal from master and disconnect the intercommunicator.
Definition ReservoirCouplingSlave.cpp:267
Definition ReservoirCoupling.hpp:42
Definition SimulatorTimer.hpp:39
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:187
Definition ReservoirCoupling.hpp:245
Definition ReservoirCoupling.hpp:229
Definition ReservoirCoupling.hpp:211