Alsvinn  0.5.3
The fast FVM simulator with UQ support
index.hpp
Go to the documentation of this file.
1 /* Copyright (c) 2018 ETH Zurich, Kjetil Olsen Lye
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #pragma once
17 
21 
32 inline const char* dataAtRawConst(const char* pointer,
33  size_t ix, size_t iy, size_t iz, size_t nx, size_t ny) {
34 
35  return pointer + iz * nx * ny + iy * nx + ix;
36 }
37 
48 inline char* dataAtRaw(char* pointer,
49  size_t ix, size_t iy, size_t iz, size_t nx, size_t ny) {
50 
51  return pointer + iz * nx * ny + iy * nx + ix;
52 }
53 
64 template<class T>
65 inline const T& dataAt(const T* pointer, size_t ix, size_t iy, size_t iz,
66  size_t nx,
67  size_t ny) {
68  return *dataAtRawConst((const char*)pointer, ix * sizeof(T), iy * sizeof(T),
69  iz * sizeof(T),
70  nx, ny);
71 }
72 
83 template<class T>
84 inline T& dataAt(T* pointer, size_t ix, size_t iy, size_t iz, size_t nx,
85  size_t ny) {
86  return *dataAtRaw((char*)pointer, ix * sizeof(T), iy * sizeof(T),
87  iz * sizeof(T),
88  nx, ny);
89 }
90 
100 inline size_t calculateIndex(size_t x, size_t y, size_t z, size_t nx,
101  size_t ny) {
102  return z * nx * ny + y * nx + x;
103 }
104 
105 
const char * dataAtRawConst(const char *pointer, size_t ix, size_t iy, size_t iz, size_t nx, size_t ny)
dataAtRaw gets the data at the given indexes
Definition: index.hpp:32
size_t nx
Definition: VolumeFactory.cpp:87
char * dataAtRaw(char *pointer, size_t ix, size_t iy, size_t iz, size_t nx, size_t ny)
dataAtRaw gets the data at the given indexes
Definition: index.hpp:48
size_t calculateIndex(size_t x, size_t y, size_t z, size_t nx, size_t ny)
calculateIndex calculates the index for the given coordinates
Definition: index.hpp:100
size_t ny
Definition: VolumeFactory.cpp:88
const T & dataAt(const T *pointer, size_t ix, size_t iy, size_t iz, size_t nx, size_t ny)
dataAt gets the data at the given address
Definition: index.hpp:65