chombo-discharge
CD_BoxLoopsImplem.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_BoxLoopsImplem_H
13 #define CD_BoxLoopsImplem_H
14 
15 // Our includes
16 #include <CD_NamespaceHeader.H>
17 
18 template <typename Functor>
19 ALWAYS_INLINE void
20 BoxLoops::loop(const Box& computeBox, Functor&& func, const IntVect& a_stride)
21 {
22 
23  CH_assert(a_stride > IntVect::Zero);
24 
25  const int* lo = computeBox.loVect();
26  const int* hi = computeBox.hiVect();
27 
28  // TLDR: This runs through all cells in the computeBox and calls the kernel function.
29 #if CH_SPACEDIM == 3
30  for (int k = lo[2]; k <= hi[2]; k += a_stride[2]) {
31 #endif
32  for (int j = lo[1]; j <= hi[1]; j += a_stride[1]) {
33  CD_PRAGMA_SIMD
34  for (int i = lo[0]; i <= hi[0]; i += a_stride[0]) {
35  func(IntVect(D_DECL(i, j, k)));
36  }
37  }
38 #if CH_SPACEDIM == 3
39  }
40 #endif
41 }
42 
43 template <typename Functor>
44 ALWAYS_INLINE void
45 BoxLoops::loop(const IntVectSet& a_ivs, Functor&& a_kernel)
46 {
47  for (IVSIterator iter(a_ivs); iter.ok(); ++iter) {
48  a_kernel(iter());
49  }
50 }
51 
52 template <typename Functor>
53 ALWAYS_INLINE void
54 BoxLoops::loop(const DenseIntVectSet& a_ivs, Functor&& a_kernel)
55 {
56  for (DenseIntVectSetIterator iter(a_ivs); iter.ok(); ++iter) {
57  a_kernel(iter());
58  }
59 }
60 
61 template <typename Functor>
62 ALWAYS_INLINE void
63 BoxLoops::loop(VoFIterator& iter, Functor&& a_kernel)
64 {
65 
66  // TLDR: This runs through all cells in the vof-iterator and calls the kernel.
67  for (iter.reset(); iter.ok(); ++iter) {
68  a_kernel(iter());
69  }
70 }
71 
72 template <typename Functor>
73 ALWAYS_INLINE void
74 BoxLoops::loop(FaceIterator& iter, Functor&& a_kernel)
75 {
76 
77  // TLDR: This runs through all cells in the vof-iterator and calls the kernel.
78  for (iter.reset(); iter.ok(); ++iter) {
79  a_kernel(iter());
80  }
81 }
82 
83 template <typename T, typename Functor>
84 ALWAYS_INLINE void
85 BoxLoops::loop(const Vector<T>& a_subset, Functor&& a_kernel)
86 {
87  const std::vector<T>& stdVec = ((Vector<T>&)a_subset).stdVector();
88 
89  for (const auto& v : stdVec) {
90  a_kernel(v);
91  }
92 }
93 
94 #include <CD_NamespaceFooter.H>
95 
96 #endif
ALWAYS_INLINE void loop(const Box &a_computeBox, Functor &&kernel, const IntVect &a_stride=IntVect::Unit)
Launch a C++ kernel over a regular grid.
Definition: CD_BoxLoopsImplem.H:20