20 #ifndef OPM_RESERVOIR_COUPLING_MASTER_HPP 21 #define OPM_RESERVOIR_COUPLING_MASTER_HPP 23 #include <opm/simulators/utils/ParallelCommunication.hpp> 24 #include <opm/simulators/flow/rescoup/ReservoirCoupling.hpp> 25 #include <opm/simulators/flow/rescoup/ReservoirCouplingMasterReportStep.hpp> 26 #include <opm/simulators/flow/rescoup/ReservoirCouplingTimeStepper.hpp> 27 #include <opm/input/eclipse/Schedule/Schedule.hpp> 28 #include <opm/common/OpmLog/OpmLog.hpp> 37 template <
class Scalar>
40 using MessageTag = ReservoirCoupling::MessageTag;
49 const Parallel::Communication &comm,
50 const Schedule &schedule,
54 bool activated() {
return this->activated_; }
55 void addSlaveCommunicator(MPI_Comm comm) {
56 this->master_slave_comm_.push_back(comm);
58 void addSlaveName(
const std::string &name) { this->slave_names_.push_back(name); }
59 void addSlaveActivationDate(
double date) { this->slave_activation_dates_.push_back(date); }
60 void addSlaveStartDate(std::time_t date) { this->slave_start_dates_.push_back(date); }
61 void clearDeferredLogger() { logger_.clearDeferredLogger(); }
75 const auto it = this->effective_gcw_.find(group_name);
76 return (it == this->effective_gcw_.end()) ? 1 : it->second;
78 void setEffectiveGCW(
const std::string& group_name,
int value) {
79 this->effective_gcw_[group_name] = value;
87 double getActivationDate()
const {
return this->activation_date_; }
88 int getArgc()
const {
return this->argc_; }
89 char *getArgv(
int index)
const {
return this->argv_[index]; }
90 char **getArgv()
const {
return this->argv_; }
91 const Parallel::Communication &getComm()
const {
return this->comm_; }
114 const std::string &slave_name,
const std::string &master_group_name)
const;
116 Scalar getMasterGroupRate(
117 const std::string &group_name, ReservoirCoupling::Phase phase, ReservoirCoupling::RateKind kind)
const;
118 std::map<std::string, std::string>& getMasterGroupToSlaveNameMap() {
119 return this->master_group_slave_names_;
121 double getSimulationStartDate()
const {
return this->schedule_.getStartTime(); }
122 double getSlaveActivationDate(
int index)
const {
return this->slave_activation_dates_[index]; }
123 const double *getSlaveActivationDates()
const {
return this->slave_activation_dates_.data(); }
124 MPI_Comm getSlaveComm(
int index)
const {
return this->master_slave_comm_[index]; }
125 std::map<std::string, std::vector<std::string>> &getSlaveNameToMasterGroupsMap() {
126 return this->slave_name_to_master_groups_map_;
128 const Potentials& getSlaveGroupPotentials(
const std::string &master_group_name);
129 int getSlaveIdx(
const std::string &slave_name)
const;
130 const std::string &getSlaveName(
int index)
const {
return this->slave_names_[index]; }
131 double getSlaveStartDate(
int index)
const {
return this->slave_start_dates_[index]; }
132 const double *getSlaveStartDates() {
return this->slave_start_dates_.data(); }
133 void initStartOfReportStep(
int report_step_idx);
134 void initTimeStepping();
135 bool isFirstSubstepOfSyncTimestep()
const;
136 bool isMasterGroup(
const std::string &group_name)
const;
151 ReservoirCoupling::Logger& logger() {
return this->logger_; }
152 ReservoirCoupling::Logger& logger()
const {
return this->logger_; }
153 void maybeActivate(
int report_step);
154 void maybeReceiveActivationHandshakeFromSlaves(
double current_time);
155 double maybeChopSubStep(
double suggested_timestep,
double current_time)
const;
156 void maybeSpawnSlaveProcesses(
int report_step);
157 std::size_t numSlaveGroups(
unsigned int index);
158 std::size_t numSlaves()
const {
return this->numSlavesStarted(); }
159 std::size_t numSlavesStarted()
const;
160 std::size_t numActivatedSlaves()
const;
161 void rebuildSlaveIdxToMasterGroupsVector();
162 void receiveNextReportDateFromSlaves();
163 void receiveProductionDataFromSlaves();
164 void receiveInjectionDataFromSlaves();
165 void resizeNextReportDates(
int size);
166 void resizeSlaveActivationDates(
int size) { this->slave_activation_dates_.resize(size); }
167 void resizeSlaveStartDates(
int size) { this->slave_start_dates_.resize(size); }
168 const Schedule& schedule()
const {
return this->schedule_; }
169 void sendNextTimeStepToSlaves(
double next_time_step) {
170 this->time_stepper_->sendNextTimeStepToSlaves(next_time_step);
176 std::size_t slave_idx,
179 void sendInjectionTargetsToSlave(
180 std::size_t slave_idx,
181 const std::vector<InjectionGroupTarget>& injection_targets
186 std::size_t slave_idx,
187 const std::vector<MasterGroupNodePressure>& pressures
189 void sendNumGroupConstraintsToSlave(
190 std::size_t slave_idx,
191 std::size_t num_injection_targets,
192 std::size_t num_production_constraints
198 std::size_t slave_idx,
199 std::size_t num_pressures,
202 void sendProductionConstraintsToSlave(
203 std::size_t slave_idx,
204 const std::vector<ProductionGroupConstraints>& production_constraints
206 void setDeferredLogger(DeferredLogger *deferred_logger) {
207 this->logger_.setDeferredLogger(deferred_logger);
209 void setFirstSubstepOfSyncTimestep(
bool value);
216 void setSlaveActivationDate(
int index,
double date) { this->slave_activation_dates_[index] = date; }
217 void setSlaveNextReportTimeOffset(
int index,
double offset);
218 void setSlaveStartDate(
int index, std::time_t date) { this->slave_start_dates_[index] = date; }
219 bool slaveIsActivated(
int index)
const {
return this->slave_activation_status_[index] != 0; }
226 void updateMasterGroupNameOrderMap(
227 const std::string& slave_name,
const std::map<std::string, std::size_t>& master_group_map);
249 double getMasterActivationDate_()
const;
251 const Parallel::Communication &comm_;
252 const Schedule& schedule_;
256 bool activated_{
false};
259 std::vector<MPI_Comm> master_slave_comm_;
260 std::vector<std::string> slave_names_;
268 std::vector<double> slave_start_dates_;
271 std::vector<double> slave_activation_dates_;
272 double activation_date_{0.0};
276 std::map<std::string, std::map<std::string, std::size_t>> master_group_name_order_;
281 std::map<std::string, int> effective_gcw_;
283 mutable ReservoirCoupling::Logger logger_;
288 std::vector<std::uint8_t> slave_activation_status_;
291 std::map<std::string, std::string> master_group_slave_names_;
298 std::map<std::string, std::vector<std::string>> slave_name_to_master_groups_map_;
303 std::vector<std::vector<std::string>> slave_idx_to_master_groups_;
306 std::unique_ptr<ReservoirCouplingMasterReportStep<Scalar>> report_step_data_{
nullptr};
309 std::unique_ptr<ReservoirCouplingTimeStepper<Scalar>> time_stepper_{
nullptr};
314 bool sync_at_report_steps_{
false};
319 #endif // OPM_RESERVOIR_COUPLING_MASTER_HPP bool needsSlaveDataReceive() const
Check if the master needs to receive production data from the slaves.
Definition: ReservoirCouplingMaster.cpp:189
data::ReservoirCouplingGroupRates collectGroupRatesForSummary() const
Collect production/injection rates for all master groups.
Definition: ReservoirCouplingMaster.cpp:557
Master-computed network-leaf node pressure for a single master group.
Definition: ReservoirCoupling.hpp:287
std::size_t getMasterGroupCanonicalIdx(const std::string &slave_name, const std::string &master_group_name) const
Get the canonical index of the master group for a given slave name and master group name...
Definition: ReservoirCouplingMaster.cpp:102
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...
Definition: ReservoirCouplingMaster.cpp:462
bool syncAtReportSteps() const
Whether the master syncs with slaves at slave report-step boundaries (true) or at every master actual...
Definition: ReservoirCouplingMaster.hpp:225
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
void sendMasterGroupNodePressuresToSlave(std::size_t slave_idx, const std::vector< MasterGroupNodePressure > &pressures) const
Send master-computed network-leaf node pressures to a slave.
Definition: ReservoirCouplingMaster.cpp:452
Utility class for comparing double values representing epoch dates or elapsed time.
Definition: ReservoirCoupling.hpp:328
void sendDontTerminateSignalToSlaves()
Send "don't terminate" signal (value=0) to all active slaves.
Definition: ReservoirCouplingMaster.cpp:405
void sendTerminateAndDisconnect()
Send terminate signal to all active slaves and disconnect intercommunicators.
Definition: ReservoirCouplingMaster.cpp:504
const std::vector< std::string > & getMasterGroupNamesForSlave(std::size_t slave_idx) const
Get the master group names associated with a slave reservoir by index.
Definition: ReservoirCouplingMaster.cpp:83
Definition: ReservoirCoupling.hpp:196
int effectiveGCW(const std::string &group_name) const
Effective group-controlled-wells (GCW) count for a master group, used by guide-rate distribution inde...
Definition: ReservoirCouplingMaster.hpp:74
void resetEffectiveGCW()
Clear all effective-GCW entries.
Definition: ReservoirCouplingMaster.hpp:85
Definition: ReservoirCoupling.hpp:254
Definition: ReservoirCouplingMaster.hpp:38
void setNeedsSlaveDataReceive(bool value)
Set whether the master needs to receive production data from the slaves.
Definition: ReservoirCouplingMaster.cpp:198
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 plus the master's is_final flag for thi...
Definition: ReservoirCouplingMaster.cpp:482
Definition: ReservoirCoupling.hpp:244
Definition: ReservoirCoupling.hpp:220