/var/opm/opm-verteq/opm/verteq/utility/runlen.hpp

Regards a set of (member) variables as a run-length encoded matrix.

Each column can have a variable number of rows. Although the values of the matrix can be changed, its sparsity cannot, i.e. one cannot remove or add new elements to a column.

Use this class to access and iterate over a run-length encoded matrix in the format that is used by UnstructuredGrid without having to worry about getting the indexing right.

Template Parameters
TDatatype for the extra data that should be stored for each element, e.g. double.
RunLenView <int> faces_in_cell (
g.number_of_cells,
g.cell_facepos,
g.cell_faces
);
int num_local_faces = faces_in_cell.size (cellno);
int first_local_face = faces_in_cell [cellno] [0];

Notice if you want to loop through every item and know where you are (because you intend to use this as an index in another matrix), you can do:

#ifndef OPM_VERTEQ_RUNLEN_HPP_INCLUDED
#define OPM_VERTEQ_RUNLEN_HPP_INCLUDED
// Copyright (C) 2013 Uni Research AS
// This file is licensed under the GNU General Public License v3.0
// forward declaration
struct UnstructuredGrid;
namespace Opm {
template <typename T>
class RunLenView {
protected:
int* pos;
T* data;
public:
RunLenView (int num_cols, int* pos_ptr, T* values)
// store them locally for later use
: num_of_cols (num_cols)
, pos (pos_ptr)
, data (values) {
}
RunLenView (const RunLenView& rhs)
// copy all fields verbatim
, pos (rhs.pos)
, data (rhs.data) {
}
T* operator [] (int col) const {
return &data [pos [col]];
}
int cols () const {
return num_of_cols;
}
int size (int col) const {
return pos [col + 1] - pos [col];
}
T& last (int col) const {
return data [pos [col + 1] - 1];
}
};
template <typename T>
struct RunLenData : public RunLenView <T> {
RunLenData (int number, int* pos_ptr)
// allocate a new vector for the data, containing the needed
// number of elements. note that there is only one new
// operation is the parameter list, so there is no leakage if
// an out-of-memory exception is thrown.
: RunLenView <T> (number, pos_ptr, new T [pos_ptr [number]]) {
}
// this member is initialized with data allocated in our ctor
}
};
// shorthands for most used types
typedef const RunLenView <int> rlw_int;
typedef const RunLenView <double> rlw_double;
// access common run-length encoded matrices in a grid structure
rlw_int grid_cell_facetag (const UnstructuredGrid& g);
rlw_int grid_cell_faces (const UnstructuredGrid& g);
} /* namespace Opm */
#endif /* OPM_VERTEQ_RUNLEN_HPP_INCLUDED */
T & last(int col) const
Definition: runlen.hpp:149
int * pos
Definition: runlen.hpp:70
T * operator[](int col) const
Definition: runlen.hpp:116
int cols() const
Definition: runlen.hpp:125
int size(int col) const
Definition: runlen.hpp:135
T * data
Definition: runlen.hpp:76
RunLenView(int num_cols, int *pos_ptr, T *values)
Definition: runlen.hpp:91
int num_of_cols
Definition: runlen.hpp:69
Definition: opmfwd.hpp:15
rlw_int grid_cell_facetag(const UnstructuredGrid &g)
rlw_int grid_cell_faces(const UnstructuredGrid &g)
const RunLenView< double > rlw_double
Definition: runlen.hpp:191
const RunLenView< int > rlw_int
Definition: runlen.hpp:190
~RunLenData()
Definition: runlen.hpp:183
RunLenData(int number, int *pos_ptr)
Definition: runlen.hpp:175