Alsvinn  0.5.3
The fast FVM simulator with UQ support
Views.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 "alsfvm/types.hpp"
18 #include <cassert>
19 
20 #include <type_traits>
21 namespace alsfvm {
22 namespace equation {
23 namespace euler {
24 
31 
32 template<class VolumeType, class ViewType, int nsd>
33 class Views {
34 public:
35 
36 
37 };
38 
39 template<class VolumeType, class ViewType>
40 class Views<VolumeType, ViewType, 3> {
41 public:
42  typedef typename Types<3>::rvec rvec;
43  typedef typename std::conditional<std::is_const<VolumeType>::value,
44  const real&,
46 
47  typedef typename Types<3>::template vec<reference_type> reference_vec;
48 
49 
50  Views(VolumeType& volume)
51  : rho(volume.getScalarMemoryArea("rho")->getView()),
52  mx(volume.getScalarMemoryArea("mx")->getView()),
53  my(volume.getScalarMemoryArea("my")->getView()),
54  mz(volume.getScalarMemoryArea("mz")->getView()),
55  E(volume.getScalarMemoryArea("E")->getView()) {
56  // Empty
57  }
58 
59 
60  template<size_t variableIndex>
61  __device__ __host__ ViewType& get() {
62  static_assert(variableIndex < 5,
63  "We only have 5 conserved variables for Euler!");
64 
65  if (variableIndex == 0) {
66  return rho;
67  } else if (variableIndex == 1) {
68  return mx;
69  } else if (variableIndex == 2) {
70  return my;
71  } else if (variableIndex == 3) {
72  return mz;
73 
74  } else if (variableIndex == 4) {
75  return E;
76  }
77 
78  // If we reach this far, something has gone wrong
79  assert(false);
80  return rho;
81  }
82 
83 
84  __device__ __host__ ViewType& get(size_t variableIndex) {
85  switch (variableIndex) {
86  case 0:
87  return rho;
88 
89  case 1:
90  return mx;
91 
92  case 2:
93  return my;
94 
95  case 3:
96  return mz;
97 
98  case 4:
99  return E;
100  }
101 
102  // If we reach this far, something has gone wrong
103  assert(false);
104  return rho;
105  }
106  __device__ __host__ size_t index(size_t x, size_t y, size_t z) const {
107  return rho.index(x, y, z);
108  }
109 
110  __device__ __host__ reference_vec m(size_t index) {
111  return reference_vec(mx.at(index), my.at(index), mz.at(index));
112  }
113 
114  __device__ __host__ rvec m(size_t index) const {
115  return rvec(mx.at(index), my.at(index), mz.at(index));
116  }
117 
118 
119  ViewType rho;
120  ViewType mx;
121  ViewType my;
122  ViewType mz;
123  ViewType E;
124 };
125 
126 template<class VolumeType, class ViewType>
127 class Views<VolumeType, ViewType, 2> {
128 public:
129  typedef typename Types<2>::rvec rvec;
130  typedef typename std::conditional<std::is_const<VolumeType>::value,
131  const real&,
133 
134  typedef typename Types<2>::template vec<reference_type> reference_vec;
135 
136 
137  Views(VolumeType& volume)
138  : rho(volume.getScalarMemoryArea("rho")->getView()),
139  mx(volume.getScalarMemoryArea("mx")->getView()),
140  my(volume.getScalarMemoryArea("my")->getView()),
141  E(volume.getScalarMemoryArea("E")->getView()) {
142  // Empty
143  }
144 
145 
146  template<size_t variableIndex>
147  __device__ __host__ ViewType& get() {
148  static_assert(variableIndex < 4,
149  "We only have 5 conserved variables for Euler!");
150 
151  if (variableIndex == 0) {
152  return rho;
153  } else if (variableIndex == 1) {
154  return mx;
155  } else if (variableIndex == 2) {
156  return my;
157  } else if (variableIndex == 3) {
158  return E;
159  }
160 
161  // If we reach this far, something has gone wrong
162  assert(false);
163  return rho;
164  }
165 
166 
167  __device__ __host__ ViewType& get(size_t variableIndex) {
168  switch (variableIndex) {
169  case 0:
170  return rho;
171 
172  case 1:
173  return mx;
174 
175  case 2:
176  return my;
177 
178  case 3:
179  return E;
180  }
181 
182  // If we reach this far, something has gone wrong
183  assert(false);
184  return rho;
185  }
186  __device__ __host__ size_t index(size_t x, size_t y, size_t z) const {
187  return rho.index(x, y, z);
188  }
189 
190  __device__ __host__ reference_vec m(size_t index) {
191  return reference_vec(mx.at(index), my.at(index));
192  }
193 
194  __device__ __host__ rvec m(size_t index) const {
195  return rvec(mx.at(index), my.at(index));
196  }
197 
198 
199  ViewType rho;
200  ViewType mx;
201  ViewType my;
202  ViewType E;
203 };
204 
205 template<class VolumeType, class ViewType>
206 class Views<VolumeType, ViewType, 1> {
207 public:
208  typedef typename Types<1>::rvec rvec;
209  typedef typename std::conditional<std::is_const<VolumeType>::value,
210  const real&,
212 
213  typedef typename Types<1>::template vec<reference_type> reference_vec;
214 
215 
216  Views(VolumeType& volume)
217  : rho(volume.getScalarMemoryArea("rho")->getView()),
218  mx(volume.getScalarMemoryArea("mx")->getView()),
219  E(volume.getScalarMemoryArea("E")->getView()) {
220  // Empty
221  }
222 
223 
224  template<size_t variableIndex>
225  __device__ __host__ ViewType& get() {
226  static_assert(variableIndex < 3,
227  "We only have 5 conserved variables for Euler!");
228 
229  if (variableIndex == 0) {
230  return rho;
231  } else if (variableIndex == 1) {
232  return mx;
233  } else if (variableIndex == 3) {
234  return E;
235  }
236 
237  // If we reach this far, something has gone wrong
238  assert(false);
239  return rho;
240  }
241 
242 
243  __device__ __host__ ViewType& get(size_t variableIndex) {
244  switch (variableIndex) {
245  case 0:
246  return rho;
247 
248  case 1:
249  return mx;
250 
251  case 2:
252  return E;
253  }
254 
255  // If we reach this far, something has gone wrong
256  assert(false);
257  return rho;
258  }
259  __device__ __host__ size_t index(size_t x, size_t y, size_t z) const {
260  return rho.index(x, y, z);
261  }
262 
263  __device__ __host__ reference_vec m(size_t index) {
264  return reference_vec(mx.at(index));
265  }
266 
267  __device__ __host__ rvec m(size_t index) const {
268  return rvec(mx.at(index));
269  }
270 
271 
272  ViewType rho;
273  ViewType mx;
274  ViewType E;
275 };
276 
277 
278 } // namespace alsfvm
279 } // namespace equation
280 } // namespace euler
Views(VolumeType &volume)
Definition: Views.hpp:137
__device__ __host__ size_t index(size_t x, size_t y, size_t z) const
Definition: Views.hpp:106
Definition: types.hpp:104
Definition: Views.hpp:33
Types< 2 >::rvec rvec
Definition: Views.hpp:129
#define __host__
Definition: types.hpp:46
Views(VolumeType &volume)
Definition: Views.hpp:50
VolumeType type
Definition: VolumeFactory.cpp:85
std::conditional< std::is_const< VolumeType >::value, const real &, real & >::type reference_type
Definition: Views.hpp:132
Types< 2 >::template vec< reference_type > reference_vec
Definition: Views.hpp:134
double real
Definition: types.hpp:65
int rho
Definition: sodshocktube.py:3
__device__ __host__ rvec m(size_t index) const
Definition: Views.hpp:267
Types< 1 >::rvec rvec
Definition: Views.hpp:208
__device__ __host__ reference_vec m(size_t index)
Definition: Views.hpp:190
__device__ __host__ rvec m(size_t index) const
Definition: Views.hpp:194
std::conditional< std::is_const< VolumeType >::value, const real &, real & >::type reference_type
Definition: Views.hpp:45
Views(VolumeType &volume)
Definition: Views.hpp:216
__device__ __host__ rvec m(size_t index) const
Definition: Views.hpp:114
__device__ __host__ size_t index(size_t x, size_t y, size_t z) const
Definition: Views.hpp:259
#define static_assert(x, y)
Definition: types.hpp:52
std::conditional< std::is_const< VolumeType >::value, const real &, real & >::type reference_type
Definition: Views.hpp:211
Types< 3 >::rvec rvec
Definition: Views.hpp:42
Types< 1 >::template vec< reference_type > reference_vec
Definition: Views.hpp:213
#define __device__
Definition: types.hpp:45
Types< 3 >::template vec< reference_type > reference_vec
Definition: Views.hpp:47
__device__ __host__ size_t index(size_t x, size_t y, size_t z) const
Definition: Views.hpp:186
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
__device__ __host__ reference_vec m(size_t index)
Definition: Views.hpp:263
__device__ __host__ reference_vec m(size_t index)
Definition: Views.hpp:110