dune-grid 2.9.0
multiindex.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3#ifndef DUNE_GRID_UTILITY_MULTIINDEX_HH
4#define DUNE_GRID_UTILITY_MULTIINDEX_HH
5
11#include<array>
12
13namespace Dune
14{
15 namespace FactoryUtilities
16 {
17 template<std::size_t dim>
18 class MultiIndex : public std::array<unsigned int,dim>
19 {
20 // The range of each component
21 std::array<unsigned int,dim> limits_;
22
23 public:
25 MultiIndex(const std::array<unsigned int,dim>& limits) : limits_(limits)
26 {
27 std::fill(this->begin(), this->end(), 0);
28 }
29
32 {
33 for (std::size_t i=0; i<dim; i++)
34 {
35 // Augment digit
36 (*this)[i]++;
37
38 // If there is no carry-over we can stop here
39 if ((*this)[i]<limits_[i])
40 break;
41
42 (*this)[i] = 0;
43 }
44 return *this;
45 }
46
48 size_t cycle() const
49 {
50 size_t result = 1;
51 for (std::size_t i=0; i<dim; i++)
52 result *= limits_[i];
53 return result;
54 }
55 };
56 }
57}
58
59#endif
Include standard header files.
Definition: agrid.hh:60
Definition: multiindex.hh:19
MultiIndex(const std::array< unsigned int, dim > &limits)
Constructor with a given range for each digit.
Definition: multiindex.hh:25
MultiIndex< dim > & operator++()
Increment the MultiIndex.
Definition: multiindex.hh:31
size_t cycle() const
Compute how many times you can call operator++ before getting to (0,...,0) again.
Definition: multiindex.hh:48