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 void error(
const std::string &msg)
const;
52 bool haveDeferredLogger()
const {
return deferred_logger_ !=
nullptr; }
53 void info(
const std::string &msg)
const;
54 void warning(
const std::string &msg)
const;
55 void setDeferredLogger(
DeferredLogger *deferred_logger) { deferred_logger_ = deferred_logger; }
58 template<
typename DeferredFn,
typename OpmLogFn>
59 void forward_(
const std::string &msg, DeferredFn deferred_fn, OpmLogFn opmlog_fn)
const;
61 const Parallel::Communication& comm_;
97 logger_->setDeferredLogger(deferred_logger);
103 logger_->clearDeferredLogger();
113 : logger_(other.logger_)
116 other.logger_ =
nullptr;
120 if (
this != &other) {
123 logger_->clearDeferredLogger();
126 logger_ = other.logger_;
127 other.logger_ =
nullptr;
138 enum class MessageTag : int {
139 CoupledNetworkActiveStatus,
140 InjectionGroupTargets,
142 MasterGroupNamesSize,
143 MasterGroupNodePressures,
145 MasterStartOfReportStep,
146 NumMasterGroupNodePressures,
147 NumSlaveGroupConstraints,
150 SlaveActivationHandshake,
152 SlaveProcessTermination,
158 SlaveSimulationStartDate,
159 SlaveStartOfReportStep,
165 enum class Phase : std::size_t {
177 enum class RateKind {
181 ProductionNetworkSurface,
185 template <
class Scalar>
189 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)]; }
195 template <
class Scalar>
197 std::array<Scalar, static_cast<std::size_t>(Phase::Count)> rate{};
199 [[nodiscard]] Scalar& operator[](Phase p) noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
200 [[nodiscard]] Scalar operator[](Phase p)
const noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
203 template <
class Scalar>
208 : rate{
static_cast<Scalar
>(rate_vector.oil_rat),
209 static_cast<Scalar>(rate_vector.gas_rat),
210 static_cast<Scalar
>(rate_vector.wat_rat)}
213 std::array<Scalar, static_cast<std::size_t>(Phase::Count)> rate{};
214 [[nodiscard]] Scalar& operator[](Phase p) noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
215 [[nodiscard]] Scalar operator[](Phase p)
const noexcept {
return rate[
static_cast<std::size_t
>(p)]; }
219 template <
class Scalar>
232 Scalar voidage_rate{0.0};
233 Scalar gas_reinjection_rate{0.0};
237 template <
class Scalar>
243 template <
class Scalar>
247 std::size_t group_name_idx;
249 Group::InjectionCMode cmode;
253 template <
class Scalar>
257 std::size_t group_name_idx;
259 Group::ProductionCMode cmode;
271 template <
class Scalar>
273 Scalar oil_limit{-1};
274 Scalar water_limit{-1};
275 Scalar gas_limit{-1};
276 Scalar liquid_limit{-1};
277 Scalar resv_limit{-1};
286 template <
class Scalar>
290 std::size_t group_name_idx;
295 Phase convertPhaseToReservoirCouplingPhase(::Opm::Phase phase);
296 ::Opm::Phase convertToOpmPhase(
const Phase phase);
297 void customErrorHandler_(MPI_Comm* comm,
int* err,
const std::string &msg);
298 void customErrorHandlerSlave_(MPI_Comm* comm,
int* err, ...);
299 void customErrorHandlerMaster_(MPI_Comm* comm,
int* err, ...);
300 void setErrhandler(MPI_Comm comm,
bool is_master);
301 std::pair<std::vector<char>, std::size_t> serializeStrings(
const std::vector<std::string>& data);
306 inline std::string formatDays(
double seconds) {
307 double days = seconds / unit::day;
308 return fmt::format(fmt::runtime(
"{:.0f}s ({:.2f} days)"), seconds, days);
387 #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:177
static bool compare_gt(double a, double b)
Determines if a is greater than b within the specified tolerance.
Definition: ReservoirCoupling.cpp:198
Master-computed network-leaf node pressure for a single master group.
Definition: ReservoirCoupling.hpp:287
Definition: ReservoirCoupling.hpp:186
Definition: ReservoirCoupling.hpp:42
Definition: ReservoirCoupling.hpp:238
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: ReservoirCoupling.hpp:204
Utility class for comparing double values representing epoch dates or elapsed time.
Definition: ReservoirCoupling.hpp:328
Definition: ReservoirCoupling.hpp:196
Definition: DeferredLogger.hpp:56
static constexpr double abstol
Absolute tolerance used for comparisons.
Definition: ReservoirCoupling.hpp:330
static bool compare_lt(double a, double b)
Determines if a is less than b within the specified tolerance.
Definition: ReservoirCoupling.cpp:192
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:204
Definition: ReservoirCoupling.hpp:254
Per-rate-type production limits received from master hierarchy.
Definition: ReservoirCoupling.hpp:272
Definition: ReservoirCoupling.hpp:244
static constexpr double reltol
Relative tolerance used for comparisons.
Definition: ReservoirCoupling.hpp:333
Guard for managing DeferredLogger lifecycle in ReservoirCoupling.
Definition: ReservoirCoupling.hpp:92
Definition: ReservoirCoupling.hpp:220
static bool compare_gt_or_eq(double a, double b)
Determines if a is greater than b within the specified tolerance.
Definition: ReservoirCoupling.cpp:183