21 #ifndef THUNDEREGG_PATCHVIEW_H
22 #define THUNDEREGG_PATCHVIEW_H
36 template<
typename T,
int D>
43 std::array<int, M + 1> strides;
44 std::array<int, M + 1> ghost_start;
45 std::array<int, M + 1> start;
46 std::array<int, M + 1> end;
47 std::array<int, M + 1> ghost_end;
48 std::array<int, D + 1> first_value;
55 static std::array<int, M + 1> DetermineGhostStart(
int num_ghost_cells)
57 std::array<int, M + 1> start;
58 start.fill(-num_ghost_cells);
67 static std::array<int, M + 1> DetermineStart()
69 std::array<int, M + 1> start;
78 static std::array<int, M + 1> DetermineEnd(
const std::array<int, M + 1>& lengths)
80 std::array<int, M + 1> end = lengths;
81 Loop::Unroll<0, M>([&](
int i) { end[i]--; });
89 static std::array<int, M + 1> DetermineGhostEnd(
const std::array<int, M + 1>& lengths,
92 std::array<int, M + 1> end = lengths;
93 Loop::Unroll<0, M - 1>([&](
int i) { end[i] += num_ghost_cells - 1; });
94 end[M] = lengths[M] - 1;
107 SliceInfo<M> getSliceOnPriv(
Face<D, M> f,
const std::array<int, D - M>& offset)
const
113 std::array<Side<D>, D - M> sides = f.
getSides();
114 size_t lengths_index = 0;
115 size_t sides_index = 0;
117 for (
size_t axis = 0; axis < (size_t)D; axis++) {
118 if (sides_index < sides.size() && sides[sides_index].getAxisIndex() == axis) {
119 if (sides[sides_index].isLowerOnAxis()) {
120 info.first_value[axis] = offset[sides_index];
122 info.first_value[axis] = this->
getEnd()[axis] - offset[sides_index];
126 info.strides[lengths_index] = this->
getStrides()[axis];
127 info.ghost_start[lengths_index] = this->
getGhostStart()[axis];
128 info.start[lengths_index] = this->
getStart()[axis];
129 info.end[lengths_index] = this->
getEnd()[axis];
130 info.ghost_end[lengths_index] = this->
getGhostEnd()[axis];
136 info.start[M] = this->
getStart()[D];
137 info.end[M] = this->
getEnd()[D];
143 using T_ptr =
typename View<T, D>::T_ptr;
161 const std::array<int, D + 1>& strides,
162 const std::array<int, D + 1>& ghost_start,
163 const std::array<int, D + 1>& start,
164 const std::array<int, D + 1>& end,
165 const std::array<int, D + 1>& ghost_end)
166 :
View<T, D + 1>(data, strides, ghost_start, start, end, ghost_end)
179 const std::array<int, D + 1>& strides,
180 const std::array<int, D + 1>& lengths,
182 :
View<T, D + 1>(data,
184 DetermineGhostStart<D>(num_ghost_cells),
186 DetermineEnd<D>(lengths),
187 DetermineGhostEnd<D>(lengths, num_ghost_cells))
202 SliceInfo<M> info = getSliceOnPriv<M>(f, offset);
204 T_ptr new_data = (&(*this)[info.first_value]);
206 new_data, info.strides, info.ghost_start, info.start, info.end, info.ghost_end);
221 const std::array<size_t, D - M>& offset)
const
223 using noconst_T =
typename std::remove_const<T>::type;
224 using noconst_T_ptr =
typename std::add_pointer<noconst_T>::type;
225 std::array<int, M + 1> new_strides;
226 std::array<int, M + 1> new_ghost_start;
227 std::array<int, M + 1> new_start;
228 std::array<int, M + 1> new_end;
229 std::array<int, M + 1> new_ghost_end;
230 std::array<int, D + 1> first_value;
234 std::array<Side<D>, D - M> sides = f.
getSides();
235 size_t lengths_index = 0;
236 size_t sides_index = 0;
238 for (
size_t axis = 0; axis < (size_t)D; axis++) {
239 if (sides_index < sides.size() && sides[sides_index].getAxisIndex() == axis) {
240 if (sides[sides_index].isLowerOnAxis()) {
241 first_value[axis] = -1 - offset[sides_index];
243 first_value[axis] = this->
getEnd()[axis] + 1 + offset[sides_index];
247 new_strides[lengths_index] = this->
getStrides()[axis];
248 new_ghost_start[lengths_index] = this->
getGhostStart()[axis];
249 new_start[lengths_index] = this->
getStart()[axis];
250 new_end[lengths_index] = this->
getEnd()[axis];
251 new_ghost_end[lengths_index] = this->
getGhostEnd()[axis];
258 new_end[M] = this->
getEnd()[D];
261 noconst_T_ptr new_data =
const_cast<noconst_T_ptr
>(
262 &(*this)[first_value]);
264 new_data, new_strides, new_ghost_start, new_start, new_end, new_ghost_end);
269 if constexpr (ENABLE_DEBUG) {
270 if (component_index < this->
getStart()[D] || component_index > this->
getEnd()[D]) {
274 std::array<int, D> new_strides;
275 std::array<int, D> new_ghost_start;
276 std::array<int, D> new_start;
277 std::array<int, D> new_end;
278 std::array<int, D> new_ghost_end;
279 std::array<int, D + 1> first_value;
282 first_value[D] = component_index;
284 for (
size_t axis = 0; axis < (size_t)D; axis++) {
287 new_start[axis] = this->
getStart()[axis];
288 new_end[axis] = this->
getEnd()[axis];
292 T_ptr new_data = (&(*this)[first_value]);
293 return ComponentView<T, D>(
294 new_data, new_strides, new_ghost_start, new_start, new_end, new_ghost_end);
296 operator PatchView<std::add_const_t<T>, D>()
const
298 return PatchView<std::add_const_t<T>, D>(this->getData() +
307 extern template class PatchView<double, 1>;
308 extern template View<double, 1>
310 extern template View<double, 1>
313 extern template class PatchView<double, 2>;
314 extern template View<double, 1>
316 extern template View<double, 2>
318 extern template View<double, 1>
320 extern template View<double, 2>
323 extern template class PatchView<double, 3>;
324 extern template View<double, 1>
326 extern template View<double, 2>
328 extern template View<double, 3>
330 extern template View<double, 1>
332 extern template View<double, 2>
334 extern template View<double, 3>
337 extern template class PatchView<const double, 1>;
338 extern template View<const double, 1>
340 extern template View<double, 1>
343 extern template class PatchView<const double, 2>;
344 extern template View<const double, 1>
346 extern template View<const double, 2>
348 extern template View<double, 1>
350 extern template View<double, 2>
353 extern template class PatchView<const double, 3>;
354 extern template View<const double, 1>
356 extern template View<const double, 2>
358 extern template View<const double, 3>
360 extern template View<double, 1>
362 extern template View<double, 2>
364 extern template View<double, 3>