Branch data Line data Source code
1 : : //
2 : : // Class NDIndex
3 : : // This is a simple wrapper around Index that just keeps track of
4 : : // N of them and passes along requests for intersect, etc.
5 : : //
6 : : #ifndef IPPL_NDINDEX_H
7 : : #define IPPL_NDINDEX_H
8 : :
9 : : #include <initializer_list>
10 : :
11 : : #include "Types/Vector.h"
12 : :
13 : : #include "Index/Index.h"
14 : :
15 : : namespace ippl {
16 : : /*!
17 : : * @file NDIndex.h
18 : : * @tparam Dim the number of index dimensions
19 : : */
20 : : template <unsigned Dim>
21 : : class NDIndex {
22 : : public:
23 : : KOKKOS_FUNCTION
24 [ + + ]: 14206 : NDIndex() {}
25 : :
26 : : template <class... Args>
27 : : KOKKOS_FUNCTION NDIndex(const Args&... args);
28 : :
29 : : KOKKOS_FUNCTION NDIndex(const Vector<unsigned, Dim>& sizes);
30 : :
31 : : /*!
32 : : * @returns a reference to any of the Indexes.
33 : : */
34 : : KOKKOS_INLINE_FUNCTION const ippl::Index& operator[](unsigned d) const noexcept;
35 : :
36 : : KOKKOS_INLINE_FUNCTION Index& operator[](unsigned d) noexcept;
37 : :
38 : : /*!
39 : : * @returns the total size.
40 : : */
41 : : KOKKOS_INLINE_FUNCTION unsigned size() const noexcept;
42 : :
43 : : /*!
44 : : * @returns true if empty.
45 : : */
46 : : KOKKOS_INLINE_FUNCTION bool empty() const noexcept;
47 : :
48 : : /*!
49 : : * Intersect with another NDIndex.
50 : : */
51 : : KOKKOS_INLINE_FUNCTION NDIndex<Dim> intersect(const NDIndex<Dim>&) const;
52 : :
53 : : /*!
54 : : * Intersect with another NDIndex.
55 : : */
56 : : KOKKOS_INLINE_FUNCTION NDIndex<Dim> grow(int ncells) const;
57 : :
58 : : KOKKOS_INLINE_FUNCTION NDIndex<Dim> grow(int ncells, unsigned int dim) const;
59 : :
60 : : KOKKOS_INLINE_FUNCTION bool touches(const NDIndex<Dim>&) const;
61 : :
62 : : KOKKOS_INLINE_FUNCTION bool contains(const NDIndex<Dim>& a) const;
63 : :
64 : : // Split on dimension d with at position i
65 : : KOKKOS_INLINE_FUNCTION bool split(NDIndex<Dim>& l, NDIndex<Dim>& r, unsigned d,
66 : : int i) const;
67 : :
68 : : // Split on dimension d with the given ratio 0<a<1.
69 : : KOKKOS_INLINE_FUNCTION bool split(NDIndex<Dim>& l, NDIndex<Dim>& r, unsigned d,
70 : : double a) const;
71 : :
72 : : // Split on dimension d, or the longest dimension.
73 : : KOKKOS_INLINE_FUNCTION bool split(NDIndex<Dim>& l, NDIndex<Dim>& r, unsigned d) const;
74 : :
75 : : KOKKOS_INLINE_FUNCTION bool split(NDIndex<Dim>& l, NDIndex<Dim>& r) const;
76 : :
77 : : KOKKOS_INLINE_FUNCTION Vector<size_t, Dim> length() const;
78 : : KOKKOS_INLINE_FUNCTION Vector<int, Dim> first() const;
79 : : KOKKOS_INLINE_FUNCTION Vector<int, Dim> last() const;
80 : :
81 : : using iterator = Index*;
82 : : using const_iterator = const Index*;
83 : : KOKKOS_INLINE_FUNCTION constexpr iterator begin();
84 : : KOKKOS_INLINE_FUNCTION constexpr iterator end();
85 : : KOKKOS_INLINE_FUNCTION constexpr const_iterator begin() const;
86 : : KOKKOS_INLINE_FUNCTION constexpr const_iterator end() const;
87 : :
88 : : private:
89 : : KOKKOS_FUNCTION
90 : : NDIndex(std::initializer_list<Index> indices);
91 : :
92 : : //! Array of indices
93 : : Index indices_m[Dim];
94 : : };
95 : : } // namespace ippl
96 : :
97 : : #include "Index/NDIndex.hpp"
98 : :
99 : : #endif
|