My Project
Loading...
Searching...
No Matches
ReservoirCouplingMaster.hpp
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
23#include <opm/simulators/utils/ParallelCommunication.hpp>
24#include <opm/simulators/flow/ReservoirCoupling.hpp>
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:
37 using MessageTag = ReservoirCoupling::MessageTag;
40 const Parallel::Communication &comm,
41 const Schedule &schedule,
42 int argc, char **argv
43 );
44
45 bool activated() { return this->numSlavesStarted() > 0; }
46 void addSlaveCommunicator(MPI_Comm comm) {
47 this->master_slave_comm_.push_back(comm);
48 }
49 void addSlaveName(const std::string &name) { this->slave_names_.push_back(name); }
50 void addSlaveNextReportTimeOffset(double offset) {
51 this->slave_next_report_time_offsets_.push_back(offset);
52 }
53 void addSlaveStartDate(std::time_t date) { this->slave_start_dates_.push_back(date); }
54 double getActivationDate() const { return this->activation_date_; }
55 int getArgc() const { return this->argc_; }
56 char *getArgv(int index) const { return this->argv_[index]; }
57 char **getArgv() const { return this->argv_; }
58 const Parallel::Communication &getComm() const { return this->comm_; }
59 double getSimulationStartDate() const { return this->schedule_.getStartTime(); }
60 MPI_Comm getSlaveComm(int index) const { return this->master_slave_comm_[index]; }
61 const std::string &getSlaveName(int index) const { return this->slave_names_[index]; }
62 const double *getSlaveStartDates() { return this->slave_start_dates_.data(); }
63 double maybeChopSubStep(double suggested_timestep, double current_time) const;
64 void maybeSpawnSlaveProcesses(int report_step);
65 std::size_t numSlavesStarted() const;
66 void receiveNextReportDateFromSlaves();
67 void resizeSlaveStartDates(int size) { this->slave_start_dates_.resize(size); }
68 void resizeNextReportDates(int size) { this->slave_next_report_time_offsets_.resize(size); }
69 void sendNextTimeStepToSlaves(double next_time_step);
70 // These are currently only used for unit testing
71 void setSlaveStartDate(int index, std::time_t date) { this->slave_start_dates_[index] = date; }
72 void setSlaveNextReportTimeOffset(int index, double offset) {
73 this->slave_next_report_time_offsets_[index] = offset;
74 }
75
76private:
77 double getMasterActivationDate_() const;
78
79 const Parallel::Communication &comm_;
80 const Schedule& schedule_;
81 int argc_;
82 char **argv_;
83 // NOTE: MPI_Comm is just an integer handle, so we can just copy it into the vector
84 std::vector<MPI_Comm> master_slave_comm_; // MPI communicators for the slave processes
85 std::vector<std::string> slave_names_;
86 // The start dates are in whole seconds since the epoch. We use a double to store the value
87 // since both schedule_.getStartTime() and schedule_.stepLength(report_step) returns
88 // a double value representing whole seconds.
89 // However, note that schedule_[report_step].start_time() returns a time_point
90 // which can include milliseconds. The double values are also convenient when we need to
91 // to add fractions of seconds for sub steps to the start date.
92 std::vector<double> slave_start_dates_;
93 // Elapsed time from the beginning of the simulation
94 std::vector<double> slave_next_report_time_offsets_;
95 double activation_date_{0.0}; // The date when SLAVES is encountered in the schedule
96};
97
98} // namespace Opm
99#endif // OPM_RESERVOIR_COUPLING_MASTER_HPP
Definition ReservoirCouplingMaster.hpp:35
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
Utility class for comparing double values representing epoch dates or elapsed time.
Definition ReservoirCoupling.hpp:61