Loading...
Searching...
No Matches
InterRegFlowMap.hpp
Go to the documentation of this file.
/*
Copyright 2016 SINTEF ICT, Applied Mathematics.
Copyright 2016 Statoil ASA.
Copyright 2022 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_OUTPUT_DATA_INTERREGFLOWMAP_HPP
#define OPM_OUTPUT_DATA_INTERREGFLOWMAP_HPP
#include <opm/output/data/InterRegFlow.hpp>
#include <opm/common/utility/CSRGraphFromCoordinates.hpp>
#include <cstddef>
#include <optional>
#include <utility>
#include <type_traits>
#include <vector>
namespace Opm { namespace data {
class InterRegFlowMap
{
private:
using Neighbours = std::vector<int>;
using Offset = Neighbours::size_type;
using Start = std::vector<Offset>;
using RateBuffer = std::vector<float>;
using Window = InterRegFlow<RateBuffer::iterator>;
public:
using ReadOnlyWindow = InterRegFlow<std::vector<float>::const_iterator>;
using FlowRates = Window::FlowRates;
using Component = Window::Component;
void addConnection(const int r1, const int r2, const FlowRates& rates);
void compress(const std::size_t numRegions);
Offset numRegions() const;
std::optional<std::pair<ReadOnlyWindow, ReadOnlyWindow::ElmT>>
getInterRegFlows(const int r1, const int r2) const;
// MessageBufferType API should be similar to Dune::MessageBufferIF
template <class MessageBufferType>
void write(MessageBufferType& buffer) const
{
this->connections_.write(buffer);
this->writeVector(this->rates_, buffer);
}
// MessageBufferType API should be similar to Dune::MessageBufferIF
template <class MessageBufferType>
void read(MessageBufferType& buffer)
{
this->connections_.read(buffer);
auto rates = RateBuffer{};
this->readVector(buffer, rates);
this->appendRates(rates);
}
void clear();
private:
// VertexID = int, TrackCompressedIdx = true.
using Graph = utility::CSRGraphFromCoordinates<int, true>;
Graph connections_{};
RateBuffer rates_{};
template <typename T, class A, class MessageBufferType>
void writeVector(const std::vector<T,A>& vec,
MessageBufferType& buffer) const
{
const auto n = vec.size();
buffer.write(n);
for (const auto& x : vec) {
buffer.write(x);
}
}
template <typename T, class A, class MessageBufferType>
void readVector(MessageBufferType& buffer,
std::vector<T,A>& vec)
{
auto n = 0 * vec.size();
buffer.read(n);
vec.resize(n);
for (auto& x : vec) {
buffer.read(x);
}
}
template <typename Rates>
void appendRates(const Rates& rates)
{
this->rates_.insert(this->rates_.end(), rates.begin(), rates.end());
}
};
}} // namespace Opm::data
#endif // OPM_OUTPUT_DATA_INTERREGFLOWMAP_HPP
CSRGraphFromCoordinates.hpp
Facility for converting collection of region ID pairs into a sparse (CSR) adjacency matrix representa...
Opm::data::InterRegFlowMap
Form CSR adjacency matrix representation of inter-region flow rate graph provided as a list of connec...
Definition InterRegFlowMap.hpp:47
Opm::data::InterRegFlowMap::numRegions
Offset numRegions() const
Retrieve number of rows (source entities) in input graph.
Definition InterRegFlowMap.cpp:113
Opm::data::InterRegFlowMap::compress
void compress(const std::size_t numRegions)
Form CSR adjacency matrix representation of input graph from connections established in previous call...
Definition InterRegFlowMap.cpp:76
Opm::data::InterRegFlowMap::clear
void clear()
Clear all internal buffers, but preserve allocated capacity.
Definition InterRegFlowMap.cpp:170
Opm::data::InterRegFlowMap::addConnection
void addConnection(const int r1, const int r2, const FlowRates &rates)
Add flow rate connection between regions.
Definition InterRegFlowMap.cpp:44
Opm::data::InterRegFlowMap::Component
Window::Component Component
Client type through which to identify a component flow of a single inter-region connection.
Definition InterRegFlowMap.hpp:73
Opm::data::InterRegFlowMap::getInterRegFlows
std::optional< std::pair< ReadOnlyWindow, ReadOnlyWindow::ElmT > > getInterRegFlows(const int r1, const int r2) const
Retrieve accumulated inter-region flow rates for identified pair of regions.
Definition InterRegFlowMap.cpp:122
Opm::data::InterRegFlowMap::FlowRates
Window::FlowRates FlowRates
Client type through which to define a single inter-region connection.
Definition InterRegFlowMap.hpp:69
Opm::data::InterRegFlowMap::ReadOnlyWindow
InterRegFlow< std::vector< float >::const_iterator > ReadOnlyWindow
Client view of flows between specified region pair.
Definition InterRegFlowMap.hpp:66
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30