38class ReservoirCouplingMaster {
40 using MessageTag = ReservoirCoupling::MessageTag;
47 ReservoirCouplingMaster(
48 const Parallel::Communication &comm,
49 const Schedule &schedule,
53 bool activated() {
return this->activated_; }
54 void addSlaveCommunicator(MPI_Comm comm) {
55 this->master_slave_comm_.push_back(comm);
57 void addSlaveName(
const std::string &name) { this->slave_names_.push_back(name); }
58 void addSlaveActivationDate(
double date) { this->slave_activation_dates_.push_back(date); }
59 void addSlaveStartDate(std::time_t date) { this->slave_start_dates_.push_back(date); }
60 void clearDeferredLogger() { logger_.clearDeferredLogger(); }
61 double getActivationDate()
const {
return this->activation_date_; }
62 int getArgc()
const {
return this->argc_; }
63 char *getArgv(
int index)
const {
return this->argv_[index]; }
64 char **getArgv()
const {
return this->argv_; }
65 const Parallel::Communication &getComm()
const {
return this->comm_; }
86 const std::string &slave_name,
const std::string &master_group_name)
const;
87 Scalar getMasterGroupRate(
88 const std::string &group_name, ReservoirCoupling::Phase phase, ReservoirCoupling::RateKind kind)
const;
89 std::map<std::string, std::string>& getMasterGroupToSlaveNameMap() {
90 return this->master_group_slave_names_;
92 double getSimulationStartDate()
const {
return this->schedule_.getStartTime(); }
93 double getSlaveActivationDate(
int index)
const {
return this->slave_activation_dates_[index]; }
94 const double *getSlaveActivationDates()
const {
return this->slave_activation_dates_.data(); }
95 MPI_Comm getSlaveComm(
int index)
const {
return this->master_slave_comm_[index]; }
96 std::map<std::string, std::vector<std::string>> &getSlaveNameToMasterGroupsMap() {
97 return this->slave_name_to_master_groups_map_;
99 const Potentials& getSlaveGroupPotentials(
const std::string &master_group_name);
100 int getSlaveIdx(
const std::string &slave_name)
const;
101 const std::string &getSlaveName(
int index)
const {
return this->slave_names_[index]; }
102 double getSlaveStartDate(
int index)
const {
return this->slave_start_dates_[index]; }
103 const double *getSlaveStartDates() {
return this->slave_start_dates_.data(); }
104 void initStartOfReportStep(
int report_step_idx);
105 void initTimeStepping();
106 bool isFirstSubstepOfSyncTimestep()
const;
107 bool isMasterGroup(
const std::string &group_name)
const;
121 void maybeActivate(
int report_step);
122 void maybeReceiveActivationHandshakeFromSlaves(
double current_time);
123 double maybeChopSubStep(
double suggested_timestep,
double current_time)
const;
124 void maybeSpawnSlaveProcesses(
int report_step);
125 std::size_t numSlaveGroups(
unsigned int index);
126 std::size_t numSlaves()
const {
return this->numSlavesStarted(); }
127 std::size_t numSlavesStarted()
const;
128 std::size_t numActivatedSlaves()
const;
129 void rebuildSlaveIdxToMasterGroupsVector();
130 void receiveNextReportDateFromSlaves();
131 void receiveProductionDataFromSlaves();
132 void receiveInjectionDataFromSlaves();
133 void resizeNextReportDates(
int size);
134 void resizeSlaveActivationDates(
int size) { this->slave_activation_dates_.resize(size); }
135 void resizeSlaveStartDates(
int size) { this->slave_start_dates_.resize(size); }
136 const Schedule& schedule()
const {
return this->schedule_; }
137 void sendNextTimeStepToSlaves(
double next_time_step) {
138 this->time_stepper_->sendNextTimeStepToSlaves(next_time_step);
140 void sendInjectionTargetsToSlave(
141 std::size_t slave_idx,
142 const std::vector<InjectionGroupTarget>& injection_targets
144 void sendNumGroupConstraintsToSlave(
145 std::size_t slave_idx,
146 std::size_t num_injection_targets,
147 std::size_t num_production_constraints
149 void sendProductionConstraintsToSlave(
150 std::size_t slave_idx,
151 const std::vector<ProductionGroupConstraints>& production_constraints
154 this->logger_.setDeferredLogger(deferred_logger);
156 void setFirstSubstepOfSyncTimestep(
bool value);
158 void setSlaveActivationDate(
int index,
double date) { this->slave_activation_dates_[index] = date; }
159 void setSlaveNextReportTimeOffset(
int index,
double offset);
160 void setSlaveStartDate(
int index, std::time_t date) { this->slave_start_dates_[index] = date; }
161 bool slaveIsActivated(
int index)
const {
return this->slave_activation_status_[index] != 0; }
162 void updateMasterGroupNameOrderMap(
163 const std::string& slave_name,
const std::map<std::string, std::size_t>& master_group_map);
185 double getMasterActivationDate_()
const;
187 const Parallel::Communication &comm_;
188 const Schedule& schedule_;
192 bool activated_{
false};
194 std::vector<MPI_Comm> master_slave_comm_;
195 std::vector<std::string> slave_names_;
202 std::vector<double> slave_start_dates_;
204 std::vector<double> slave_activation_dates_;
205 double activation_date_{0.0};
208 std::map<std::string, std::map<std::string, std::size_t>> master_group_name_order_;
213 std::vector<std::uint8_t> slave_activation_status_;
215 std::map<std::string, std::string> master_group_slave_names_;
221 std::map<std::string, std::vector<std::string>> slave_name_to_master_groups_map_;
225 std::vector<std::vector<std::string>> slave_idx_to_master_groups_;
227 std::unique_ptr<ReservoirCouplingMasterReportStep<Scalar>> report_step_data_{
nullptr};
229 std::unique_ptr<ReservoirCouplingTimeStepper<Scalar>> time_stepper_{
nullptr};