20#ifndef OPM_RESERVOIR_COUPLING_HPP
21#define OPM_RESERVOIR_COUPLING_HPP
22#include <opm/simulators/utils/DeferredLogger.hpp>
23#include <opm/simulators/utils/ParallelCommunication.hpp>
24#include <opm/input/eclipse/Schedule/Group/Group.hpp>
25#include <opm/input/eclipse/Schedule/Group/GuideRate.hpp>
26#include <opm/input/eclipse/Units/Units.hpp>
28#include <dune/common/parallel/mpitraits.hh>
30#include <fmt/format.h>
40namespace ReservoirCoupling {
45 explicit Logger(
const Parallel::Communication& comm) : comm_(comm) {}
47 void clearDeferredLogger() { deferred_logger_ =
nullptr; }
48 void debug(
const std::string &msg)
const;
50 DeferredLogger& deferredLogger()
const {
return *deferred_logger_; }
51 bool haveDeferredLogger()
const {
return deferred_logger_ !=
nullptr; }
52 void info(
const std::string &msg)
const;
53 void warning(
const std::string &msg)
const;
54 void setDeferredLogger(
DeferredLogger *deferred_logger) { deferred_logger_ = deferred_logger; }
57 const Parallel::Communication& comm_;
88class ScopedLoggerGuard {
93 logger_->setDeferredLogger(deferred_logger);
96 ~ScopedLoggerGuard() {
99 logger_->clearDeferredLogger();
104 ScopedLoggerGuard(
const ScopedLoggerGuard&) =
delete;
105 ScopedLoggerGuard& operator=(
const ScopedLoggerGuard&) =
delete;
108 ScopedLoggerGuard(ScopedLoggerGuard&& other) noexcept
109 : logger_(other.logger_)
112 other.logger_ =
nullptr;
115 ScopedLoggerGuard& operator=(ScopedLoggerGuard&& other)
noexcept {
116 if (
this != &other) {
119 logger_->clearDeferredLogger();
122 logger_ = other.logger_;
123 other.logger_ =
nullptr;
134enum class MessageTag :
int {
135 InjectionGroupTargets,
137 MasterGroupNamesSize,
138 MasterStartOfReportStep,
139 NumSlaveGroupConstraints,
142 SlaveActivationHandshake,
144 SlaveProcessTermination,
150 SlaveSimulationStartDate,
151 SlaveStartOfReportStep,
156enum class Phase : std::size_t {
172 ProductionNetworkSurface,
176template <
class Scalar>
177struct InjectionRates {
178 InjectionRates() =
default;
180 std::array<Scalar, static_cast<std::size_t>(Phase::Count)> rate{};
181 [[nodiscard]] Scalar& operator[](Phase p)
noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
182 [[nodiscard]] Scalar operator[](Phase p)
const noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
186template <
class Scalar>
188 std::array<Scalar, static_cast<std::size_t>(Phase::Count)> rate{};
190 [[nodiscard]] Scalar& operator[](Phase p)
noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
191 [[nodiscard]] Scalar operator[](Phase p)
const noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
194template <
class Scalar>
195struct ProductionRates {
196 ProductionRates() =
default;
198 explicit ProductionRates(
const GuideRate::RateVector& rate_vector)
199 : rate{
static_cast<Scalar
>(rate_vector.oil_rat),
200 static_cast<Scalar
>(rate_vector.gas_rat),
201 static_cast<Scalar
>(rate_vector.wat_rat)}
204 std::array<Scalar, static_cast<std::size_t>(Phase::Count)> rate{};
205 [[nodiscard]] Scalar& operator[](Phase p)
noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
206 [[nodiscard]] Scalar operator[](Phase p)
const noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
210template <
class Scalar>
223 Scalar voidage_rate{0.0};
224 Scalar gas_reinjection_rate{0.0};
228template <
class Scalar>
234template <
class Scalar>
238 std::size_t group_name_idx;
240 Group::InjectionCMode cmode;
244template <
class Scalar>
248 std::size_t group_name_idx;
250 Group::ProductionCMode cmode;
262template <
class Scalar>
264 Scalar oil_limit{-1};
265 Scalar water_limit{-1};
266 Scalar gas_limit{-1};
267 Scalar liquid_limit{-1};
268 Scalar resv_limit{-1};
272Phase convertPhaseToReservoirCouplingPhase(::Opm::Phase phase);
273::Opm::Phase convertToOpmPhase(
const Phase phase);
274void customErrorHandler_(MPI_Comm* comm,
int* err,
const std::string &msg);
275void customErrorHandlerSlave_(MPI_Comm* comm,
int* err, ...);
276void customErrorHandlerMaster_(MPI_Comm* comm,
int* err, ...);
277void setErrhandler(MPI_Comm comm,
bool is_master);
278std::pair<std::vector<char>, std::size_t> serializeStrings(
const std::vector<std::string>& data);
283inline std::string formatDays(
double seconds) {
284 double days = seconds / unit::day;
285 return fmt::format(fmt::runtime(
"{:.0f}s ({:.2f} days)"), seconds, days);
Definition DeferredLogger.hpp:57
Definition ReservoirCoupling.hpp:42
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:45
Definition ReservoirCoupling.hpp:235
Definition ReservoirCoupling.hpp:177
Per-rate-type production limits received from master hierarchy.
Definition ReservoirCoupling.hpp:263
Definition ReservoirCoupling.hpp:187
Definition ReservoirCoupling.hpp:245
Definition ReservoirCoupling.hpp:195
Utility class for comparing double values representing epoch dates or elapsed time.
Definition ReservoirCoupling.hpp:305
static bool compare_eq(double a, double b)
Determines if two double values are equal within a specified tolerance.
Definition ReservoirCoupling.cpp:173
static bool compare_gt(double a, double b)
Determines if a is greater than b within the specified tolerance.
Definition ReservoirCoupling.cpp:194
static bool compare_lt_or_eq(double a, double b)
Determines if a is less than or equal to b within the specified tolerance.
Definition ReservoirCoupling.cpp:200
static constexpr double reltol
Relative tolerance used for comparisons.
Definition ReservoirCoupling.hpp:310
static bool compare_gt_or_eq(double a, double b)
Determines if a is greater than b within the specified tolerance.
Definition ReservoirCoupling.cpp:179
static bool compare_lt(double a, double b)
Determines if a is less than b within the specified tolerance.
Definition ReservoirCoupling.cpp:188
static constexpr double abstol
Absolute tolerance used for comparisons.
Definition ReservoirCoupling.hpp:307
Definition ReservoirCoupling.hpp:229
Definition ReservoirCoupling.hpp:211