ReservoirCoupling.hpp
Go to the documentation of this file.
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_HPP
21#define OPM_RESERVOIR_COUPLING_HPP
23
24#include <dune/common/parallel/mpitraits.hh>
25
26#include <mpi.h>
27#include <cmath>
28#include <iostream>
29#include <memory>
30#include <vector>
31
32namespace Opm {
33namespace ReservoirCoupling {
34
35class Logger {
36public:
37 Logger() = default;
38 void clearDeferredLogger() { deferred_logger_ = nullptr; }
39 bool haveDeferredLogger() const { return deferred_logger_ != nullptr; }
40 void info(const std::string &msg) const;
41 void setDeferredLogger(DeferredLogger *deferred_logger) { deferred_logger_ = deferred_logger; }
42
43private:
44 DeferredLogger *deferred_logger_ = nullptr;
45};
46
47enum class MessageTag : int {
60};
61
62// Used to communicate potentials for oil, gas, and water rates between slave and master processes
63struct Potentials {
64 enum class Phase : std::size_t { Oil = 0, Gas, Water, Count };
65
66 std::array<double, static_cast<std::size_t>(Phase::Count)> rate{};
67
68 [[nodiscard]] double& operator[](Phase p) noexcept { return rate[static_cast<std::size_t>(p)]; }
69 [[nodiscard]] double operator[](Phase p) const noexcept { return rate[static_cast<std::size_t>(p)]; }
70};
71
72
73// Helper functions
74void custom_error_handler_(MPI_Comm* comm, int* err, const std::string &msg);
75void setErrhandler(MPI_Comm comm, bool is_master);
76std::pair<std::vector<char>, std::size_t> serializeStrings(const std::vector<std::string>& data);
77
95struct Seconds {
97 static constexpr double abstol = 1e-15;
98
100 static constexpr double reltol = 1e-15;
101
120 static bool compare_eq(double a, double b);
121
127 static bool compare_gt(double a, double b);
128
134 static bool compare_gt_or_eq(double a, double b);
135
141 static bool compare_lt(double a, double b);
142
148 static bool compare_lt_or_eq(double a, double b);
149};
150
151} // namespace ReservoirCoupling
152} // namespace Opm
153
154#endif // OPM_RESERVOIR_COUPLING_HPP
Definition: DeferredLogger.hpp:57
Definition: ReservoirCoupling.hpp:35
void info(const std::string &msg) const
void setDeferredLogger(DeferredLogger *deferred_logger)
Definition: ReservoirCoupling.hpp:41
void clearDeferredLogger()
Definition: ReservoirCoupling.hpp:38
bool haveDeferredLogger() const
Definition: ReservoirCoupling.hpp:39
std::pair< std::vector< char >, std::size_t > serializeStrings(const std::vector< std::string > &data)
MessageTag
Definition: ReservoirCoupling.hpp:47
void setErrhandler(MPI_Comm comm, bool is_master)
void custom_error_handler_(MPI_Comm *comm, int *err, const std::string &msg)
Definition: blackoilboundaryratevector.hh:39
Definition: ReservoirCoupling.hpp:63
double operator[](Phase p) const noexcept
Definition: ReservoirCoupling.hpp:69
double & operator[](Phase p) noexcept
Definition: ReservoirCoupling.hpp:68
std::array< double, static_cast< std::size_t >(Phase::Count)> rate
Definition: ReservoirCoupling.hpp:66
Phase
Definition: ReservoirCoupling.hpp:64
Utility class for comparing double values representing epoch dates or elapsed time.
Definition: ReservoirCoupling.hpp:95
static bool compare_gt_or_eq(double a, double b)
Determines if a is greater than b within the specified tolerance.
static bool compare_gt(double a, double b)
Determines if a is greater than b within the specified tolerance.
static bool compare_lt_or_eq(double a, double b)
Determines if a is less than or equal to b within the specified tolerance.
static bool compare_eq(double a, double b)
Determines if two double values are equal within a specified tolerance.
static constexpr double reltol
Relative tolerance used for comparisons.
Definition: ReservoirCoupling.hpp:100
static bool compare_lt(double a, double b)
Determines if a is less than b within the specified tolerance.
static constexpr double abstol
Absolute tolerance used for comparisons.
Definition: ReservoirCoupling.hpp:97