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