Alsvinn  0.5.3
The fast FVM simulator with UQ support
View.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 #include <cassert>
18 #include "alsfvm/types.hpp"
19 #include "alsfvm/boundary/Type.hpp"
20 
21 namespace alsfvm {
22 namespace memory {
23 
31 template<class T>
32 class View {
33 public:
34 
47  __device__ __host__ View(T* pointer,
48  size_t nx,
49  size_t ny,
50  size_t nz,
51  size_t extentXInBytes,
52  size_t extentYInBytes)
53  : nx(nx), ny(ny), nz(nz), pointer(pointer), extentXInBytes(extentXInBytes),
54  extentYInBytes(extentYInBytes) {
55  // empty
56  }
57 
65  __device__ __host__ T& at(size_t x, size_t y, size_t z) {
66  assert(x < nx);
67  assert(y < ny);
68  assert(z < nz);
69  return pointer[index(x, y, z)];
70  }
71 
79  __device__ __host__ const T& at(size_t x, size_t y, size_t z) const {
80  assert(x < nx);
81  assert(y < ny);
82  assert(z < nz);
83  return pointer[index(x, y, z)];
84  }
85 
91  __device__ __host__ T& at(size_t index) {
92  return pointer[index];
93  }
94 
100  __device__ __host__ const T& at(size_t index) const {
101  return pointer[index];
102  }
103 
104 
105  __device__ __host__ size_t size() const {
106  return nx * ny * nz;
107  }
108 
116  __device__ __host__ size_t index(size_t x, size_t y, size_t z) const {
117  return z * nx * ny + y * nx + x ;
118  }
119 
121  return nx;
122  }
123 
125  return ny;
126  }
127 
129  return nz;
130  }
131 
132  const size_t nx;
133  const size_t ny;
134  const size_t nz;
135 private:
136  T* pointer;
137 
138  size_t extentXInBytes;
139  size_t extentYInBytes;
140 
141 };
142 
143 
144 }
145 
146 }
147 
__device__ __host__ size_t index(size_t x, size_t y, size_t z) const
index computes the linear index of the given cell
Definition: View.hpp:116
__device__ __host__ size_t size() const
Definition: View.hpp:105
const size_t nz
Definition: View.hpp:134
#define __host__
Definition: types.hpp:46
__device__ __host__ T & at(size_t x, size_t y, size_t z)
at returns a reference to the element at the given location
Definition: View.hpp:65
__device__ __host__ View(T *pointer, size_t nx, size_t ny, size_t nz, size_t extentXInBytes, size_t extentYInBytes)
View constructs the View.
Definition: View.hpp:47
__device__ __host__ size_t getNumberOfZCells() const
Definition: View.hpp:128
const size_t nx
Definition: View.hpp:132
const size_t ny
Definition: View.hpp:133
__device__ __host__ T & at(size_t index)
at returns the reference to the element index by the single value index
Definition: View.hpp:91
#define __device__
Definition: types.hpp:45
__device__ __host__ size_t getNumberOfXCells() const
Definition: View.hpp:120
__device__ __host__ size_t getNumberOfYCells() const
Definition: View.hpp:124
Definition: View.hpp:32
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
__device__ __host__ const T & at(size_t index) const
at returns the reference to the element index by the single value index
Definition: View.hpp:100
__device__ __host__ const T & at(size_t x, size_t y, size_t z) const
at returns a reference to the element at the given location (const version)
Definition: View.hpp:79