21 #ifndef THUNDEREGG_COMPONENTVIEW_H
22 #define THUNDEREGG_COMPONENTVIEW_H
37 template<
typename T,
int D>
44 std::array<int, M> strides;
45 std::array<int, M> ghost_start;
46 std::array<int, M> start;
47 std::array<int, M> end;
48 std::array<int, M> ghost_end;
49 std::array<int, D> first_value;
56 static std::array<int, M> DetermineGhostStart(
int num_ghost_cells)
58 std::array<int, M> start;
59 start.fill(-num_ghost_cells);
67 static std::array<int, M> DetermineStart()
69 std::array<int, M> start;
78 static std::array<int, M> DetermineEnd(
const std::array<int, M>& lengths)
80 std::array<int, M> end = lengths;
89 static std::array<int, M> DetermineGhostEnd(
const std::array<int, M>& lengths,
92 std::array<int, M> end = lengths;
93 Loop::Unroll<0, M - 1>([&](
int i) { end[i] += num_ghost_cells - 1; });
106 SliceInfo<M> getSliceOnPriv(
Face<D, M> f,
const std::array<int, D - M>& offset)
const
112 std::array<Side<D>, D - M> sides = f.
getSides();
113 size_t lengths_index = 0;
114 size_t sides_index = 0;
116 for (
size_t axis = 0; axis < (size_t)D; axis++) {
117 if (sides_index < sides.size() && sides[sides_index].getAxisIndex() == axis) {
118 if (sides[sides_index].isLowerOnAxis()) {
119 info.first_value[axis] = offset[sides_index];
121 info.first_value[axis] = this->
getEnd()[axis] - offset[sides_index];
125 info.strides[lengths_index] = this->
getStrides()[axis];
126 info.ghost_start[lengths_index] = this->
getGhostStart()[axis];
127 info.start[lengths_index] = this->
getStart()[axis];
128 info.end[lengths_index] = this->
getEnd()[axis];
129 info.ghost_end[lengths_index] = this->
getGhostEnd()[axis];
137 using T_ptr =
typename View<T, D>::T_ptr;
155 const std::array<int, D>& strides,
156 const std::array<int, D>& ghost_start,
157 const std::array<int, D>& start,
158 const std::array<int, D>& end,
159 const std::array<int, D>& ghost_end)
160 :
View<T, D>(data, strides, ghost_start, start, end, ghost_end)
173 const std::array<int, D>& strides,
174 const std::array<int, D>& lengths,
178 DetermineGhostStart<D>(num_ghost_cells),
180 DetermineEnd<D>(lengths),
181 DetermineGhostEnd<D>(lengths, num_ghost_cells))
196 SliceInfo<M> info = getSliceOnPriv<M>(f, offset);
198 T_ptr new_data = (&(*this)[info.first_value]);
200 new_data, info.strides, info.ghost_start, info.start, info.end, info.ghost_end);
215 const std::array<size_t, D - M>& offset)
const
217 using noconst_T =
typename std::remove_const<T>::type;
218 using noconst_T_ptr =
typename std::add_pointer<noconst_T>::type;
219 std::array<int, M> new_strides;
220 std::array<int, M> new_ghost_start;
221 std::array<int, M> new_start;
222 std::array<int, M> new_end;
223 std::array<int, M> new_ghost_end;
224 std::array<int, D> first_value;
228 std::array<Side<D>, D - M> sides = f.
getSides();
229 size_t lengths_index = 0;
230 size_t sides_index = 0;
232 for (
size_t axis = 0; axis < (size_t)D; axis++) {
233 if (sides_index < sides.size() && sides[sides_index].getAxisIndex() == axis) {
234 if (sides[sides_index].isLowerOnAxis()) {
235 first_value[axis] = -1 - offset[sides_index];
237 first_value[axis] = this->
getEnd()[axis] + 1 + offset[sides_index];
241 new_strides[lengths_index] = this->
getStrides()[axis];
242 new_ghost_start[lengths_index] = this->
getGhostStart()[axis];
243 new_start[lengths_index] = this->
getStart()[axis];
244 new_end[lengths_index] = this->
getEnd()[axis];
245 new_ghost_end[lengths_index] = this->
getGhostEnd()[axis];
250 noconst_T_ptr new_data =
const_cast<noconst_T_ptr
>(
251 &(*this)[first_value]);
253 new_data, new_strides, new_ghost_start, new_start, new_end, new_ghost_end);
267 extern template class ComponentView<double, 1>;
268 extern template View<double, 0>
270 extern template View<double, 0>
272 extern template class ComponentView<double, 2>;
273 extern template View<double, 0>
275 extern template View<double, 1>
277 extern template View<double, 0>
279 extern template View<double, 1>
281 extern template class ComponentView<double, 3>;
282 extern template View<double, 0>
284 extern template View<double, 1>
286 extern template View<double, 2>
288 extern template View<double, 0>
290 extern template View<double, 1>
292 extern template View<double, 2>
294 extern template class ComponentView<const double, 1>;
295 extern template View<const double, 0>
297 extern template View<double, 0>
299 extern template class ComponentView<const double, 2>;
300 extern template View<const double, 0>
302 extern template View<const double, 1>
304 extern template View<double, 0>
306 extern template View<double, 1>
308 extern template class ComponentView<const double, 3>;
309 extern template View<const double, 0>
311 extern template View<const double, 1>
313 extern template View<const double, 2>
315 extern template View<double, 0>
317 extern template View<double, 1>
319 extern template View<double, 2>