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 {
59};
60
61// Used to communicate potentials for oil, gas, and water rates between slave and master processes
62struct Potentials {
63 enum class Phase : std::size_t { Oil = 0, Gas, Water, Count };
64
65 std::array<double, static_cast<std::size_t>(Phase::Count)> rate{};
66
67 [[nodiscard]] double& operator[](Phase p) noexcept { return rate[static_cast<std::size_t>(p)]; }
68 [[nodiscard]] double operator[](Phase p) const noexcept { return rate[static_cast<std::size_t>(p)]; }
69};
70
71
72// Helper functions
73void custom_error_handler_(MPI_Comm* comm, int* err, const std::string &msg);
74void setErrhandler(MPI_Comm comm, bool is_master);
75std::pair<std::vector<char>, std::size_t> serializeStrings(const std::vector<std::string>& data);
76
94struct Seconds {
96 static constexpr double abstol = 1e-15;
97
99 static constexpr double reltol = 1e-15;
100
119 static bool compare_eq(double a, double b);
120
126 static bool compare_gt(double a, double b);
127
133 static bool compare_gt_or_eq(double a, double b);
134
140 static bool compare_lt_or_eq(double a, double b);
141};
142
143} // namespace ReservoirCoupling
144} // namespace Opm
145
146#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:62
double operator[](Phase p) const noexcept
Definition: ReservoirCoupling.hpp:68
double & operator[](Phase p) noexcept
Definition: ReservoirCoupling.hpp:67
std::array< double, static_cast< std::size_t >(Phase::Count)> rate
Definition: ReservoirCoupling.hpp:65
Phase
Definition: ReservoirCoupling.hpp:63
Utility class for comparing double values representing epoch dates or elapsed time.
Definition: ReservoirCoupling.hpp:94
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:99
static constexpr double abstol
Absolute tolerance used for comparisons.
Definition: ReservoirCoupling.hpp:96