20#ifndef OPM_WINDOWED_ARRAY_HPP
21#define OPM_WINDOWED_ARRAY_HPP
30#include <boost/range/iterator_range.hpp>
37namespace Opm {
namespace RestartIO {
namespace Helpers {
54 typename std::vector<T>::iterator>;
58 typename std::vector<T>::const_iterator>;
60 using Idx =
typename std::vector<T>::size_type;
77 const T initial = T{})
78 : x_ (n.value * sz.value, initial)
79 , windowSize_(sz.value)
82 throw std::invalid_argument {
83 "Zero-sized windows are not permitted"
88 WindowedArray(
const WindowedArray& rhs) =
default;
89 WindowedArray(WindowedArray&& rhs) =
default;
90 WindowedArray& operator=(
const WindowedArray& rhs) =
delete;
91 WindowedArray& operator=(WindowedArray&& rhs) =
default;
96 return this->x_.size() / this->windowSize_;
102 return this->windowSize_;
112 "Window ID Out of Bounds");
114 auto b = std::begin(this->x_) + window*this->windowSize_;
115 auto e = b + this->windowSize_;
127 "Window ID Out of Bounds");
129 auto b = std::begin(this->x_) + window*this->windowSize_;
130 auto e = b + this->windowSize_;
137 const std::vector<T>&
data()
const
147 return std::move(this->x_);
168 template <
typename T>
178 using Idx =
typename WindowedArray<T>::Idx;
195 const NumCols& nCols,
196 const WindowSize& sz,
197 const T initial = T{})
198 : data_ (NumWindows{ nRows.value * nCols.value }, sz, initial)
199 , numCols_(nCols.value)
201 if (nCols.value == 0) {
202 throw std::invalid_argument {
203 "Zero-columned windowed matrices are not permitted"
211 return this->numCols_;
217 return this->data_.numWindows() / this->
numCols();
223 return this->data_.windowSize();
237 return this->data_[ this->i(row, col) ];
251 return this->data_[ this->i(row, col) ];
259 return this->data_.data();
266 ->
decltype(std::declval<WindowedArray<T>>()
267 .getDataDestructively())
269 return this->data_.getDataDestructively();
278 Idx i(
const Idx row,
const Idx col)
const
280 return row*this->numCols() + col;
Provide read-only and read/write access to constantly sized portions/windows of a linearised buffer w...
Definition WindowedArray.hpp:50
std::vector< T > getDataDestructively()
Extract full, linearised data items for all windows.
Definition WindowedArray.hpp:145
Idx numWindows() const
Retrieve number of windows allocated for this array.
Definition WindowedArray.hpp:94
Idx windowSize() const
Retrieve number of data items per windows.
Definition WindowedArray.hpp:100
const std::vector< T > & data() const
Get read-only access to full, linearised data items for all windows.
Definition WindowedArray.hpp:137
WriteWindow operator[](const Idx window)
Request read/write access to individual window.
Definition WindowedArray.hpp:109
boost::iterator_range< typename std::vector< double >::const_iterator > ReadWindow
Definition WindowedArray.hpp:57
ReadWindow operator[](const Idx window) const
Request read-only access to individual window.
Definition WindowedArray.hpp:124
boost::iterator_range< typename std::vector< double >::iterator > WriteWindow
Definition WindowedArray.hpp:53
WindowedArray(const NumWindows n, const WindowSize sz, const T initial=T{})
Constructor.
Definition WindowedArray.hpp:75
ReadWindow operator()(const Idx row, const Idx col) const
Request read-only access to individual window.
Definition WindowedArray.hpp:249
WriteWindow operator()(const Idx row, const Idx col)
Request read/write access to individual window.
Definition WindowedArray.hpp:235
auto getDataDestructively() -> decltype(std::declval< WindowedArray< T > >() .getDataDestructively())
Extract full, linearised data items for all windows.
Definition WindowedArray.hpp:265
Idx windowSize() const
Retrieve number of data items per windows.
Definition WindowedArray.hpp:221
Idx numRows() const
Retrieve number of rows allocated for this matrix.
Definition WindowedArray.hpp:215
Idx numCols() const
Retrieve number of columns allocated for this matrix.
Definition WindowedArray.hpp:209
WindowedMatrix(const NumRows &nRows, const NumCols &nCols, const WindowSize &sz, const T initial=T{})
Constructor.
Definition WindowedArray.hpp:194
auto data() const -> decltype(std::declval< const WindowedArray< T > >().data())
Get read-only access to full, linearised data items for all windows.
Definition WindowedArray.hpp:256
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Distinct compile-time type for number of windows in underlying storage.
Definition WindowedArray.hpp:64
Distinct compile-time type for size of windows (number of data items per window.).
Definition WindowedArray.hpp:68
Distinct compile-time type for number of matrix columns in underlying storage.
Definition WindowedArray.hpp:186
Distinct compile-time type for number of matrix rows in underlying storage.
Definition WindowedArray.hpp:182