Loading...
Searching...
No Matches
ReservoirCoupling.hpp
/*
Copyright 2024 Equinor ASA
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_RESERVOIR_COUPLING_HPP
#define OPM_RESERVOIR_COUPLING_HPP
#include <opm/simulators/utils/DeferredLogger.hpp>
#include <dune/common/parallel/mpitraits.hh>
#include <mpi.h>
#include <cmath>
#include <iostream>
#include <memory>
#include <vector>
namespace Opm {
namespace ReservoirCoupling {
class Logger {
public:
Logger() = default;
void clearDeferredLogger() { deferred_logger_ = nullptr; }
bool haveDeferredLogger() const { return deferred_logger_ != nullptr; }
void info(const std::string &msg) const;
void setDeferredLogger(DeferredLogger *deferred_logger) { deferred_logger_ = deferred_logger; }
private:
DeferredLogger *deferred_logger_ = nullptr;
};
enum class MessageTag : int {
MasterGroupNames,
MasterGroupNamesSize,
Potentials,
PotentialsSize,
SlaveSimulationStartDate,
SlaveActivationDate,
SlaveActivationHandshake,
SlaveProcessTermination,
SlaveName,
SlaveNameSize,
SlaveNextReportDate,
SlaveNextTimeStep,
};
// Used to communicate potentials for oil, gas, and water rates between slave and master processes
struct Potentials {
enum class Phase : std::size_t { Oil = 0, Gas, Water, Count };
std::array<double, static_cast<std::size_t>(Phase::Count)> rate{};
[[nodiscard]] double& operator[](Phase p) noexcept { return rate[static_cast<std::size_t>(p)]; }
[[nodiscard]] double operator[](Phase p) const noexcept { return rate[static_cast<std::size_t>(p)]; }
};
// Helper functions
void custom_error_handler_(MPI_Comm* comm, int* err, const std::string &msg);
void setErrhandler(MPI_Comm comm, bool is_master);
std::pair<std::vector<char>, std::size_t> serializeStrings(const std::vector<std::string>& data);
struct Seconds {
static constexpr double abstol = 1e-15;
static constexpr double reltol = 1e-15;
static bool compare_eq(double a, double b);
static bool compare_gt(double a, double b);
static bool compare_gt_or_eq(double a, double b);
static bool compare_lt(double a, double b);
static bool compare_lt_or_eq(double a, double b);
};
} // namespace ReservoirCoupling
} // namespace Opm
#endif // OPM_RESERVOIR_COUPLING_HPP
Opm::DeferredLogger
Definition DeferredLogger.hpp:57
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::ReservoirCoupling::Potentials
Definition ReservoirCoupling.hpp:63
Opm::ReservoirCoupling::Seconds
Utility class for comparing double values representing epoch dates or elapsed time.
Definition ReservoirCoupling.hpp:95
Opm::ReservoirCoupling::Seconds::compare_eq
static bool compare_eq(double a, double b)
Determines if two double values are equal within a specified tolerance.
Definition ReservoirCoupling.cpp:114
Opm::ReservoirCoupling::Seconds::compare_gt
static bool compare_gt(double a, double b)
Determines if a is greater than b within the specified tolerance.
Definition ReservoirCoupling.cpp:135
Opm::ReservoirCoupling::Seconds::compare_lt_or_eq
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:141
Opm::ReservoirCoupling::Seconds::reltol
static constexpr double reltol
Relative tolerance used for comparisons.
Definition ReservoirCoupling.hpp:100
Opm::ReservoirCoupling::Seconds::compare_gt_or_eq
static bool compare_gt_or_eq(double a, double b)
Determines if a is greater than b within the specified tolerance.
Definition ReservoirCoupling.cpp:120
Opm::ReservoirCoupling::Seconds::compare_lt
static bool compare_lt(double a, double b)
Determines if a is less than b within the specified tolerance.
Definition ReservoirCoupling.cpp:129
Opm::ReservoirCoupling::Seconds::abstol
static constexpr double abstol
Absolute tolerance used for comparisons.
Definition ReservoirCoupling.hpp:97