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 [ + + ]: 12194 : NDIndex() {}
25 : :
26 : : template <class... Args>
27 : : KOKKOS_FUNCTION NDIndex(const Args&... args);
28 : :
29 : : /*!
30 : : * @returns a reference to any of the Indexes.
31 : : */
32 : : KOKKOS_INLINE_FUNCTION const ippl::Index& operator[](unsigned d) const noexcept;
33 : :
34 : : KOKKOS_INLINE_FUNCTION Index& operator[](unsigned d) noexcept;
35 : :
36 : : /*!
37 : : * @returns the total size.
38 : : */
39 : : KOKKOS_INLINE_FUNCTION unsigned size() const noexcept;
40 : :
41 : : /*!
42 : : * @returns true if empty.
43 : : */
44 : : KOKKOS_INLINE_FUNCTION bool empty() const noexcept;
45 : :
46 : : /*!
47 : : * Intersect with another NDIndex.
48 : : */
49 : : KOKKOS_INLINE_FUNCTION NDIndex<Dim> intersect(const NDIndex<Dim>&) const;
50 : :
51 : : /*!
52 : : * Intersect with another NDIndex.
53 : : */
54 : : KOKKOS_INLINE_FUNCTION NDIndex<Dim> grow(int ncells) const;
55 : :
56 : : KOKKOS_INLINE_FUNCTION NDIndex<Dim> grow(int ncells, unsigned int dim) const;
57 : :
58 : : KOKKOS_INLINE_FUNCTION bool touches(const NDIndex<Dim>&) const;
59 : :
60 : : KOKKOS_INLINE_FUNCTION bool contains(const NDIndex<Dim>& a) const;
61 : :
62 : : // Split on dimension d with at position i
63 : : KOKKOS_INLINE_FUNCTION bool split(NDIndex<Dim>& l, NDIndex<Dim>& r, unsigned d,
64 : : int i) const;
65 : :
66 : : // Split on dimension d with the given ratio 0<a<1.
67 : : KOKKOS_INLINE_FUNCTION bool split(NDIndex<Dim>& l, NDIndex<Dim>& r, unsigned d,
68 : : double a) const;
69 : :
70 : : // Split on dimension d, or the longest dimension.
71 : : KOKKOS_INLINE_FUNCTION bool split(NDIndex<Dim>& l, NDIndex<Dim>& r, unsigned d) const;
72 : :
73 : : KOKKOS_INLINE_FUNCTION bool split(NDIndex<Dim>& l, NDIndex<Dim>& r) const;
74 : :
75 : : KOKKOS_INLINE_FUNCTION Vector<size_t, Dim> length() const;
76 : : KOKKOS_INLINE_FUNCTION Vector<int, Dim> first() const;
77 : : KOKKOS_INLINE_FUNCTION Vector<int, Dim> last() const;
78 : :
79 : : using iterator = Index*;
80 : : using const_iterator = const Index*;
81 : : KOKKOS_INLINE_FUNCTION constexpr iterator begin();
82 : : KOKKOS_INLINE_FUNCTION constexpr iterator end();
83 : : KOKKOS_INLINE_FUNCTION constexpr const_iterator begin() const;
84 : : KOKKOS_INLINE_FUNCTION constexpr const_iterator end() const;
85 : :
86 : : private:
87 : : KOKKOS_FUNCTION
88 : : NDIndex(std::initializer_list<Index> indices);
89 : :
90 : : //! Array of indices
91 : : Index indices_m[Dim];
92 : : };
93 : : } // namespace ippl
94 : :
95 : : #include "Index/NDIndex.hpp"
96 : :
97 : : #endif
|