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> 40 namespace 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_;
93 logger_->setDeferredLogger(deferred_logger);
99 logger_->clearDeferredLogger();
109 : logger_(other.logger_)
112 other.logger_ =
nullptr;
116 if (
this != &other) {
119 logger_->clearDeferredLogger();
122 logger_ = other.logger_;
123 other.logger_ =
nullptr;
134 enum class MessageTag : int {
135 InjectionGroupTargets,
137 MasterGroupNamesSize,
138 MasterStartOfReportStep,
139 NumSlaveGroupConstraints,
142 SlaveActivationHandshake,
144 SlaveProcessTermination,
150 SlaveSimulationStartDate,
151 SlaveStartOfReportStep,
156 enum class Phase : std::size_t {
168 enum class RateKind {
172 ProductionNetworkSurface,
176 template <
class Scalar>
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)]; }
186 template <
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)]; }
194 template <
class Scalar>
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)]; }
210 template <
class Scalar>
223 Scalar voidage_rate{0.0};
224 Scalar gas_reinjection_rate{0.0};
228 template <
class Scalar>
234 template <
class Scalar>
238 std::size_t group_name_idx;
240 Group::InjectionCMode cmode;
244 template <
class Scalar>
248 std::size_t group_name_idx;
250 Group::ProductionCMode cmode;
262 template <
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};
272 Phase convertPhaseToReservoirCouplingPhase(::Opm::Phase phase);
273 ::Opm::Phase convertToOpmPhase(
const Phase phase);
274 void customErrorHandler_(MPI_Comm* comm,
int* err,
const std::string &msg);
275 void customErrorHandlerSlave_(MPI_Comm* comm,
int* err, ...);
276 void customErrorHandlerMaster_(MPI_Comm* comm,
int* err, ...);
277 void setErrhandler(MPI_Comm comm,
bool is_master);
278 std::pair<std::vector<char>, std::size_t> serializeStrings(
const std::vector<std::string>& data);
283 inline std::string formatDays(
double seconds) {
284 double days = seconds / unit::day;
285 return fmt::format(fmt::runtime(
"{:.0f}s ({:.2f} days)"), seconds, days);
364 #endif // OPM_RESERVOIR_COUPLING_HPP 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
Definition: ReservoirCoupling.hpp:177
Definition: ReservoirCoupling.hpp:42
Definition: ReservoirCoupling.hpp:229
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Definition: ReservoirCoupling.hpp:195
Utility class for comparing double values representing epoch dates or elapsed time.
Definition: ReservoirCoupling.hpp:305
Definition: ReservoirCoupling.hpp:187
Definition: DeferredLogger.hpp:56
static constexpr double abstol
Absolute tolerance used for comparisons.
Definition: ReservoirCoupling.hpp:307
static bool compare_lt(double a, double b)
Determines if a is less than b within the specified tolerance.
Definition: ReservoirCoupling.cpp:188
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
Definition: ReservoirCoupling.hpp:245
Per-rate-type production limits received from master hierarchy.
Definition: ReservoirCoupling.hpp:263
Definition: ReservoirCoupling.hpp:235
static constexpr double reltol
Relative tolerance used for comparisons.
Definition: ReservoirCoupling.hpp:310
Guard for managing DeferredLogger lifecycle in ReservoirCoupling.
Definition: ReservoirCoupling.hpp:88
Definition: ReservoirCoupling.hpp:211
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