OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
ParticleIt_Cells.hpp
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 
18 template<unsigned int dim,typename CellListType> class ParticleIt_Cells
19 {
20 private:
21 
23  const size_t * start;
24 
26  const size_t * stop;
27 
29  size_t cid;
30 
33 
35  CellListType & cli;
36 
38  size_t g_m;
39 
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 
64 public:
65 
73  ParticleIt_Cells(CellListType & cli,
75  size_t 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 
111  {
112  ++start;
113  selectValid();
114 
115  while (*start >= g_m)
116  {
117  ++start;
118  selectValid();
119  }
120 
121  return *this;
122  }
123 
129  bool isNext()
130  {
131  return cid < dom_cell.size();
132  }
133 
139  size_t get()
140  {
141  return *start;
142  }
143 };
144 
145 
146 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_PARTICLEIT_CELLS_HPP_ */
size_t cid
Actual cell.
const size_t * start
starting position
ParticleIt_Cells(CellListType &cli, const openfpm::vector< size_t > &dom_cell, size_t g_m)
Initialize the iterator.
size_t size()
Stub size.
Definition: map_vector.hpp:211
const openfpm::vector< size_t > & dom_cell
List of all the domain cells.
const size_t * stop
stop position
ParticleIt_Cells & operator++()
Increment to the next particle.
CellListType & cli
Celllist type.
size_t g_m
Ghost marker.
void selectValid()
Adjust the counters to reach a valid particle element.
bool isNext()
Return true if there is the next particle.
This iterator iterate across the particles of a Cell-list following the Cell structure.
size_t get()
Get the actual particle id.