OpenFPM  5.2.0
Project that contain the implementation of distributed structures
CellListIterator.hpp
1 
2 /*
3  * CellListIt.hpp
4  *
5  * Created on: May 18, 2016
6  * Author: Yaroslav Zaluzhnyi
7  */
8 
9 #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_HPP_
10 #define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_HPP_
11 
12 template<typename CellList_type>
14 {
15 private:
16 
17  CellList_type & cellList;
18 
19  size_t cellIndexAct;
20  size_t partIndexAct;
21 
22 
26  inline void selectValid()
27  {
28  ++partIndexAct;
29 
30  const auto & SFCkeys = cellList.getCellSFCKeys();
31 
32  if (partIndexAct >= (long int)cellList.getNelements(SFCkeys.get(cellIndexAct)))
33  {
34  partIndexAct = 0;
35  ++cellIndexAct;
36 
37  while (cellIndexAct < SFCkeys.size() && cellList.getNelements(SFCkeys.get(cellIndexAct)) == 0)
38  ++cellIndexAct;
39  }
40  }
41 
42 public:
43 
44  ParticleIt_CellP(CellList_type & cellList)
45  :cellList(cellList) { reset(); }
46 
53  {
54  selectValid();
55  while (isNext() && this->get() >= cellList.getGhostMarker())
56  selectValid();
57 
58  return *this;
59  }
60 
61 
67  inline bool isNext()
68  {
69  if (cellIndexAct >= cellList.getCellSFCKeys().size())
70  return false;
71 
72  return true;
73  }
74 
75 
82  inline size_t get()
83  {
84  auto cellIndex = cellList.getCellSFCKeys().get(cellIndexAct);
85  auto p = cellList.get(cellIndex,partIndexAct);
86 
87  return p;
88  }
89 
93  void reset()
94  {
95  cellIndexAct = 0;
96  partIndexAct = -1;
97 
98  this->operator++();
99  }
100 };
101 
102 
103 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_HPP_ */
void reset()
Reset an iterator (set the counters to the first valid ones)
void selectValid()
Handles incrementing of cells and particles counters.
bool isNext()
Checks if there is a next element.
size_t get()
Get the real particle id.
ParticleIt_CellP & operator++()
Get the next element.