2024-06-21 01:55:00 -05:00
|
|
|
/*
|
2024-12-07 09:28:09 -06:00
|
|
|
Copyright 2024 Equinor ASA
|
2024-06-21 01:55:00 -05:00
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPM_RESERVOIR_COUPLING_MASTER_HPP
|
|
|
|
#define OPM_RESERVOIR_COUPLING_MASTER_HPP
|
|
|
|
|
|
|
|
#include <opm/simulators/utils/ParallelCommunication.hpp>
|
2024-08-12 08:17:38 -05:00
|
|
|
#include <opm/simulators/flow/ReservoirCoupling.hpp>
|
2024-06-21 01:55:00 -05:00
|
|
|
#include <opm/input/eclipse/Schedule/Schedule.hpp>
|
|
|
|
#include <opm/common/OpmLog/OpmLog.hpp>
|
|
|
|
|
|
|
|
#include <mpi.h>
|
|
|
|
|
2024-06-28 07:10:55 -05:00
|
|
|
#include <filesystem>
|
2024-06-21 01:55:00 -05:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Opm {
|
|
|
|
|
|
|
|
class ReservoirCouplingMaster {
|
|
|
|
public:
|
2024-08-12 08:17:38 -05:00
|
|
|
using MessageTag = ReservoirCoupling::MessageTag;
|
2024-12-02 15:30:21 -06:00
|
|
|
using Seconds = ReservoirCoupling::Seconds;
|
2024-11-21 04:18:20 -06:00
|
|
|
ReservoirCouplingMaster(
|
|
|
|
const Parallel::Communication &comm,
|
|
|
|
const Schedule &schedule,
|
|
|
|
int argc, char **argv
|
|
|
|
);
|
2024-06-21 01:55:00 -05:00
|
|
|
|
2024-11-21 04:18:20 -06:00
|
|
|
bool activated() { return this->numSlavesStarted() > 0; }
|
2024-12-02 07:05:17 -06:00
|
|
|
void addSlaveCommunicator(MPI_Comm comm) {
|
|
|
|
this->master_slave_comm_.push_back(comm);
|
2024-11-21 04:18:20 -06:00
|
|
|
}
|
|
|
|
void addSlaveName(const std::string &name) { this->slave_names_.push_back(name); }
|
|
|
|
void addSlaveStartDate(std::time_t date) { this->slave_start_dates_.push_back(date); }
|
|
|
|
double getActivationDate() const { return this->activation_date_; }
|
|
|
|
int getArgc() const { return this->argc_; }
|
|
|
|
char *getArgv(int index) const { return this->argv_[index]; }
|
|
|
|
char **getArgv() const { return this->argv_; }
|
|
|
|
const Parallel::Communication &getComm() const { return this->comm_; }
|
|
|
|
double getSimulationStartDate() const { return this->schedule_.getStartTime(); }
|
2024-12-02 07:05:17 -06:00
|
|
|
MPI_Comm getSlaveComm(int index) const { return this->master_slave_comm_[index]; }
|
2024-11-21 04:18:20 -06:00
|
|
|
const std::string &getSlaveName(int index) const { return this->slave_names_[index]; }
|
|
|
|
const double *getSlaveStartDates() { return this->slave_start_dates_.data(); }
|
2024-08-19 16:45:56 -05:00
|
|
|
double maybeChopSubStep(double suggested_timestep, double current_time) const;
|
2024-11-21 04:18:20 -06:00
|
|
|
void maybeSpawnSlaveProcesses(int report_step);
|
|
|
|
std::size_t numSlavesStarted() const;
|
2024-08-19 16:45:56 -05:00
|
|
|
void receiveNextReportDateFromSlaves();
|
2024-11-21 04:18:20 -06:00
|
|
|
void resizeSlaveStartDates(int size) { this->slave_start_dates_.resize(size); }
|
|
|
|
void resizeNextReportDates(int size) { this->slave_next_report_time_offsets_.resize(size); }
|
2024-08-19 16:45:56 -05:00
|
|
|
void sendNextTimeStepToSlaves(double next_time_step);
|
2024-06-21 01:55:00 -05:00
|
|
|
|
|
|
|
private:
|
2024-11-21 04:18:20 -06:00
|
|
|
double getMasterActivationDate_() const;
|
2024-06-28 07:10:55 -05:00
|
|
|
|
2024-06-21 01:55:00 -05:00
|
|
|
const Parallel::Communication &comm_;
|
|
|
|
const Schedule& schedule_;
|
2024-11-21 04:18:20 -06:00
|
|
|
int argc_;
|
|
|
|
char **argv_;
|
2024-12-02 07:05:17 -06:00
|
|
|
// NOTE: MPI_Comm is just an integer handle, so we can just copy it into the vector
|
|
|
|
std::vector<MPI_Comm> master_slave_comm_; // MPI communicators for the slave processes
|
2024-06-21 01:55:00 -05:00
|
|
|
std::vector<std::string> slave_names_;
|
2024-11-21 04:18:20 -06:00
|
|
|
// The start dates are in whole seconds since the epoch. We use a double to store the value
|
|
|
|
// since both schedule_.getStartTime() and schedule_.stepLength(report_step) returns
|
|
|
|
// a double value representing whole seconds.
|
|
|
|
// However, note that schedule_[report_step].start_time() returns a time_point
|
|
|
|
// which can include milliseconds. The double values are also convenient when we need to
|
|
|
|
// to add fractions of seconds for sub steps to the start date.
|
|
|
|
std::vector<double> slave_start_dates_;
|
|
|
|
// Elapsed time from the beginning of the simulation
|
|
|
|
std::vector<double> slave_next_report_time_offsets_;
|
|
|
|
double activation_date_{0.0}; // The date when SLAVES is encountered in the schedule
|
2024-06-21 01:55:00 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Opm
|
|
|
|
#endif // OPM_RESERVOIR_COUPLING_MASTER_HPP
|