dune-grid
2.11
Toggle main menu visibility
Loading...
Searching...
No Matches
dune
grid
utility
multiindex.hh
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Copyright © 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
10
11
#include<array>
12
13
namespace
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
31
MultiIndex<dim>
&
operator++
()
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
Dune
Include standard header files.
Definition
agrid.hh:60
Dune::FactoryUtilities
Definition
multiindex.hh:16
Dune::FactoryUtilities::MultiIndex::MultiIndex
MultiIndex(const std::array< unsigned int, dim > &limits)
Constructor with a given range for each digit.
Definition
multiindex.hh:25
Dune::FactoryUtilities::MultiIndex::operator++
MultiIndex< dim > & operator++()
Increment the MultiIndex.
Definition
multiindex.hh:31
Dune::FactoryUtilities::MultiIndex::cycle
size_t cycle() const
Compute how many times you can call operator++ before getting to (0,...,0) again.
Definition
multiindex.hh:48
Generated by
1.17.0