1/*
2 * CellNNIteratorRuntimeM.hpp
3 *
4 * Created on: Jan 26, 2017
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLNNITERATORRUNTIMEM_HPP_
9#define OPENFPM_DATA_SRC_NN_CELLLIST_CELLNNITERATORRUNTIMEM_HPP_
10
11
12/*! \brief Iterator for the neighborhood of the cell structures
13 *
14 * In general you never create it directly but you get it from the CellList structures
15 *
16 * It iterate across all the element of the selected cell and the near cells
17 *
18 * \note to calculate quantities that involve a total reduction (like energies) use the CellIteratorSymRed
19 *
20 * \tparam dim dimensionality of the space where the cell live
21 * \tparam Cell cell type on which the iterator is working
22 * \tparam impl implementation specific options NO_CHECK do not do check on access, SAFE do check on access
23 *
24 */
25template<unsigned int dim, typename Cell, unsigned int sh_byte, unsigned int impl>
26class CellNNIteratorM<dim,Cell,sh_byte,RUNTIME,impl> : public CellNNIterator<dim,Cell,RUNTIME,impl>
27{
28 typedef boost::low_bits_mask_t<sizeof(size_t)*8-sh_byte> mask_low;
29
30public:
31
32 /*! \brief
33 *
34 * Cell NN iterator
35 *
36 * \param cell Cell id
37 * \param NNc Cell neighborhood indexes (relative)
38 * \param cl Cell structure
39 *
40 */
41 CellNNIteratorM(size_t cell, const long int * NNc, size_t NNc_size, Cell & cl)
42 :CellNNIterator<dim,Cell,RUNTIME,impl>(cell,NNc,NNc_size,cl)
43 {}
44
45
46 /*! \brief Get the value of the cell
47 *
48 * \return the next element object
49 *
50 */
51 inline size_t getP()
52 {
53 return CellNNIterator<dim,Cell,RUNTIME,impl>::get() & mask_low::sig_bits_fast;
54 }
55
56 /*! \brief Get the value of the cell
57 *
58 * \return the next element object
59 *
60 */
61 inline size_t getV()
62 {
63 return (CellNNIterator<dim,Cell,RUNTIME,impl>::get()) >> (sizeof(size_t)*8-sh_byte);
64 }
65};
66
67
68/*! \brief Symmetric iterator for the neighborhood of the cell structures
69 *
70 * In general you never create it directly but you get it from the CellList structures
71 *
72 * It iterate across all the element of the selected cell and the near cells.
73 *
74 * \note if we query the neighborhood of p and q is the neighborhood of p
75 * when we will query the neighborhood of q p is not present. This is
76 * useful to implement formula like \f$ \sum_{q = neighborhood(p) and p <= q} \f$
77 *
78 * \tparam dim dimensionality of the space where the cell live
79 * \tparam Cell cell type on which the iterator is working
80 * \tparam NNc_size neighborhood size
81 * \tparam impl implementation specific options NO_CHECK do not do check on access, SAFE do check on access
82 *
83 */
84template<unsigned int dim, typename Cell, unsigned int sh_byte, unsigned int impl>
85class CellNNIteratorSymM<dim,Cell,sh_byte,RUNTIME,impl> : public CellNNIterator<dim,Cell,RUNTIME,impl>
86{
87 typedef boost::low_bits_mask_t<sizeof(size_t)*8-sh_byte> mask_low;
88
89 //! phase of the particle p
90 size_t pp;
91
92 //! index of the particle p
93 size_t p;
94
95 const typename Cell::internal_vector_pos_type & pos;
96
97 //! Position of the particles in the phases
98 const openfpm::vector<pos_v<typename Cell::internal_vector_pos_type>> & ps;
99
100 /*! Select the next valid element
101 *
102 */
103 inline void selectValid()
104 {
105 if (this->NNc[this->NNc_id] == 0)
106 {
107 while (this->start_id < this->stop_id)
108 {
109 size_t q = this->cl.get_lin(this->start_id);
110 for (long int i = dim-1 ; i >= 0 ; i--)
111 {
112 if (pos.template get<0>(p)[i] < ps.get(q >> (sizeof(size_t)*8-sh_byte)).pos.template get<0>(q & mask_low::sig_bits_fast)[i])
113 return;
114 else if (pos.template get<0>(p)[i] > ps.get(q >> (sizeof(size_t)*8-sh_byte)).pos.template get<0>(q & mask_low::sig_bits_fast)[i])
115 goto next;
116 }
117 if (q >> (sizeof(size_t)*8-sh_byte) != pp) return;
118 if ((q & mask_low::sig_bits_fast) >= p) return;
119next:
120 this->start_id++;
121 }
122
123 CellNNIterator<dim,Cell,RUNTIME,impl>::selectValid();
124 }
125 else
126 {
127 CellNNIterator<dim,Cell,RUNTIME,impl>::selectValid();
128 }
129 }
130
131public:
132
133 /*! \brief
134 *
135 * Cell NN iterator
136 *
137 * \param cell Cell id
138 * \param NNc Cell neighborhood indexes (relative)
139 * \param cl Cell structure
140 *
141 */
142 CellNNIteratorSymM(size_t cell,
143 size_t pp,
144 size_t p,
145 const long int * NNc,
146 size_t NNc_size,
147 Cell & cl,
148 const typename Cell::internal_vector_pos_type & pos,
149 const openfpm::vector<pos_v<typename Cell::internal_vector_pos_type>> & ps)
150 :CellNNIterator<dim,Cell,RUNTIME,impl>(cell,NNc,NNc_size,cl),pp(pp),p(p),pos(pos),ps(ps)
151 {}
152
153
154 /*! \brief Get the value of the cell
155 *
156 * \return the next element object
157 *
158 */
159 inline size_t getP()
160 {
161 return CellNNIterator<dim,Cell,RUNTIME,impl>::get() & mask_low::sig_bits_fast;
162 }
163
164 /*! \brief Get the value of the cell
165 *
166 * \return the next element object
167 *
168 */
169 inline size_t getV()
170 {
171 return (CellNNIterator<dim,Cell,RUNTIME,impl>::get()) >> (sizeof(size_t)*8-sh_byte);
172 }
173
174 /*! \brief take the next element
175 *
176 * \return itself
177 *
178 */
179 inline CellNNIteratorSymM<dim,Cell,sh_byte,RUNTIME,impl> & operator++()
180 {
181 this->start_id++;
182
183 selectValid();
184
185 return *this;
186 }
187};
188
189
190#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLNNITERATORRUNTIMEM_HPP_ */
191