Alsvinn  0.5.3
The fast FVM simulator with UQ support
ViewsExtra.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 namespace alsfvm {
21 namespace equation {
22 namespace euler {
23 
30 template<class VolumeType, class ViewType, int nsd>
31 class ViewsExtra {
32 public:
33 
34 };
35 
36 template<class VolumeType, class ViewType>
37 class ViewsExtra<VolumeType, ViewType, 3> {
38 public:
39  typedef typename Types<3>::rvec rvec;
40  typedef typename std::conditional<std::is_const<VolumeType>::value,
41  const real&,
43 
44  typedef typename Types<3>::template vec<reference_type> reference_vec;
45 
46  ViewsExtra(VolumeType& volume)
47  : p(volume.getScalarMemoryArea("p")->getView()),
48  ux(volume.getScalarMemoryArea("ux")->getView()),
49  uy(volume.getScalarMemoryArea("uy")->getView()),
50  uz(volume.getScalarMemoryArea("uz")->getView()) {
51  // Empty
52  }
53 
54  template<size_t variableIndex>
55  __device__ __host__ ViewType& get() {
56  static_assert(variableIndex < 5,
57  "We only have 5 conserved variables for Euler!");
58 
59  switch (variableIndex) {
60  case 0:
61  return p;
62 
63  case 1:
64  return ux;
65 
66  case 2:
67  return uy;
68 
69  case 3:
70  return uz;
71  }
72 
73  // If we reach this far, something has gone wrong
74  assert(false);
75  return p;
76  }
77 
78  __device__ __host__ size_t index(size_t x, size_t y, size_t z) const {
79  return p.index(x, y, z);
80  }
81 
82 
83 
84  __device__ __host__ reference_vec u(size_t index) {
85  return reference_vec(ux.at(index), uy.at(index), uz.at(index));
86  }
87 
88  __device__ __host__ rvec u(size_t index) const {
89  return rvec(ux.at(index), uy.at(index), uz.at(index));
90  }
91 
92 
93 
94  ViewType p;
95  ViewType ux;
96  ViewType uy;
97  ViewType uz;
98 };
99 
100 template<class VolumeType, class ViewType>
101 class ViewsExtra<VolumeType, ViewType, 2> {
102 public:
103  typedef typename Types<2>::rvec rvec;
104  typedef typename std::conditional<std::is_const<VolumeType>::value,
105  const real&,
107 
108  typedef typename Types<2>::template vec<reference_type> reference_vec;
109 
110 
111  ViewsExtra(VolumeType& volume)
112  : p(volume.getScalarMemoryArea("p")->getView()),
113  ux(volume.getScalarMemoryArea("ux")->getView()),
114  uy(volume.getScalarMemoryArea("uy")->getView()) {
115  // Empty
116  }
117 
118  template<size_t variableIndex>
119  __device__ __host__ ViewType& get() {
120  static_assert(variableIndex < 4,
121  "We only have 5 conserved variables for Euler!");
122 
123  switch (variableIndex) {
124  case 0:
125  return p;
126 
127  case 1:
128  return ux;
129 
130  case 2:
131  return uy;
132  }
133 
134  // If we reach this far, something has gone wrong
135  assert(false);
136  return p;
137  }
138 
139  __device__ __host__ size_t index(size_t x, size_t y, size_t z) const {
140  return p.index(x, y, z);
141  }
142 
143  __device__ __host__ reference_vec u(size_t index) {
144  return reference_vec(ux.at(index), uy.at(index));
145  }
146 
147  __device__ __host__ rvec u(size_t index) const {
148  return rvec(ux.at(index), uy.at(index));
149  }
150 
151 
152  ViewType p;
153  ViewType ux;
154  ViewType uy;
155 };
156 
157 
158 template<class VolumeType, class ViewType>
159 class ViewsExtra<VolumeType, ViewType, 1> {
160 public:
161  typedef typename Types<1>::rvec rvec;
162  typedef typename std::conditional<std::is_const<VolumeType>::value,
163  const real&,
165 
166  typedef typename Types<1>::template vec<reference_type> reference_vec;
167 
168 
169  ViewsExtra(VolumeType& volume)
170  : p(volume.getScalarMemoryArea("p")->getView()),
171  ux(volume.getScalarMemoryArea("ux")->getView()) {
172  // Empty
173  }
174 
175  template<size_t variableIndex>
176  __device__ __host__ ViewType& get() {
177  static_assert(variableIndex < 2,
178  "We only have 5 conserved variables for Euler!");
179 
180  switch (variableIndex) {
181  case 0:
182  return p;
183 
184  case 1:
185  return ux;
186  }
187 
188  // If we reach this far, something has gone wrong
189  assert(false);
190  return p;
191  }
192 
193  __device__ __host__ size_t index(size_t x, size_t y, size_t z) const {
194  return p.index(x, y, z);
195  }
196 
197  __device__ __host__ reference_vec u(size_t index) {
198  return reference_vec(ux.at(index));
199  }
200 
201  __device__ __host__ rvec u(size_t index) const {
202  return rvec(ux.at(index));
203  }
204 
205  ViewType p;
206  ViewType ux;
207 };
208 
209 
210 } // namespace alsfvm
211 } // namespace equation
212 } // namespace euler
Definition: types.hpp:104
ViewsExtra(VolumeType &volume)
Definition: ViewsExtra.hpp:111
__device__ __host__ size_t index(size_t x, size_t y, size_t z) const
Definition: ViewsExtra.hpp:193
Types< 1 >::rvec rvec
Definition: ViewsExtra.hpp:161
ViewsExtra(VolumeType &volume)
Definition: ViewsExtra.hpp:169
#define __host__
Definition: types.hpp:46
VolumeType type
Definition: VolumeFactory.cpp:85
__device__ __host__ reference_vec u(size_t index)
Definition: ViewsExtra.hpp:197
double real
Definition: types.hpp:65
int ux
Definition: sodshocktube.py:4
Types< 2 >::rvec rvec
Definition: ViewsExtra.hpp:103
Types< 1 >::template vec< reference_type > reference_vec
Definition: ViewsExtra.hpp:166
__device__ __host__ size_t index(size_t x, size_t y, size_t z) const
Definition: ViewsExtra.hpp:139
__device__ __host__ rvec u(size_t index) const
Definition: ViewsExtra.hpp:201
Types< 3 >::template vec< reference_type > reference_vec
Definition: ViewsExtra.hpp:44
Types< 3 >::rvec rvec
Definition: ViewsExtra.hpp:39
#define static_assert(x, y)
Definition: types.hpp:52
Types< 2 >::template vec< reference_type > reference_vec
Definition: ViewsExtra.hpp:108
__device__ __host__ size_t index(size_t x, size_t y, size_t z) const
Definition: ViewsExtra.hpp:78
__device__ __host__ reference_vec u(size_t index)
Definition: ViewsExtra.hpp:143
#define __device__
Definition: types.hpp:45
std::conditional< std::is_const< VolumeType >::value, const real &, real & >::type reference_type
Definition: ViewsExtra.hpp:164
__device__ __host__ rvec u(size_t index) const
Definition: ViewsExtra.hpp:147
std::conditional< std::is_const< VolumeType >::value, const real &, real & >::type reference_type
Definition: ViewsExtra.hpp:42
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
ViewsExtra(VolumeType &volume)
Definition: ViewsExtra.hpp:46
float p
Definition: sodshocktube.py:5
std::conditional< std::is_const< VolumeType >::value, const real &, real & >::type reference_type
Definition: ViewsExtra.hpp:106
Definition: ViewsExtra.hpp:31
__device__ __host__ reference_vec u(size_t index)
Definition: ViewsExtra.hpp:84
__device__ __host__ rvec u(size_t index) const
Definition: ViewsExtra.hpp:88