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 <array>
33#include <limits>
34#include <map>
35#include <string>
36#include <tuple>
37#include <utility>
38#include <vector>
39
40namespace Opm {
41
42// Avoid including the complete definition of ReservoirCouplingMaster here to avoid circular dependency.
43template <class Scalar> class ReservoirCouplingMaster;
44
65template <class Scalar>
67public:
76
81 );
82
85 const Parallel::Communication &comm() const { return this->master_.getComm(); }
86
90 const std::vector<std::string>& getMasterGroupNamesForSlave(std::size_t slave_idx) const {
91 return this->master_.getMasterGroupNamesForSlave(slave_idx);
92 }
93
96 const std::map<std::string, std::string>& getMasterGroupToSlaveNameMap() const {
97 return this->master_.getMasterGroupToSlaveNameMap();
98 }
99
105 const std::string &slave_name, const std::string &master_group_name) const;
106
110 MPI_Comm getSlaveComm(int index) const { return this->master_.getSlaveComm(index); }
111
116 Scalar getMasterGroupInjectionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
117
122 Scalar getMasterGroupInjectionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
123
128 Scalar getMasterGroupProductionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
129
140 const std::string &group_name, ReservoirCoupling::Phase phase) const;
141
152 Scalar getMasterGroupProductionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const;
153
156 bool hasSlaveGroupProductionData(const std::string &group_name) const;
157
163 Scalar getMasterGroupGasLiftRate(const std::string &group_name, bool network) const;
164
167 Scalar getMasterGroupGasLiftHeadroom(const std::string &group_name) const;
168
177 int getSlaveGroupNumGroupControlledInjectors(const std::string &master_group_name,
178 ReservoirCoupling::Phase phase) const;
179
186 int getSlaveGroupNumGroupControlledProducers(const std::string &master_group_name) const;
187
191 const Potentials& getSlaveGroupPotentials(const std::string &master_group_name) const;
192
198 bool isFirstSubstepOfSyncTimestep() const { return is_first_substep_of_sync_timestep_; }
199
203 bool needsSlaveDataReceive() const { return needs_slave_data_receive_; }
204
206 void setNeedsSlaveDataReceive(bool value) { needs_slave_data_receive_ = value; }
207
211 std::size_t numSlaveGroups(unsigned int index) const { return this->master_.numSlaveGroups(index); }
212
215 std::size_t numSlaves() const { return this->master_.numSlavesStarted(); }
216
219 ReservoirCoupling::Logger& logger() const { return this->master_.logger(); }
220
230
241
244 const Schedule &schedule() const { return this->master_.schedule(); }
245
255 std::size_t slave_idx, bool active
256 ) const;
257
259 std::size_t slave_idx, const std::vector<InjectionGroupTarget>& injection_targets
260 ) const;
261
266 std::size_t slave_idx, const std::vector<MasterGroupNodePressure>& pressures
267 ) const;
268
270 std::size_t slave_idx, std::size_t num_injection_targets, std::size_t num_production_constraints,
271 std::size_t num_gas_lift_limits
272 ) const;
273
277 std::size_t slave_idx, const std::vector<GasLiftGroupLimits>& gas_lift_limits
278 ) const;
279
289 std::size_t slave_idx, std::size_t num_pressures, bool is_final
290 ) const;
291
293 std::size_t slave_idx, const std::vector<ProductionGroupConstraints>& production_constraints
294 ) const;
295
298 void setFirstSubstepOfSyncTimestep(bool value) { is_first_substep_of_sync_timestep_ = value; }
299
305 void setReportStepIdx(int report_step_idx);
306
311 void setSlaveGroupInjectionData(const std::string& slave_name,
312 std::vector<SlaveGroupInjectionData> injection_data)
313 {
314 this->slave_group_injection_data_[slave_name] = std::move(injection_data);
315 }
316
321 void setSlaveGroupProductionData(const std::string& slave_name,
322 std::vector<SlaveGroupProductionData> production_data)
323 {
324 this->slave_group_production_data_[slave_name] = std::move(production_data);
325 }
326
333
335 void setSyncStepLength(Scalar length) { sync_step_length_ = length; }
336
345
348 Scalar flowChangeTimeStepLimit() const { return flow_change_time_step_limit_; }
349
352 std::tuple<std::string, Scalar, Scalar> flowChangeLimitingGroup() const {
353 return {flow_change_limiting_group_, flow_change_limiting_change_, flow_change_limiting_fraction_};
354 }
355
358 data::ReservoirCouplingGroupRates collectGroupRatesForSummary() const;
359
365 bool slaveIsCoupled(int index) const { return this->master_.slaveIsCoupled(index); }
366
370 const std::string &slaveName(int index) const { return this->master_.getSlaveName(index); }
371
372private:
376 slaveGroupProductionDataOrNull_(const std::string &group_name) const;
377
379 struct GroupFlows {
380 Scalar production_reservoir{};
381 std::array<Scalar, 3> injection_surface{};
382 };
383
385 GroupFlows getMasterGroupFlows_(const std::string& group_name) const;
386
392 Scalar getMasterGroupRate_(const std::string &group_name, ReservoirCoupling::Phase phase,
393 ReservoirCoupling::RateKind kind) const;
394
396 ReservoirCouplingMaster<Scalar> &master_;
397
399 int report_step_idx_;
400
402 std::map<std::string, std::vector<SlaveGroupProductionData>> slave_group_production_data_;
403
405 std::map<std::string, std::vector<SlaveGroupInjectionData>> slave_group_injection_data_;
406
409 bool is_first_substep_of_sync_timestep_{true};
410
416 bool needs_slave_data_receive_{false};
417
419 std::map<std::string, GroupFlows> group_flows_at_start_of_sync_step_;
420
422 Scalar sync_step_length_{0};
423
425 Scalar flow_change_time_step_limit_{std::numeric_limits<Scalar>::infinity()};
426
428 std::string flow_change_limiting_group_;
429 Scalar flow_change_limiting_change_{0};
430 Scalar flow_change_limiting_fraction_{0};
431};
432} // namespace Opm
433#endif // OPM_RESERVOIR_COUPLING_MASTER_REPORT_STEP_HPP
Definition: ReservoirCoupling.hpp:42
Definition: ReservoirCouplingMaster.hpp:43
Manages master-side reservoir coupling operations for a single report step.
Definition: ReservoirCouplingMasterReportStep.hpp:66
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:198
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:90
Scalar flowChangeTimeStepLimit() const
Upper limit for the next sync step length from GRUPMAST item 4 (in seconds)
Definition: ReservoirCouplingMasterReportStep.hpp:348
MPI_Comm getSlaveComm(int index) const
Get the MPI communicator for a specific slave process.
Definition: ReservoirCouplingMasterReportStep.hpp:110
void receiveProductionDataFromSlaves()
Receive production data from all active slave processes.
std::tuple< std::string, Scalar, Scalar > flowChangeLimitingGroup() const
Description of the group that sets flowChangeTimeStepLimit()
Definition: ReservoirCouplingMasterReportStep.hpp:352
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:85
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 hasSlaveGroupProductionData(const std::string &group_name) const
Whether the slave of a master group has sent production data, which a slave with no slave groups (his...
void saveGroupFlowsAtStartOfSyncStep()
Remember the flow rates of the master groups as they stand now.
bool slaveIsCoupled(int index) const
Check if a specific slave process currently takes part in the coupling.
Definition: ReservoirCouplingMasterReportStep.hpp:365
Scalar getMasterGroupGasLiftRate(const std::string &group_name, bool network) const
Get the lift gas rate of the slave group of a master group.
const std::map< std::string, std::string > & getMasterGroupToSlaveNameMap() const
Get the mapping from master group names to slave names.
Definition: ReservoirCouplingMasterReportStep.hpp:96
void setNeedsSlaveDataReceive(bool value)
Set/clear the flag for pending slave data receive.
Definition: ReservoirCouplingMasterReportStep.hpp:206
Scalar getMasterGroupNetworkProductionSurfaceRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the network production surface rate for a master group.
void setSlaveGroupInjectionData(const std::string &slave_name, std::vector< SlaveGroupInjectionData > injection_data)
Set the injection data of a slave's groups, as received from the slave.
Definition: ReservoirCouplingMasterReportStep.hpp:311
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.
int getSlaveGroupNumGroupControlledProducers(const std::string &master_group_name) const
Get the number of a slave group's producers under group control.
void sendGasLiftGroupLimitsToSlave(std::size_t slave_idx, const std::vector< GasLiftGroupLimits > &gas_lift_limits) const
Send the gas lift limits (GLIFTOPT) for the slave's groups. Rank-0-only on the master comm.
ReservoirCoupling::Logger & logger() const
Get the logger for reservoir coupling operations.
Definition: ReservoirCouplingMasterReportStep.hpp:219
void setSyncStepLength(Scalar length)
Set the length of the sync step that is about to be taken.
Definition: ReservoirCouplingMasterReportStep.hpp:335
void setSlaveGroupProductionData(const std::string &slave_name, std::vector< SlaveGroupProductionData > production_data)
Set the production data of a slave's groups, as received from the slave.
Definition: ReservoirCouplingMasterReportStep.hpp:321
void updateFlowChangeTimeStepLimit()
Update the flow-change time step limit (GRUPMAST item 4, RCMASTS)
data::ReservoirCouplingGroupRates collectGroupRatesForSummary() const
Collect production/injection rates for all master groups.
int getSlaveGroupNumGroupControlledInjectors(const std::string &master_group_name, ReservoirCoupling::Phase phase) const
Get the number of a slave group's injectors under group control for a phase.
bool needsSlaveDataReceive() const
Check if the master needs to receive slave data at the next timeStepSucceeded() call.
Definition: ReservoirCouplingMasterReportStep.hpp:203
Scalar getMasterGroupProductionReservoirRate(const std::string &group_name, ReservoirCoupling::Phase phase) const
Get the production reservoir rate for a master group.
Scalar getMasterGroupGasLiftHeadroom(const std::string &group_name) const
How much more lift gas the slave group of a master group can take, 0 if the slave has sent no product...
void sendNumGroupConstraintsToSlave(std::size_t slave_idx, std::size_t num_injection_targets, std::size_t num_production_constraints, std::size_t num_gas_lift_limits) const
const Schedule & schedule() const
Get the simulation schedule.
Definition: ReservoirCouplingMasterReportStep.hpp:244
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:215
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:298
std::size_t numSlaveGroups(unsigned int index) const
Get the number of slave groups for a specific slave process.
Definition: ReservoirCouplingMasterReportStep.hpp:211
const std::string & slaveName(int index) const
Get the name of a specific slave process.
Definition: ReservoirCouplingMasterReportStep.hpp:370
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
RateKind
Selects which kind of rate to retrieve from slave group data.
Definition: ReservoirCoupling.hpp:196
MessageTag
Definition: ReservoirCoupling.hpp:138
Phase
Phase indices for reservoir coupling, we currently only support black-oil phases (oil,...
Definition: ReservoirCoupling.hpp:184
Definition: blackoilbioeffectsmodules.hh:45
Gas lift limits (GLIFTOPT) the master imposes on a slave group.
Definition: ReservoirCoupling.hpp:336
Definition: ReservoirCoupling.hpp:305
Master-computed network-leaf node pressure for a single master group.
Definition: ReservoirCoupling.hpp:362
Definition: ReservoirCoupling.hpp:215
Definition: ReservoirCoupling.hpp:315
Definition: ReservoirCoupling.hpp:285
Definition: ReservoirCoupling.hpp:239