ReservoirCouplingSlave.hpp
Go to the documentation of this file.
1/*
2 Copyright 2024 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_HPP
21#define OPM_RESERVOIR_COUPLING_SLAVE_HPP
22
25#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
36template <class Scalar>
37class ReservoirCouplingSlaveReportStep;
38
39template <class Scalar>
41public:
48
50 const Parallel::Communication &comm, const Schedule &schedule, const SimulatorTimer &timer
51 );
52 bool activated() const { return activated_; }
54 const Parallel::Communication& getComm() const { return comm_; }
55 MPI_Comm getMasterComm() const { return slave_master_comm_; }
56 const std::string& getSlaveName() const { return slave_name_; }
57 const std::map<std::string, std::string>& getSlaveToMasterGroupNameMap() const {
58 return slave_to_master_group_map_; }
61 ReservoirCoupling::Logger& logger() { return this->logger_; }
62 ReservoirCoupling::Logger& logger() const { return this->logger_; }
63 void maybeActivate(int report_step);
64 std::size_t numSlaveGroups() const { return this->slave_group_order_.size(); }
66 std::pair<std::size_t, std::size_t> receiveNumGroupTargetsFromMaster() const;
67 void receiveInjectionGroupTargetsFromMaster(std::size_t num_targets) const;
68 void receiveProductionGroupTargetsFromMaster(std::size_t num_targets) const;
70 void sendInjectionDataToMaster(const std::vector<SlaveGroupInjectionData> &injection_data) const;
72 void sendProductionDataToMaster(const std::vector<SlaveGroupProductionData> &production_data) const;
73 void setDeferredLogger(DeferredLogger *deferred_logger) {
74 this->logger_.setDeferredLogger(deferred_logger);
75 }
77 const std::string& slaveGroupIdxToGroupName(std::size_t group_idx) const {
78 return this->slave_group_order_.at(group_idx);
79 }
80
81private:
82 void checkGrupSlavGroupNames_();
83 std::pair<double, bool> getGrupSlavActivationDateAndCheckHistoryMatchingMode_() const;
84 bool historyMatchingMode_() const { return this->history_matching_mode_; }
85 std::size_t numMasterGroups_() const { return this->slave_to_master_group_map_.size(); }
86 void receiveMasterGroupNamesFromMasterProcess_();
87 void receiveSlaveNameFromMasterProcess_();
88 void saveMasterGroupNamesAsMapAndEstablishOrder_(const std::vector<char>& group_names);
89 void sendActivationDateToMasterProcess_();
90 void sendActivationHandshakeToMasterProcess_() const;
91 void sendSimulationStartDateToMasterProcess_() const;
92
93 const Parallel::Communication &comm_;
94 const Schedule& schedule_;
95 const SimulatorTimer &timer_;
96 // MPI parent communicator for a slave process
97 MPI_Comm slave_master_comm_{MPI_COMM_NULL};
98 std::map<std::string, std::string> slave_to_master_group_map_;
99 bool activated_{false};
100 // True if no GRUPMAST keyword in the master schedule and no GRUPSLAV keyword in the slave schedule
101 bool history_matching_mode_{false};
102 std::string slave_name_; // This is the slave name as defined in the master process
103 mutable ReservoirCoupling::Logger logger_;
104 // Order of the slave groups. A mapping from slave group index to slave group name.
105 // The indices are determined by the order the master process sends us the group names, see
106 // receiveMasterGroupNamesFromMasterProcess_()
107 // Later, the master process will send us group name indices, and not the group names themselves,
108 // so we use this mapping to recover the slave group names from the indices.
109 std::map<std::size_t, std::string> slave_group_order_;
110 // Stores data that changes for a single report step or for timesteps within a report step.
111 std::unique_ptr<ReservoirCouplingSlaveReportStep<Scalar>> report_step_data_{nullptr};
112};
113
114} // namespace Opm
115
116#endif // OPM_RESERVOIR_COUPLING_SLAVE_HPP
Definition: DeferredLogger.hpp:57
Definition: ReservoirCoupling.hpp:38
void setDeferredLogger(DeferredLogger *deferred_logger)
Definition: ReservoirCoupling.hpp:47
void clearDeferredLogger()
Definition: ReservoirCoupling.hpp:41
Definition: ReservoirCouplingSlave.hpp:40
const std::map< std::string, std::string > & getSlaveToMasterGroupNameMap() const
Definition: ReservoirCouplingSlave.hpp:57
ReservoirCouplingSlave(const Parallel::Communication &comm, const Schedule &schedule, const SimulatorTimer &timer)
const std::string & getSlaveName() const
Definition: ReservoirCouplingSlave.hpp:56
void setFirstSubstepOfSyncTimestep(bool value)
void receiveInjectionGroupTargetsFromMaster(std::size_t num_targets) const
void sendProductionDataToMaster(const std::vector< SlaveGroupProductionData > &production_data) const
std::size_t numSlaveGroups() const
Definition: ReservoirCouplingSlave.hpp:64
bool isFirstSubstepOfSyncTimestep() const
const Parallel::Communication & getComm() const
Definition: ReservoirCouplingSlave.hpp:54
void setDeferredLogger(DeferredLogger *deferred_logger)
Definition: ReservoirCouplingSlave.hpp:73
MPI_Comm getMasterComm() const
Definition: ReservoirCouplingSlave.hpp:55
void clearDeferredLogger()
Definition: ReservoirCouplingSlave.hpp:53
void sendNextReportDateToMasterProcess() const
ReservoirCoupling::Logger & logger()
Definition: ReservoirCouplingSlave.hpp:61
const std::string & slaveGroupIdxToGroupName(std::size_t group_idx) const
Definition: ReservoirCouplingSlave.hpp:77
void sendInjectionDataToMaster(const std::vector< SlaveGroupInjectionData > &injection_data) const
bool activated() const
Definition: ReservoirCouplingSlave.hpp:52
ReservoirCoupling::Logger & logger() const
Definition: ReservoirCouplingSlave.hpp:62
void maybeActivate(int report_step)
void receiveProductionGroupTargetsFromMaster(std::size_t num_targets) const
std::pair< std::size_t, std::size_t > receiveNumGroupTargetsFromMaster() const
Definition: SimulatorTimer.hpp:39
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
MessageTag
Definition: ReservoirCoupling.hpp:126
Definition: blackoilbioeffectsmodules.hh:43
Definition: ReservoirCoupling.hpp:212
Definition: ReservoirCoupling.hpp:167
Definition: ReservoirCoupling.hpp:222
Definition: ReservoirCoupling.hpp:206
Definition: ReservoirCoupling.hpp:191