35class ReservoirCouplingMaster {
37 using MessageTag = ReservoirCoupling::MessageTag;
40 ReservoirCouplingMaster(
41 const Parallel::Communication &comm,
42 const Schedule &schedule,
46 bool activated() {
return this->activated_; }
47 void addSlaveCommunicator(MPI_Comm comm) {
48 this->master_slave_comm_.push_back(comm);
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);
54 void addSlaveActivationDate(
double date) { this->slave_activation_dates_.push_back(date); }
55 void addSlaveStartDate(std::time_t date) { this->slave_start_dates_.push_back(date); }
56 void clearDeferredLogger() { logger_.clearDeferredLogger(); }
57 double getActivationDate()
const {
return this->activation_date_; }
58 int getArgc()
const {
return this->argc_; }
59 char *getArgv(
int index)
const {
return this->argv_[index]; }
60 char **getArgv()
const {
return this->argv_; }
61 const Parallel::Communication &getComm()
const {
return this->comm_; }
68 const std::string &slave_name,
const std::string &master_group_name)
const;
69 std::map<std::string, std::string>& getMasterGroupToSlaveNameMap() {
70 return this->master_group_slave_names_;
72 double getSlaveActivationDate(
int index)
const {
return this->slave_activation_dates_[index]; }
73 const double *getSlaveActivationDates()
const {
return this->slave_activation_dates_.data(); }
74 double getSimulationStartDate()
const {
return this->schedule_.getStartTime(); }
75 MPI_Comm getSlaveComm(
int index)
const {
return this->master_slave_comm_[index]; }
76 const Potentials& getSlaveGroupPotentials(
const std::string &master_group_name);
77 const std::string &getSlaveName(
int index)
const {
return this->slave_names_[index]; }
78 const double *getSlaveStartDates() {
return this->slave_start_dates_.data(); }
79 bool isMasterGroup(
const std::string &group_name)
const;
80 void maybeActivate(
int report_step);
81 void maybeReceiveActivationHandshakeFromSlaves(
double current_time);
82 double maybeChopSubStep(
double suggested_timestep,
double current_time)
const;
83 void maybeSpawnSlaveProcesses(
int report_step);
84 std::size_t numSlaveGroups(
unsigned int index);
85 std::size_t numSlavesStarted()
const;
86 void receiveNextReportDateFromSlaves();
87 void receivePotentialsFromSlaves();
88 void resizeSlaveActivationDates(
int size) { this->slave_activation_dates_.resize(size); }
89 void resizeSlaveStartDates(
int size) { this->slave_start_dates_.resize(size); }
90 void resizeNextReportDates(
int size) { this->slave_next_report_time_offsets_.resize(size); }
91 void sendNextTimeStepToSlaves(
double next_time_step);
93 this->logger_.setDeferredLogger(deferred_logger);
96 void setSlaveActivationDate(
int index,
double date) { this->slave_activation_dates_[index] = date; }
97 void setSlaveStartDate(
int index, std::time_t date) { this->slave_start_dates_[index] = date; }
98 void setSlaveNextReportTimeOffset(
int index,
double offset) {
99 this->slave_next_report_time_offsets_[index] = offset;
101 bool slaveIsActivated(
int index)
const {
return this->slave_activation_status_[index] != 0; }
102 void updateMasterGroupNameOrderMap(
103 const std::string& slave_name,
const std::map<std::string, std::size_t>& master_group_map);
106 double getMasterActivationDate_()
const;
108 const Parallel::Communication &comm_;
109 const Schedule& schedule_;
113 bool activated_{
false};
115 std::vector<MPI_Comm> master_slave_comm_;
116 std::vector<std::string> slave_names_;
123 std::vector<double> slave_start_dates_;
125 std::vector<double> slave_activation_dates_;
127 std::vector<double> slave_next_report_time_offsets_;
128 double activation_date_{0.0};
131 std::map<std::string, std::map<std::string, std::size_t>> master_group_name_order_;
136 std::vector<std::uint8_t> slave_activation_status_;
138 std::map<std::string, std::vector<Potentials>> slave_group_potentials_;
140 std::map<std::string, std::string> master_group_slave_names_;