OpenFPM  5.2.0
Project that contain the implementation of distributed structures
CellNNIteratorRadius.hpp
1 /*
2  * CellNNIteratorRadius.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 
24 template<unsigned int dim, typename Cell> class CellNNIteratorRadius
25 {
26  // Cell list
27  Cell & cl;
28 
29  // Actual NNc_id;
30  size_t NNc_id;
31 
32  // actual cell id = NNc[NNc_id]+cell stored for performance reason
33  size_t cell_id;
34 
35  // actual element id
36  size_t ele_id;
37 
38  // NN number of neighborhood cells
39  const openfpm::vector<long int> & NNc;
40 
41  // Center cell, or cell for witch we are searching the NN-cell
42  const long int cell;
43 
47  inline void selectValid()
48  {
49  while (ele_id >= cl.getNelements(cell_id))
50  {
51  NNc_id++;
52 
53  // No more Cell
54  if (NNc_id >= NNc.size()) return;
55 
56  cell_id = NNc.get(NNc_id) + cell;
57 
58  ele_id = 0;
59  }
60  }
61 
62 public:
63 
73  inline CellNNIteratorRadius(size_t cell, const openfpm::vector<long int> &NNc, Cell & cl)
74  :cl(cl),NNc_id(0),cell_id(NNc.get(NNc_id) + cell),ele_id(0),NNc(NNc),cell(cell)
75  {
76 #ifdef SE_CLASS1
77  if (cell_id < 0)
78  std::cerr << "Error " << __FILE__ ":" << __LINE__ << " cell_id is negative, please check the the padding is chosen correctly." <<
79  "Remember, if you choose a radius that span N neighborhood cell-list, padding must be one" << std::endl;
80 #endif
81 
82  selectValid();
83  }
84 
90  inline bool isNext()
91  {
92  if (NNc_id >= NNc.size())
93  return false;
94  return true;
95  }
96 
101  {
102  ele_id++;
103 
104  selectValid();
105 
106  return *this;
107  }
108 
114  inline typename Cell::value_type & get()
115  {
116  return cl.get(cell_id,ele_id);
117  }
118 };
119 
120 
121 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTNNITERATORRADIUS_HPP_ */
Iterator for the neighborhood of the cell structures with free radius.
Cell::value_type & get()
Get the value of the cell.
CellNNIteratorRadius & operator++()
take the next element
bool isNext()
Check if there is the next element.
void selectValid()
Select non-empty cell.
CellNNIteratorRadius(size_t cell, const openfpm::vector< long int > &NNc, Cell &cl)
Cell NN iterator.
size_t size()
Stub size.
Definition: map_vector.hpp:212