ReservoirCouplingMaster.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_MASTER_HPP
21#define OPM_RESERVOIR_COUPLING_MASTER_HPP
22
25#include <opm/input/eclipse/Schedule/Schedule.hpp>
26#include <opm/common/OpmLog/OpmLog.hpp>
27
28#include <mpi.h>
29
30#include <filesystem>
31#include <vector>
32
33namespace Opm {
34
36public:
41 const Parallel::Communication &comm,
42 const Schedule &schedule,
43 int argc, char **argv
44 );
45
46 bool activated() { return this->numSlavesStarted() > 0; }
47 void addSlaveCommunicator(MPI_Comm comm) {
48 this->master_slave_comm_.push_back(comm);
49 }
50 void addSlaveName(const std::string &name) { this->slave_names_.push_back(name); }
51 void addSlaveNextReportTimeOffset(double offset) {
52 this->slave_next_report_time_offsets_.push_back(offset);
53 }
54 void addSlaveStartDate(std::time_t date) { this->slave_start_dates_.push_back(date); }
56 double getActivationDate() const { return this->activation_date_; }
57 int getArgc() const { return this->argc_; }
58 char *getArgv(int index) const { return this->argv_[index]; }
59 char **getArgv() const { return this->argv_; }
60 const Parallel::Communication &getComm() const { return this->comm_; }
67 const std::string &slave_name, const std::string &master_group_name) const;
68 std::map<std::string, std::string>& getMasterGroupToSlaveNameMap() {
69 return this->master_group_slave_names_;
70 }
71 double getSimulationStartDate() const { return this->schedule_.getStartTime(); }
72 MPI_Comm getSlaveComm(int index) const { return this->master_slave_comm_[index]; }
73 const Potentials& getSlaveGroupPotentials(const std::string &master_group_name);
74 const std::string &getSlaveName(int index) const { return this->slave_names_[index]; }
75 const double *getSlaveStartDates() { return this->slave_start_dates_.data(); }
76 bool isMasterGroup(const std::string &group_name) const;
77 double maybeChopSubStep(double suggested_timestep, double current_time) const;
78 void maybeSpawnSlaveProcesses(int report_step);
79 std::size_t numSlaveGroups(unsigned int index);
80 std::size_t numSlavesStarted() const;
83 void resizeSlaveStartDates(int size) { this->slave_start_dates_.resize(size); }
84 void resizeNextReportDates(int size) { this->slave_next_report_time_offsets_.resize(size); }
85 void sendNextTimeStepToSlaves(double next_time_step);
86 void setDeferredLogger(DeferredLogger *deferred_logger) {
87 this->logger_.setDeferredLogger(deferred_logger);
88 }
89 // These are currently only used for unit testing
90 void setSlaveStartDate(int index, std::time_t date) { this->slave_start_dates_[index] = date; }
91 void setSlaveNextReportTimeOffset(int index, double offset) {
92 this->slave_next_report_time_offsets_[index] = offset;
93 }
95 const std::string& slave_name, const std::map<std::string, std::size_t>& master_group_map);
96
97private:
98 double getMasterActivationDate_() const;
99
100 const Parallel::Communication &comm_;
101 const Schedule& schedule_;
102 int argc_;
103 char **argv_;
104 // NOTE: MPI_Comm is just an integer handle, so we can just copy it into the vector
105 std::vector<MPI_Comm> master_slave_comm_; // MPI communicators for the slave processes
106 std::vector<std::string> slave_names_;
107 // The start dates are in whole seconds since the epoch. We use a double to store the value
108 // since both schedule_.getStartTime() and schedule_.stepLength(report_step) returns
109 // a double value representing whole seconds.
110 // However, note that schedule_[report_step].start_time() returns a time_point
111 // which can include milliseconds. The double values are also convenient when we need to
112 // to add fractions of seconds for sub steps to the start date.
113 std::vector<double> slave_start_dates_;
114 // Elapsed time from the beginning of the simulation
115 std::vector<double> slave_next_report_time_offsets_;
116 double activation_date_{0.0}; // The date when SLAVES is encountered in the schedule
117 // A mapping from a slave name to the master group name order used when slaves send
118 // potentials to the master process.
119 std::map<std::string, std::map<std::string, std::size_t>> master_group_name_order_;
121 // Potentials for oil, gas, and water rates for each slave group
122 std::map<std::string, std::vector<Potentials>> slave_group_potentials_;
123 // A mapping from master group names to slave names
124 std::map<std::string, std::string> master_group_slave_names_;
125};
126
127} // namespace Opm
128#endif // OPM_RESERVOIR_COUPLING_MASTER_HPP
Definition: DeferredLogger.hpp:57
Definition: ReservoirCoupling.hpp:35
void setDeferredLogger(DeferredLogger *deferred_logger)
Definition: ReservoirCoupling.hpp:41
void clearDeferredLogger()
Definition: ReservoirCoupling.hpp:38
Definition: ReservoirCouplingMaster.hpp:35
bool isMasterGroup(const std::string &group_name) const
std::size_t getMasterGroupPotIdx(const std::string &slave_name, const std::string &master_group_name) const
Get the index of the master group potential for a given slave name and master group name....
bool activated()
Definition: ReservoirCouplingMaster.hpp:46
void resizeSlaveStartDates(int size)
Definition: ReservoirCouplingMaster.hpp:83
void setSlaveNextReportTimeOffset(int index, double offset)
Definition: ReservoirCouplingMaster.hpp:91
int getArgc() const
Definition: ReservoirCouplingMaster.hpp:57
void addSlaveName(const std::string &name)
Definition: ReservoirCouplingMaster.hpp:50
void clearDeferredLogger()
Definition: ReservoirCouplingMaster.hpp:55
const double * getSlaveStartDates()
Definition: ReservoirCouplingMaster.hpp:75
const Potentials & getSlaveGroupPotentials(const std::string &master_group_name)
std::size_t numSlaveGroups(unsigned int index)
char ** getArgv() const
Definition: ReservoirCouplingMaster.hpp:59
void sendNextTimeStepToSlaves(double next_time_step)
void addSlaveStartDate(std::time_t date)
Definition: ReservoirCouplingMaster.hpp:54
const Parallel::Communication & getComm() const
Definition: ReservoirCouplingMaster.hpp:60
void addSlaveNextReportTimeOffset(double offset)
Definition: ReservoirCouplingMaster.hpp:51
MPI_Comm getSlaveComm(int index) const
Definition: ReservoirCouplingMaster.hpp:72
double getActivationDate() const
Definition: ReservoirCouplingMaster.hpp:56
void setDeferredLogger(DeferredLogger *deferred_logger)
Definition: ReservoirCouplingMaster.hpp:86
double getSimulationStartDate() const
Definition: ReservoirCouplingMaster.hpp:71
const std::string & getSlaveName(int index) const
Definition: ReservoirCouplingMaster.hpp:74
void resizeNextReportDates(int size)
Definition: ReservoirCouplingMaster.hpp:84
ReservoirCouplingMaster(const Parallel::Communication &comm, const Schedule &schedule, int argc, char **argv)
std::size_t numSlavesStarted() const
void updateMasterGroupNameOrderMap(const std::string &slave_name, const std::map< std::string, std::size_t > &master_group_map)
void setSlaveStartDate(int index, std::time_t date)
Definition: ReservoirCouplingMaster.hpp:90
void maybeSpawnSlaveProcesses(int report_step)
double maybeChopSubStep(double suggested_timestep, double current_time) const
std::map< std::string, std::string > & getMasterGroupToSlaveNameMap()
Definition: ReservoirCouplingMaster.hpp:68
void addSlaveCommunicator(MPI_Comm comm)
Definition: ReservoirCouplingMaster.hpp:47
char * getArgv(int index) const
Definition: ReservoirCouplingMaster.hpp:58
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
MessageTag
Definition: ReservoirCoupling.hpp:47
Definition: blackoilboundaryratevector.hh:39
Definition: ReservoirCoupling.hpp:62
Utility class for comparing double values representing epoch dates or elapsed time.
Definition: ReservoirCoupling.hpp:94