1#ifndef DUNE_SPGRID_MULTIINDEX_HH
2#define DUNE_SPGRID_MULTIINDEX_HH
7#include <dune/common/iostream.hh>
32 typedef typename std::array< int, dimension >::const_iterator ConstIterator;
33 typedef typename std::array< int, dimension >::iterator Iterator;
45 template <
int d, std::enable_if_t<(d == dimension && d > 0),
int> = 0>
55 SPMultiIndex (
const std::array< int, dimension > &index ) { *
this = index; }
74 index_[ i ] = other.index_[ i ];
79 template <
int d, std::enable_if_t<(d == dimension && d > 0),
int> = 0>
83 index_[ i ] = index[ i ];
87 This &
operator= (
const std::array< int, dimension > &index )
90 index_[ i ] = index[ i ];
98 index_[ i ] += other.index_[ i ];
106 index_[ i ] -= other.index_[ i ];
127 const int &
operator[] (
int i )
const {
return index_[ i ]; }
137 equals &= (index_[ i ] == other.index_[ i ]);
146 equals |= (index_[ i ] != other.index_[ i ]);
154 index_[ i ] += a*other.index_[ i ];
157 ConstIterator begin ()
const {
return index_.begin(); }
158 Iterator begin () {
return index_.begin(); }
160 ConstIterator cbegin ()
const {
return index_.begin(); }
162 ConstIterator end ()
const {
return index_.end(); }
163 Iterator end () {
return index_.end(); }
165 ConstIterator cend ()
const {
return index_.end(); }
180 if( index_[ i ] < bound[ i ] )
191 codim -= (index_[ i ] & 1);
204 std::array< int, dimension > index_;
212 template<
class char_type,
class traits,
int dim >
213 inline std::basic_ostream< char_type, traits > &
214 operator<< ( std::basic_ostream< char_type, traits > &out,
const SPMultiIndex< dim > &multiIndex )
216 out <<
"( " << multiIndex[ 0 ];
217 for(
int i = 1; i < dim; ++i )
218 out <<
", " << multiIndex[ i ];
223 template<
class char_type,
class traits,
int dim >
224 inline std::basic_istream< char_type, traits > &
225 operator>> ( std::basic_istream< char_type, traits > &in, SPMultiIndex< dim > &multiIndex )
227 SPMultiIndex< dim > m;
228 in >> match(
'(' ) >> m[ 0 ];
229 for(
int i = 1; i < dim; ++i )
230 in >> match(
',' ) >> m[ i ];
239 inline SPMultiIndex< dim >
240 operator+ (
const SPMultiIndex< dim > &a,
const SPMultiIndex< dim > &b )
242 SPMultiIndex< dim > c = a;
249 inline SPMultiIndex< dim >
250 operator- (
const SPMultiIndex< dim > &a,
const SPMultiIndex< dim > &b )
252 SPMultiIndex< dim > c = a;
259 inline SPMultiIndex< dim >
260 operator* (
const SPMultiIndex< dim > &a,
const int &b )
262 SPMultiIndex< dim > c = a;
269 inline SPMultiIndex< dim >
270 operator* (
const int &a,
const SPMultiIndex< dim > &b )
277 inline SPMultiIndex< dim >
278 operator/ (
const SPMultiIndex< dim > &a,
const int &b )
280 SPMultiIndex< dim > c = a;
299 for(
int i = 0; i < dim; ++i )
300 c[ i ] = min( a[ i ], b[ i ] );
310 for(
int i = 0; i < dim; ++i )
311 c[ i ] = max( a[ i ], b[ i ] );
multiindex
Definition: multiindex.hh:25
This & operator=(const This &other)
copy assignment
Definition: multiindex.hh:71
void increment(const This &bound, const int k=1)
Definition: multiindex.hh:175
static const int dimension
dimension of the multiindex
Definition: multiindex.hh:30
static This zero()
obtain the zero multiindex
Definition: multiindex.hh:196
SPMultiIndex()
default constructor
Definition: multiindex.hh:36
SPMultiIndex(const std::array< int, dimension > &index)
constructor from int array
Definition: multiindex.hh:55
This & operator-=(const This &other)
subtract another multiindex from this one (vector operation)
Definition: multiindex.hh:103
void clear()
initialize to zero
Definition: multiindex.hh:168
const int & operator[](int i) const
access i-th component
Definition: multiindex.hh:127
bool operator==(const This &other) const
compare two multiindices for equality
Definition: multiindex.hh:133
void axpy(const int a, const This &other)
add multiple of a multiindex to this one (vector operation)
Definition: multiindex.hh:151
This & operator/=(int a)
scale this multiindex (vector operation)
Definition: multiindex.hh:119
This & operator*=(int a)
scale this multiindex (vector operation)
Definition: multiindex.hh:111
This & operator+=(const This &other)
add another multiindex to this one (vector operation)
Definition: multiindex.hh:95
SPMultiIndex(const This &other)
copy constructor
Definition: multiindex.hh:63
SPMultiIndex(const int(&index)[d])
constructor from int array
Definition: multiindex.hh:46
int codimension() const
Definition: multiindex.hh:187
bool operator!=(const This &other) const
compare two multiindices for inequality
Definition: multiindex.hh:142
miscellaneous helper functions
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:402
Dune namespace.
Definition: alignedallocator.hh:13