OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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)
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 
105  {
106  ++start;
107  selectValid();
108 
109  while (*start >= g_m)
110  {
111  ++start;
112  selectValid();
113  }
114 
115  return *this;
116  }
117 
123  bool isNext()
124  {
125  return cid < dom_cell.size();
126  }
127 
133  size_t get()
134  {
135  return *start;
136  }
137 };
138 
139 
140 #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:70
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.