opm-simulators
ReservoirCouplingMasterReportStep.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_MASTER_REPORT_STEP_HPP
21 #define OPM_RESERVOIR_COUPLING_MASTER_REPORT_STEP_HPP
22 
23 #include <opm/simulators/flow/rescoup/ReservoirCoupling.hpp>
24 #include <opm/simulators/flow/rescoup/ReservoirCouplingMpiTraits.hpp>
25 #include <opm/input/eclipse/Schedule/Schedule.hpp>
26 #include <opm/simulators/utils/ParallelCommunication.hpp>
27 #include <opm/common/OpmLog/OpmLog.hpp>
28 
29 #include <mpi.h>
30 
31 #include <vector>
32 
33 namespace Opm {
34 
35 // Avoid including the complete definition of ReservoirCouplingMaster here to avoid circular dependency.
36 template <class Scalar> class ReservoirCouplingMaster;
37 
58 template <class Scalar>
60 public:
61  using MessageTag = ReservoirCoupling::MessageTag;
67 
72  );
73 
76  const Parallel::Communication &comm() const { return this->master_.getComm(); }
77 
81  const std::vector<std::string>& getMasterGroupNamesForSlave(std::size_t slave_idx) const {
82  return this->master_.getMasterGroupNamesForSlave(slave_idx);
83  }
84 
87  const std::map<std::string, std::string>& getMasterGroupToSlaveNameMap() const {
88  return this->master_.getMasterGroupToSlaveNameMap();
89  }
90 
95  std::size_t getMasterGroupCanonicalIdx(
96  const std::string &slave_name, const std::string &master_group_name) const;
97 
101  MPI_Comm getSlaveComm(int index) const { return this->master_.getSlaveComm(index); }
102 
107  Scalar getMasterGroupInjectionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
108 
113  Scalar getMasterGroupInjectionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
114 
119  Scalar getMasterGroupProductionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
120 
131  const std::string &group_name, ReservoirCoupling::Phase phase) const;
132 
143  Scalar getMasterGroupProductionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
144 
148  const Potentials& getSlaveGroupPotentials(const std::string &master_group_name) const;
149 
155  bool isFirstSubstepOfSyncTimestep() const { return is_first_substep_of_sync_timestep_; }
156 
160  bool needsSlaveDataReceive() const { return needs_slave_data_receive_; }
161 
163  void setNeedsSlaveDataReceive(bool value) { needs_slave_data_receive_ = value; }
164 
168  std::size_t numSlaveGroups(unsigned int index) const { return this->master_.numSlaveGroups(index); }
169 
172  std::size_t numSlaves() const { return this->master_.numSlavesStarted(); }
173 
176  ReservoirCoupling::Logger& logger() const { return this->master_.logger(); }
177 
187 
198 
201  const Schedule &schedule() const { return this->master_.schedule(); }
202 
203  void sendInjectionTargetsToSlave(
204  std::size_t slave_idx, const std::vector<InjectionGroupTarget>& injection_targets
205  ) const;
206  void sendNumGroupConstraintsToSlave(
207  std::size_t slave_idx, std::size_t num_injection_targets, std::size_t num_production_constraints
208  ) const;
209  void sendProductionConstraintsToSlave(
210  std::size_t slave_idx, const std::vector<ProductionGroupConstraints>& production_constraints
211  ) const;
212 
215  void setFirstSubstepOfSyncTimestep(bool value) { is_first_substep_of_sync_timestep_ = value; }
216 
222  void setReportStepIdx(int report_step_idx);
223 
227  bool slaveIsActivated(int index) const { return this->master_.slaveIsActivated(index); }
228 
232  const std::string &slaveName(int index) const { return this->master_.getSlaveName(index); }
233 
234 private:
240  Scalar getMasterGroupRate_(const std::string &group_name, ReservoirCoupling::Phase phase,
241  ReservoirCoupling::RateKind kind) const;
242 
245 
247  int report_step_idx_;
248 
250  std::map<std::string, std::vector<SlaveGroupProductionData>> slave_group_production_data_;
251 
253  std::map<std::string, std::vector<SlaveGroupInjectionData>> slave_group_injection_data_;
254 
257  bool is_first_substep_of_sync_timestep_{true};
258 
264  bool needs_slave_data_receive_{false};
265 };
266 } // namespace Opm
267 #endif // OPM_RESERVOIR_COUPLING_MASTER_REPORT_STEP_HPP
const Parallel::Communication & comm() const
Get the MPI communicator for master-slave communication.
Definition: ReservoirCouplingMasterReportStep.hpp:76
const Potentials & getSlaveGroupPotentials(const std::string &master_group_name) const
Get the production potentials for a slave group.
Definition: ReservoirCouplingMasterReportStep.cpp:105
const Schedule & schedule() const
Get the simulation schedule.
Definition: ReservoirCouplingMasterReportStep.hpp:201
std::size_t getMasterGroupCanonicalIdx(const std::string &slave_name, const std::string &master_group_name) const
Get the canonical index for a master group.
Definition: ReservoirCouplingMasterReportStep.cpp:55
Scalar getMasterGroupInjectionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the injection surface rate for a master group.
Definition: ReservoirCouplingMasterReportStep.cpp:63
Scalar getMasterGroupInjectionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the injection reservoir rate for a master group.
Definition: ReservoirCouplingMasterReportStep.cpp:71
void setNeedsSlaveDataReceive(bool value)
Set/clear the flag for pending slave data receive.
Definition: ReservoirCouplingMasterReportStep.hpp:163
Definition: ReservoirCoupling.hpp:42
Scalar getMasterGroupProductionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the production reservoir rate for a master group.
Definition: ReservoirCouplingMasterReportStep.cpp:97
ReservoirCoupling::Logger & logger() const
Get the logger for reservoir coupling operations.
Definition: ReservoirCouplingMasterReportStep.hpp:176
void receiveInjectionDataFromSlaves()
Receive injection data from all active slave processes.
Definition: ReservoirCouplingMasterReportStep.cpp:127
void receiveProductionDataFromSlaves()
Receive production data from all active slave processes.
Definition: ReservoirCouplingMasterReportStep.cpp:180
MPI_Comm getSlaveComm(int index) const
Get the MPI communicator for a specific slave process.
Definition: ReservoirCouplingMasterReportStep.hpp:101
const std::vector< std::string > & getMasterGroupNamesForSlave(std::size_t slave_idx) const
Get the names of master groups associated with a specific slave.
Definition: ReservoirCouplingMasterReportStep.hpp:81
const std::string & slaveName(int index) const
Get the name of a specific slave process.
Definition: ReservoirCouplingMasterReportStep.hpp:232
Definition: ReservoirCoupling.hpp:229
Scalar getMasterGroupProductionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the production surface rate for a master group.
Definition: ReservoirCouplingMasterReportStep.cpp:79
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
ReservoirCouplingMasterReportStep(ReservoirCouplingMaster< Scalar > &master)
Construct a report step manager for the master process.
Definition: ReservoirCouplingMasterReportStep.cpp:41
void setReportStepIdx(int report_step_idx)
Set the current report step index.
Definition: ReservoirCouplingMasterReportStep.cpp:318
bool needsSlaveDataReceive() const
Check if the master needs to receive slave data at the next timeStepSucceeded() call.
Definition: ReservoirCouplingMasterReportStep.hpp:160
Definition: ReservoirCoupling.hpp:187
std::size_t numSlaveGroups(unsigned int index) const
Get the number of slave groups for a specific slave process.
Definition: ReservoirCouplingMasterReportStep.hpp:168
void setFirstSubstepOfSyncTimestep(bool value)
Set whether this is the first substep within a "sync" timestep.
Definition: ReservoirCouplingMasterReportStep.hpp:215
const std::map< std::string, std::string > & getMasterGroupToSlaveNameMap() const
Get the mapping from master group names to slave names.
Definition: ReservoirCouplingMasterReportStep.hpp:87
std::size_t numSlaves() const
Get the total number of active slave processes.
Definition: ReservoirCouplingMasterReportStep.hpp:172
Definition: ReservoirCoupling.hpp:245
Definition: ReservoirCouplingMaster.hpp:38
bool slaveIsActivated(int index) const
Check if a specific slave process has been activated.
Definition: ReservoirCouplingMasterReportStep.hpp:227
Definition: ReservoirCoupling.hpp:235
bool isFirstSubstepOfSyncTimestep() const
Check if this is the first substep within a "sync" timestep.
Definition: ReservoirCouplingMasterReportStep.hpp:155
Scalar getMasterGroupNetworkProductionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the network production surface rate for a master group.
Definition: ReservoirCouplingMasterReportStep.cpp:87
Manages master-side reservoir coupling operations for a single report step.
Definition: ReservoirCouplingMasterReportStep.hpp:59
Definition: ReservoirCoupling.hpp:211