opm-simulators
ReservoirCouplingTimeStepper.hpp
1 /*
2  Copyright 2025 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_TIME_STEPPER_HPP
21 #define OPM_RESERVOIR_COUPLING_TIME_STEPPER_HPP
22 
23 #include <opm/simulators/flow/rescoup/ReservoirCoupling.hpp>
24 #include <opm/input/eclipse/Schedule/Schedule.hpp>
25 #include <opm/simulators/utils/ParallelCommunication.hpp>
26 #include <opm/common/OpmLog/OpmLog.hpp>
27 
28 #include <mpi.h>
29 
30 #include <vector>
31 
32 namespace Opm {
33 
34 // Avoid including the complete definition of ReservoirCouplingMaster here to avoid circular dependency.
35 template <class Scalar> class ReservoirCouplingMaster;
36 
56 template <class Scalar>
58 public:
59  using MessageTag = ReservoirCoupling::MessageTag;
62 
67  );
68 
71  const Parallel::Communication &comm() const { return this->master_.getComm(); }
72 
76  MPI_Comm getSlaveComm(int index) const { return this->master_.getSlaveComm(index); }
77 
80  std::size_t numSlaves() const { return this->master_.numSlavesStarted(); }
81 
84  ReservoirCoupling::Logger& logger() const { return this->master_.logger(); }
85 
98  double maybeChopSubStep(double suggested_timestep_original, double elapsed_time) const;
99 
109 
112  void resizeNextReportDates(int size) { this->slave_next_report_time_offsets_.resize(size); }
113 
116  const Schedule& schedule() const { return this->master_.schedule(); }
117 
121  bool slaveIsActivated(int index) const { return this->master_.slaveIsActivated(index); }
122 
126  const std::string &slaveName(int index) const { return this->master_.getSlaveName(index); }
127 
131  double slaveStartDate(int index) const { return this->master_.getSlaveStartDate(index); }
132 
136  double slaveActivationDate(int index) const { return this->master_.getSlaveActivationDate(index); }
137 
147  void sendNextTimeStepToSlaves(double timestep);
148 
152  void setSlaveNextReportTimeOffset(int index, double offset) {
153  this->slave_next_report_time_offsets_[index] = offset;
154  }
155 
156 private:
159 
161  std::vector<double> slave_next_report_time_offsets_;
162 
165  std::map<std::string, std::vector<Potentials>> slave_group_potentials_;
166 };
167 } // namespace Opm
168 #endif // OPM_RESERVOIR_COUPLING_TIME_STEPPER_HPP
ReservoirCouplingTimeStepper(ReservoirCouplingMaster< Scalar > &master)
Construct a time stepper for coordinating master-slave time stepping.
Definition: ReservoirCouplingTimeStepper.cpp:41
Manages time stepping coordination between master and slave processes.
Definition: ReservoirCouplingTimeStepper.hpp:57
void sendNextTimeStepToSlaves(double timestep)
Send the next time step size to all active slave processes.
Definition: ReservoirCouplingTimeStepper.cpp:146
void receiveNextReportDateFromSlaves()
Receive next report dates from all active slave processes.
Definition: ReservoirCouplingTimeStepper.cpp:105
const Schedule & schedule() const
Get the simulation schedule.
Definition: ReservoirCouplingTimeStepper.hpp:116
Definition: ReservoirCoupling.hpp:42
void setSlaveNextReportTimeOffset(int index, double offset)
Set the next report time offset for a specific slave.
Definition: ReservoirCouplingTimeStepper.hpp:152
bool slaveIsActivated(int index) const
Check if a specific slave process has been activated.
Definition: ReservoirCouplingTimeStepper.hpp:121
const std::string & slaveName(int index) const
Get the name of a specific slave process.
Definition: ReservoirCouplingTimeStepper.hpp:126
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Utility class for comparing double values representing epoch dates or elapsed time.
Definition: ReservoirCoupling.hpp:305
void resizeNextReportDates(int size)
Resize the internal storage for slave next report times.
Definition: ReservoirCouplingTimeStepper.hpp:112
Definition: ReservoirCoupling.hpp:187
MPI_Comm getSlaveComm(int index) const
Get the MPI communicator for a specific slave process.
Definition: ReservoirCouplingTimeStepper.hpp:76
std::size_t numSlaves() const
Get the total number of active slave processes.
Definition: ReservoirCouplingTimeStepper.hpp:80
Definition: ReservoirCouplingMaster.hpp:38
double slaveActivationDate(int index) const
Get the activation date for a specific slave.
Definition: ReservoirCouplingTimeStepper.hpp:136
double maybeChopSubStep(double suggested_timestep_original, double elapsed_time) const
Potentially adjust time step to align with slave report boundaries.
Definition: ReservoirCouplingTimeStepper.cpp:56
double slaveStartDate(int index) const
Get the simulation start date for a specific slave.
Definition: ReservoirCouplingTimeStepper.hpp:131
ReservoirCoupling::Logger & logger() const
Get the logger for reservoir coupling operations.
Definition: ReservoirCouplingTimeStepper.hpp:84
const Parallel::Communication & comm() const
Get the MPI communicator for master-to-master communication.
Definition: ReservoirCouplingTimeStepper.hpp:71