1 | /* |
2 | * CellListNNIteratorRadius.hpp |
3 | * |
4 | * Created on: Aug 17, 2016 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTNNITERATORRADIUS_HPP_ |
9 | #define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTNNITERATORRADIUS_HPP_ |
10 | |
11 | #include "Vector/map_vector.hpp" |
12 | |
13 | /*! \brief Iterator for the neighborhood of the cell structures with free radius |
14 | * |
15 | * In general you never create it directly but you get it from the CellList structures |
16 | * |
17 | * It iterate across all the element of the selected cell and the near cells (inside a radius) |
18 | * |
19 | * \tparam dim dimensionality of the space where the cell live |
20 | * \tparam Cell cell type on which the iterator is working |
21 | * \tparam NNc_size neighborhood size |
22 | * \tparam impl implementation specific options NO_CHECK do not do check on access, SAFE do check on access |
23 | * |
24 | */ |
25 | template<unsigned int dim, typename Cell, unsigned int impl> class CellNNIteratorRadius |
26 | { |
27 | // Cell list |
28 | Cell & cl; |
29 | |
30 | // Actual NNc_id; |
31 | size_t NNc_id; |
32 | |
33 | // actual cell id = NNc[NNc_id]+cell stored for performance reason |
34 | size_t cell_id; |
35 | |
36 | // actual element id |
37 | size_t ele_id; |
38 | |
39 | // NN number of neighborhood cells |
40 | const openfpm::vector<long int> & NNc; |
41 | |
42 | // Center cell, or cell for witch we are searching the NN-cell |
43 | const long int cell; |
44 | |
45 | /*! \brief Select non-empty cell |
46 | * |
47 | */ |
48 | inline void selectValid() |
49 | { |
50 | while (ele_id >= cl.getNelements(cell_id)) |
51 | { |
52 | NNc_id++; |
53 | |
54 | // No more Cell |
55 | if (NNc_id >= NNc.size()) return; |
56 | |
57 | cell_id = NNc.get(NNc_id) + cell; |
58 | |
59 | ele_id = 0; |
60 | } |
61 | } |
62 | |
63 | public: |
64 | |
65 | /*! \brief |
66 | * |
67 | * Cell NN iterator |
68 | * |
69 | * \param cell Cell id |
70 | * \param NNc Cell neighborhood indexes (relative) |
71 | * \param cl Cell structure |
72 | * |
73 | */ |
74 | inline CellNNIteratorRadius(size_t cell, const openfpm::vector<long int> &NNc, Cell & cl) |
75 | :cl(cl),NNc_id(0),cell_id(NNc.get(NNc_id) + cell),ele_id(0),NNc(NNc),cell(cell) |
76 | { |
77 | #ifdef SE_CLASS1 |
78 | if (cell_id < 0) |
79 | std::cerr << "Error " << __FILE__ ":" << __LINE__ << " cell_id is negative, please check the the padding is chosen correctly." << |
80 | "Remember, if you choose a radius that span N neighborhood cell-list, padding must be one" << std::endl; |
81 | #endif |
82 | |
83 | selectValid(); |
84 | } |
85 | |
86 | /*! \brief |
87 | * |
88 | * Check if there is the next element |
89 | * |
90 | */ |
91 | inline bool isNext() |
92 | { |
93 | if (NNc_id >= NNc.size()) |
94 | return false; |
95 | return true; |
96 | } |
97 | |
98 | /*! \brief take the next element |
99 | * |
100 | */ |
101 | inline CellNNIteratorRadius & operator++() |
102 | { |
103 | ele_id++; |
104 | |
105 | selectValid(); |
106 | |
107 | return *this; |
108 | } |
109 | |
110 | /*! \brief Get the value of the cell |
111 | * |
112 | * \return the next element object |
113 | * |
114 | */ |
115 | inline typename Cell::value_type & get() |
116 | { |
117 | return cl.get(cell_id,ele_id); |
118 | } |
119 | }; |
120 | |
121 | |
122 | #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTNNITERATORRADIUS_HPP_ */ |
123 | |