Peano
idx.h
Go to the documentation of this file.
1 #pragma once
2 
3 // This contains loop options for iterating over higher dimensional objects
4 // they were shamelessly stolen from ExaHyPE1
5 namespace kernels{
6 
7  struct idx2 {
8  idx2(int I, int J, int line = -1) : I_(I), J_(J), size(I*J), line_(line) {}
9 
10  int operator()(int i, int j) const {
11  assertion3(i < I_, i, I_, line_);
12  assertion3(j < J_, j, J_, line_);
13  return i * J_ + j;
14  }
15 
16  void rev(int pos, int& i, int& j) const {
17  assertion(pos < size);
18  i = pos % J_;
19  j = pos - i * J_;
20  }
21 
22  const int I_, J_, size, line_;
23  };
24 
25  struct idx3 {
26  idx3(int I, int J, int K, int line = -1) : I_(I), J_(J), K_(K), size(I*J*K), line_(line) {}
27 
28  int operator()(int i, int j, int k) const {
29  assertion3(i < I_, i, I_, line_);
30  assertion3(j < J_, j, J_, line_);
31  assertion3(k < K_, k, K_, line_);
32  return i * (J_ * K_) + j * K_ + k;
33  }
34 
35  const int I_, J_, K_, size, line_;
36  };
37 
38  struct idx4 {
39  idx4(int I, int J, int K, int L, int line = -1)
40  : I_(I), J_(J), K_(K), L_(L), size(I*J*K*L), line_(line) {}
41 
42  int operator()(int i, int j, int k, int l) const {
43  assertion3(i < I_, i, I_, line_);
44  assertion3(j < J_, j, J_, line_);
45  assertion3(k < K_, k, K_, line_);
46  assertion3(l < L_, l, L_, line_);
47  return i * (J_ * K_ * L_) + j * (K_ * L_) + k * L_ + l;
48  }
49 
50  const int I_, J_, K_, L_, size, line_;
51  };
52 
53  struct idx5 {
54  idx5(int I, int J, int K, int L, int M, int line = -1)
55  : I_(I), J_(J), K_(K), L_(L), M_(M), size(I*J*K*L*M), line_(line) {}
56 
57  int operator()(int i, int j, int k, int l, int m) const {
58  assertion3(i < I_, i, I_, line_);
59  assertion3(j < J_, j, J_, line_);
60  assertion3(k < K_, k, K_, line_);
61  assertion3(l < L_, l, L_, line_);
62  assertion3(m < M_, m, M_, line_);
63  return i * (J_ * K_ * L_ * M_) + j * (K_ * L_ * M_) + k * (L_ * M_) +
64  l * M_ + m;
65  }
66 
67  const int I_, J_, K_, L_, M_, size, line_;
68  };
69 }
j
Definition: euler.py:95
Definition: idx.h:5
idx2(int I, int J, int line=-1)
Definition: idx.h:8
int operator()(int i, int j) const
Definition: idx.h:10
const int J_
Definition: idx.h:22
void rev(int pos, int &i, int &j) const
Definition: idx.h:16
const int size
Definition: idx.h:22
const int line_
Definition: idx.h:22
const int I_
Definition: idx.h:22
int operator()(int i, int j, int k) const
Definition: idx.h:28
const int size
Definition: idx.h:35
const int I_
Definition: idx.h:35
idx3(int I, int J, int K, int line=-1)
Definition: idx.h:26
const int J_
Definition: idx.h:35
const int K_
Definition: idx.h:35
const int line_
Definition: idx.h:35
const int L_
Definition: idx.h:50
int operator()(int i, int j, int k, int l) const
Definition: idx.h:42
const int line_
Definition: idx.h:50
const int I_
Definition: idx.h:50
const int size
Definition: idx.h:50
idx4(int I, int J, int K, int L, int line=-1)
Definition: idx.h:39
const int K_
Definition: idx.h:50
const int J_
Definition: idx.h:50
const int I_
Definition: idx.h:67
idx5(int I, int J, int K, int L, int M, int line=-1)
Definition: idx.h:54
const int K_
Definition: idx.h:67
const int M_
Definition: idx.h:67
const int J_
Definition: idx.h:67
const int L_
Definition: idx.h:67
const int line_
Definition: idx.h:67
int operator()(int i, int j, int k, int l, int m) const
Definition: idx.h:57
const int size
Definition: idx.h:67