ReservoirCouplingMasterReportStep.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_MASTER_REPORT_STEP_HPP
21#define OPM_RESERVOIR_COUPLING_MASTER_REPORT_STEP_HPP
22
25#include <opm/output/data/Groups.hpp>
26#include <opm/input/eclipse/Schedule/Schedule.hpp>
28#include <opm/common/OpmLog/OpmLog.hpp>
29
30#include <mpi.h>
31
32#include <vector>
33
34namespace Opm {
35
36// Avoid including the complete definition of ReservoirCouplingMaster here to avoid circular dependency.
37template <class Scalar> class ReservoirCouplingMaster;
38
59template <class Scalar>
61public:
69
74 );
75
78 const Parallel::Communication &comm() const { return this->master_.getComm(); }
79
83 const std::vector<std::string>& getMasterGroupNamesForSlave(std::size_t slave_idx) const {
84 return this->master_.getMasterGroupNamesForSlave(slave_idx);
85 }
86
89 const std::map<std::string, std::string>& getMasterGroupToSlaveNameMap() const {
90 return this->master_.getMasterGroupToSlaveNameMap();
91 }
92
98 const std::string &slave_name, const std::string &master_group_name) const;
99
103 MPI_Comm getSlaveComm(int index) const { return this->master_.getSlaveComm(index); }
104
109 Scalar getMasterGroupInjectionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
110
115 Scalar getMasterGroupInjectionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
116
121 Scalar getMasterGroupProductionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
122
133 const std::string &group_name, ReservoirCoupling::Phase phase) const;
134
145 Scalar getMasterGroupProductionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
146
152 const Potentials& getSlaveGroupInjectionPotentials(const std::string &master_group_name) const;
153
157 const Potentials& getSlaveGroupPotentials(const std::string &master_group_name) const;
158
164 bool isFirstSubstepOfSyncTimestep() const { return is_first_substep_of_sync_timestep_; }
165
169 bool needsSlaveDataReceive() const { return needs_slave_data_receive_; }
170
172 void setNeedsSlaveDataReceive(bool value) { needs_slave_data_receive_ = value; }
173
177 std::size_t numSlaveGroups(unsigned int index) const { return this->master_.numSlaveGroups(index); }
178
181 std::size_t numSlaves() const { return this->master_.numSlavesStarted(); }
182
185 ReservoirCoupling::Logger& logger() const { return this->master_.logger(); }
186
196
207
210 const Schedule &schedule() const { return this->master_.schedule(); }
211
221 std::size_t slave_idx, bool active
222 ) const;
223
225 std::size_t slave_idx, const std::vector<InjectionGroupTarget>& injection_targets
226 ) const;
227
232 std::size_t slave_idx, const std::vector<MasterGroupNodePressure>& pressures
233 ) const;
234
236 std::size_t slave_idx, std::size_t num_injection_targets, std::size_t num_production_constraints
237 ) const;
238
248 std::size_t slave_idx, std::size_t num_pressures, bool is_final
249 ) const;
250
252 std::size_t slave_idx, const std::vector<ProductionGroupConstraints>& production_constraints
253 ) const;
254
257 void setFirstSubstepOfSyncTimestep(bool value) { is_first_substep_of_sync_timestep_ = value; }
258
264 void setReportStepIdx(int report_step_idx);
265
268 data::ReservoirCouplingGroupRates collectGroupRatesForSummary() const;
269
275 bool slaveIsCoupled(int index) const { return this->master_.slaveIsCoupled(index); }
276
280 const std::string &slaveName(int index) const { return this->master_.getSlaveName(index); }
281
282private:
288 Scalar getMasterGroupRate_(const std::string &group_name, ReservoirCoupling::Phase phase,
289 ReservoirCoupling::RateKind kind) const;
290
293
295 int report_step_idx_;
296
298 std::map<std::string, std::vector<SlaveGroupProductionData>> slave_group_production_data_;
299
301 std::map<std::string, std::vector<SlaveGroupInjectionData>> slave_group_injection_data_;
302
305 bool is_first_substep_of_sync_timestep_{true};
306
312 bool needs_slave_data_receive_{false};
313};
314} // namespace Opm
315#endif // OPM_RESERVOIR_COUPLING_MASTER_REPORT_STEP_HPP
Definition: ReservoirCoupling.hpp:42
Definition: ReservoirCouplingMaster.hpp:42
Manages master-side reservoir coupling operations for a single report step.
Definition: ReservoirCouplingMasterReportStep.hpp:60
ReservoirCouplingMasterReportStep(ReservoirCouplingMaster< Scalar > &master)
Construct a report step manager for the master process.
void sendProductionConstraintsToSlave(std::size_t slave_idx, const std::vector< ProductionGroupConstraints > &production_constraints) const
bool isFirstSubstepOfSyncTimestep() const
Check if this is the first substep within a "sync" timestep.
Definition: ReservoirCouplingMasterReportStep.hpp:164
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:83
MPI_Comm getSlaveComm(int index) const
Get the MPI communicator for a specific slave process.
Definition: ReservoirCouplingMasterReportStep.hpp:103
void receiveProductionDataFromSlaves()
Receive production data from all active slave processes.
Scalar getMasterGroupInjectionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the injection surface rate for a master group.
const Parallel::Communication & comm() const
Get the MPI communicator for master-slave communication.
Definition: ReservoirCouplingMasterReportStep.hpp:78
std::size_t getMasterGroupCanonicalIdx(const std::string &slave_name, const std::string &master_group_name) const
Get the canonical index for a master group.
bool slaveIsCoupled(int index) const
Check if a specific slave process currently takes part in the coupling.
Definition: ReservoirCouplingMasterReportStep.hpp:275
const std::map< std::string, std::string > & getMasterGroupToSlaveNameMap() const
Get the mapping from master group names to slave names.
Definition: ReservoirCouplingMasterReportStep.hpp:89
void setNeedsSlaveDataReceive(bool value)
Set/clear the flag for pending slave data receive.
Definition: ReservoirCouplingMasterReportStep.hpp:172
Scalar getMasterGroupNetworkProductionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the network production surface rate for a master group.
void setReportStepIdx(int report_step_idx)
Set the current report step index.
Scalar getMasterGroupProductionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the production surface rate for a master group.
ReservoirCoupling::Logger & logger() const
Get the logger for reservoir coupling operations.
Definition: ReservoirCouplingMasterReportStep.hpp:185
data::ReservoirCouplingGroupRates collectGroupRatesForSummary() const
Collect production/injection rates for all master groups.
bool needsSlaveDataReceive() const
Check if the master needs to receive slave data at the next timeStepSucceeded() call.
Definition: ReservoirCouplingMasterReportStep.hpp:169
const Potentials & getSlaveGroupInjectionPotentials(const std::string &master_group_name) const
Get the injection potentials for a slave group.
Scalar getMasterGroupProductionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the production reservoir rate for a master group.
const Schedule & schedule() const
Get the simulation schedule.
Definition: ReservoirCouplingMasterReportStep.hpp:210
void sendNumMasterGroupNodePressuresToSlave(std::size_t slave_idx, std::size_t num_pressures, bool is_final) const
Send the count of master-computed network-leaf node pressures that will follow, plus an is_final flag...
const Potentials & getSlaveGroupPotentials(const std::string &master_group_name) const
Get the production potentials for a slave group.
void sendMasterGroupNodePressuresToSlave(std::size_t slave_idx, const std::vector< MasterGroupNodePressure > &pressures) const
Send master-computed network-leaf node pressures to a slave.
void sendCoupledNetworkActiveStatusToSlave(std::size_t slave_idx, bool active) const
Send a single boolean to a slave telling it whether the master will iterate the cross-rescoup network...
void receiveInjectionDataFromSlaves()
Receive injection data from all active slave processes.
std::size_t numSlaves() const
Get the total number of active slave processes.
Definition: ReservoirCouplingMasterReportStep.hpp:181
void sendInjectionTargetsToSlave(std::size_t slave_idx, const std::vector< InjectionGroupTarget > &injection_targets) const
Scalar getMasterGroupInjectionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the injection reservoir rate for a master group.
void setFirstSubstepOfSyncTimestep(bool value)
Set whether this is the first substep within a "sync" timestep.
Definition: ReservoirCouplingMasterReportStep.hpp:257
void sendNumGroupConstraintsToSlave(std::size_t slave_idx, std::size_t num_injection_targets, std::size_t num_production_constraints) const
std::size_t numSlaveGroups(unsigned int index) const
Get the number of slave groups for a specific slave process.
Definition: ReservoirCouplingMasterReportStep.hpp:177
const std::string & slaveName(int index) const
Get the name of a specific slave process.
Definition: ReservoirCouplingMasterReportStep.hpp:280
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
RateKind
Selects which kind of rate to retrieve from slave group data.
Definition: ReservoirCoupling.hpp:195
MessageTag
Definition: ReservoirCoupling.hpp:138
Phase
Phase indices for reservoir coupling, we currently only support black-oil phases (oil,...
Definition: ReservoirCoupling.hpp:183
Definition: blackoilbioeffectsmodules.hh:45
Definition: ReservoirCoupling.hpp:286
Master-computed network-leaf node pressure for a single master group.
Definition: ReservoirCoupling.hpp:329
Definition: ReservoirCoupling.hpp:214
Definition: ReservoirCoupling.hpp:296
Definition: ReservoirCoupling.hpp:271
Definition: ReservoirCoupling.hpp:238