1/*
2 * CellListM.hpp
3 *
4 * Created on: Jun 23, 2016
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTM_HPP_
9#define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTM_HPP_
10
11#include "CellList.hpp"
12#include "CellNNIteratorM.hpp"
13
14struct PV_cl
15{
16 //! phase id
17 size_t v;
18};
19
20/*! \brief Class for Multi-Phase cell-list
21 *
22 * This class implement a Multi-Phase cell list. In practice this Cell list can contain
23 * the particles from multiple vector distributed. By default this cell list is based on
24 * Cell list fast with shifting
25 *
26 * \verbatim
27 * +-----------------------+
28 * |p |p |p |p |p |p |p |p |
29 * +-----------------------+
30 * |p | | | | | | |p |
31 * +-----------------------+
32 * |p | | | | | | |p |
33 * +-----------------------+
34 * |p | | | | | | |p |
35 * +-----------------------+
36 * |p |9 | | | | | |p |
37 * +-----------------------+
38 * |p |p |p |p |p |p |p |p |
39 * +-----------------------+
40 * \endverbatim
41 *
42 * \tparam dim dimensionality
43 * \tparam T type of the space
44 * \tparam sh_byte bit to dedicate to the phases informations
45 * \tparam CellBase Base cell list used for the implementation
46 *
47 * ### Declaration of a Multi-Phase cell list and usage
48 *
49 */
50template<unsigned int dim, typename T, unsigned int sh_byte, typename CellBase=CellList<dim,T,Mem_fast<>,shift<dim, T>> >
51class CellListM : public CellBase
52{
53 //! Mask to get the high bits of a number
54 typedef boost::high_bit_mask_t<sh_byte> mask_high;
55
56 //! Mask to get the low bits of a number
57 typedef boost::low_bits_mask_t<sizeof(size_t)*8-sh_byte> mask_low;
58
59public:
60
61 //! Type of the iterator for the neighborhood
62 typedef CellNNIteratorSymM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,RUNTIME,NO_CHECK> SymNNIterator;
63
64 //! Default Constructor
65 CellListM()
66 {};
67
68 /*! \brief Copy constructor
69 *
70 * \param cell Cell to copy
71 *
72 */
73 CellListM(const CellListM<dim,T,sh_byte,CellBase> & cell)
74 {
75 this->operator=(cell);
76 }
77
78 /*! \brief Copy constructor
79 *
80 * \param cell Cell to copy
81 *
82 */
83 CellListM(CellListM<dim,T,sh_byte,CellBase> && cell)
84 {
85 this->operator=(cell);
86 }
87
88
89 /*! \brief Cell list constructor
90 *
91 * \param box Domain where this cell list is living
92 * \param div grid size on each dimension
93 * \param mat Matrix transformation
94 * \param pad Cell padding
95 * \param slot maximum number of slot
96 *
97 */
98 CellListM(Box<dim,T> & box, const size_t (&div)[dim], Matrix<dim,T> mat, const size_t pad = 1, size_t slot=STARTING_NSLOT)
99 :CellBase(box,div,mat,pad,slot)
100 {}
101
102 /*! \brief Cell list constructor
103 *
104 * \param box Domain where this cell list is living
105 * \param div grid size on each dimension
106 * \param pad Cell padding
107 * \param slot maximum number of slot
108 *
109 */
110 CellListM(Box<dim,T> & box, const size_t (&div)[dim], const size_t pad = 1, size_t slot=STARTING_NSLOT)
111 :CellBase(box,div,pad,slot)
112 {}
113
114
115 /*! \brief Destructor
116 *
117 *
118 */
119 ~CellListM()
120 {}
121
122 /*! \brief Add to the cell
123 *
124 * \param cell_id Cell id where to add
125 * \param ele element to add
126 * \param v_id phase id
127 *
128 */
129 inline void addCell(size_t cell_id, size_t ele, size_t v_id)
130 {
131 size_t ele_k = ele | (v_id << (sizeof(size_t)*8-sh_byte));
132
133 CellBase::addCell(cell_id,ele_k);
134 }
135
136 /*! \brief Add an element in the cell list
137 *
138 * \param pos array that contain the coordinate
139 * \param ele element to store
140 * \param v_id phase id
141 *
142 */
143 inline void add(const T (& pos)[dim], size_t ele, size_t v_id)
144 {
145 // calculate the Cell id
146
147 size_t cell_id = this->getCell(pos);
148 size_t ele_k = ele | (v_id << (sizeof(size_t)*8-sh_byte));
149
150 // add the element to the cell
151
152 CellBase::addCell(cell_id,ele_k);
153 }
154
155 /*! \brief Add an element in the cell list
156 *
157 * \param pos array that contain the coordinate
158 * \param ele element to store
159 * \param v_id phase id
160 *
161 */
162 inline void add(const Point<dim,T> & pos, size_t ele, size_t v_id)
163 {
164 // calculate the Cell id
165
166 size_t cell_id = this->getCell(pos);
167 size_t ele_k = ele | (v_id << (sizeof(size_t)*8-sh_byte));
168
169 // add the element to the cell
170
171 CellBase::addCell(cell_id,ele_k);
172 }
173
174 /*! \brief Convert an element in particle id
175 *
176 * \param ele element id
177 *
178 * \return The element value
179 *
180 */
181 static inline size_t getP(size_t ele)
182 {
183 return ele & mask_low::sig_bits_fast;
184 }
185
186 /*! \brief Convert an element in phase id
187 *
188 * \param ele element id
189 *
190 * \return The element value
191 *
192 */
193 static inline size_t getV(size_t ele)
194 {
195 return ele >> (sizeof(size_t)*8-sh_byte);
196 }
197
198 /*! \brief Get the element-id in the cell
199 *
200 * \tparam i property to get
201 *
202 * \param cell cell id
203 * \param ele element id
204 *
205 * \return The element value
206 *
207 */
208 inline size_t getP(size_t cell, size_t ele)
209 {
210 return CellBase::get(cell,ele) & mask_low::sig_bits_fast;
211 }
212
213 /*! \brief Get the element vector in the cell
214 *
215 * \tparam i property to get
216 *
217 * \param cell cell id
218 * \param ele element id
219 *
220 * \return The element value
221 *
222 */
223 inline size_t getV(size_t cell, size_t ele)
224 {
225 return (CellBase::get(cell,ele)) >> (sizeof(size_t)*8-sh_byte);
226 }
227
228 /*! \brief Swap the memory
229 *
230 * \param cl Cell list with witch you swap the memory
231 *
232 */
233 inline void swap(CellListM<dim,T,sh_byte,CellBase> & cl)
234 {
235 CellBase::swap(*this);
236 }
237
238 /*! \brief Get the Cell iterator
239 *
240 * \param cell
241 *
242 * \return the iterator to the elements inside cell
243 *
244 */
245 CellIterator<CellListM<dim,T,sh_byte,CellBase>> getIterator(size_t cell)
246 {
247 return CellBase::getIterator(cell);
248 }
249
250 /*! \brief Get the Neighborhood iterator
251 *
252 * It iterate across all the element of the selected cell and the near cells
253 *
254 * \verbatim
255
256 * * *
257 * x *
258 * * *
259
260 \endverbatim
261 *
262 * * x is the selected cell
263 * * * are the near cell
264 *
265 * \param cell cell id
266 *
267 * \return an iterator over the particle of the selected cell
268 *
269 */
270 template<unsigned int impl=NO_CHECK> inline CellNNIteratorM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,FULL,impl> getNNIterator(size_t cell)
271 {
272 CellNNIteratorM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,FULL,impl> cln(cell,CellListM<dim,T,sh_byte,CellBase>::NNc_full,*this);
273
274 return cln;
275 }
276
277
278 /*! \brief Get the Neighborhood iterator
279 *
280 * It iterate across all the element of the selected cell and the near cells
281 *
282 * \verbatim
283
284 * * *
285 x *
286
287 \endverbatim
288 *
289 * * x is the selected cell
290 * * * are the near cell
291 *
292 * \param cell cell id
293 *
294 * \return Cell-list structure
295 *
296 */
297 template<unsigned int impl> inline CellNNIteratorSymM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,SYM,impl>
298 getNNIteratorSym(size_t cell,
299 size_t pp,
300 size_t p,
301 const typename CellBase::internal_vector_pos_type & pos,
302 const openfpm::vector<pos_v<typename CellBase::internal_vector_pos_type>> & v)
303 {
304 CellNNIteratorSymM<dim,CellListM<dim,T,sh_byte,CellBase>,sh_byte,SYM,impl> cln(cell,pp,p,CellListM<dim,T,sh_byte,CellBase>::NNc_sym,*this,pos,v);
305
306 return cln;
307 }
308
309
310 /*! \brief operator=
311 *
312 * \param clm Cell list to copy
313 *
314 * \return Cell-list structure
315 *
316 */
317 CellListM<dim,T,sh_byte,CellBase> & operator=(CellListM<dim,T,sh_byte,CellBase> && clm)
318 {
319 CellBase::swap(clm);
320
321 return *this;
322 }
323
324 /*! \brief operator=
325 *
326 * \param clm Cell list to copy
327 *
328 * \return Cell-list structure
329 *
330 */
331 CellListM<dim,T,sh_byte,CellBase> & operator=(const CellListM<dim,T,sh_byte,CellBase> & clm)
332 {
333 static_cast<CellBase *>(this)->operator=(*static_cast<const CellBase *>(&clm));
334
335 return *this;
336 }
337};
338
339#endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTM_HPP_ */
340