1/*
2 * ParticleIt_Cells.hpp
3 *
4 * Created on: Mar 5, 2017
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_PARTICLEIT_CELLS_HPP_
9#define OPENFPM_DATA_SRC_NN_CELLLIST_PARTICLEIT_CELLS_HPP_
10
11/*! \brief This iterator iterate across the particles of a Cell-list following the Cell structure
12 *
13 *
14 * \tparam dim Dimensionality
15 * \tparam CellListType type of the cell-list
16 *
17 */
18template<unsigned int dim,typename CellListType> class ParticleIt_Cells
19{
20private:
21
22 //! starting position
23 const size_t * start;
24
25 //! stop position
26 const size_t * stop;
27
28 //! Actual cell
29 size_t cid;
30
31 //! List of all the domain cells
32 const openfpm::vector<size_t> &dom_cell;
33
34 //! Celllist type
35 CellListType & cli;
36
37 //! Ghost marker
38 size_t g_m;
39
40 /*! \brief Adjust the counters to reach a valid particle element
41 *
42 *
43 */
44 void selectValid()
45 {
46 while (start == stop)
47 {
48 cid++;
49
50 size_t s_cell;
51 if (cid >= dom_cell.size())
52 return;
53 else
54 s_cell = dom_cell.get(cid);
55
56 // Get the starting particle
57 start = &cli.getStartId(s_cell);
58
59 // Get the stop particle
60 stop = &cli.getStopId(s_cell);
61 }
62 }
63
64public:
65
66 /*! \brief Initialize the iterator
67 *
68 * \param cli Cell-list
69 * \param dom_cell domain cell
70 * \param g_m ghost marker
71 *
72 */
73 ParticleIt_Cells(CellListType & cli,
74 const openfpm::vector<size_t> & dom_cell,
75 size_t g_m)
76 :cid(0),dom_cell(dom_cell),cli(cli),g_m(g_m)
77 {
78 size_t s_cell;
79 if (dom_cell.size() != 0)
80 s_cell = dom_cell.get(0);
81 else
82 {
83 cid = 1;
84 start = NULL;
85 stop = NULL;
86
87 return;
88 }
89
90 // Get the starting particle
91 start = &cli.getStartId(s_cell);
92
93 // Get the stop particle
94 stop = &cli.getStopId(s_cell);
95
96 selectValid();
97
98 while (*start >= g_m)
99 {
100 ++start;
101 selectValid();
102 }
103 }
104
105 /*! \brief Increment to the next particle
106 *
107 * \return The actual particle iterator
108 *
109 */
110 ParticleIt_Cells & operator++()
111 {
112 ++start;
113 selectValid();
114
115 while (*start >= g_m)
116 {
117 ++start;
118 selectValid();
119 }
120
121 return *this;
122 }
123
124 /*! \brief Return true if there is the next particle
125 *
126 * \return true if there is a new point
127 *
128 */
129 bool isNext()
130 {
131 return cid < dom_cell.size();
132 }
133
134 /*! \brief Get the actual particle id
135 *
136 * \return the actual particle id
137 *
138 */
139 size_t get()
140 {
141 return *start;
142 }
143};
144
145
146#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_PARTICLEIT_CELLS_HPP_ */
147