OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
CellList.hpp
1/*
2 * CellList.hpp
3 *
4 * Created on: Mar 21, 2015
5 * Author: Pietro Incardona
6 */
7
8#ifndef CELLLIST_HPP_
9#define CELLLIST_HPP_
10
11#include "CellList_def.hpp"
12#include "Vector/map_vector.hpp"
13#include "CellDecomposer.hpp"
14#include "Space/SpaceBox.hpp"
15#include "util/mathutil.hpp"
16#include "CellNNIterator.hpp"
17#include "Space/Shape/HyperCube.hpp"
18#include "CellListNNIteratorRadius.hpp"
19#include <unordered_map>
20
21#include "CellListIterator.hpp"
22#include "ParticleIt_Cells.hpp"
23#include "ParticleItCRS_Cells.hpp"
24#include "util/common.hpp"
25
26#include "NN/Mem_type/MemFast.hpp"
27#include "NN/Mem_type/MemBalanced.hpp"
28#include "NN/Mem_type/MemMemoryWise.hpp"
29#include "NN/CellList/NNc_array.hpp"
30#include "cuda/CellList_cpu_ker.cuh"
31
33template<typename key,typename val>
34class wrap_unordered_map: public std::unordered_map<key,val>
35{
36};
37
38#ifdef HAVE_LIBQUADMATH
39
40#include <boost/multiprecision/float128.hpp>
41
42
44template<typename val>
45class wrap_unordered_map<boost::multiprecision::float128,val>
46{
47};
48
49#endif
50
52#define CELL_REALLOC 16ul
53
54#define STARTING_NSLOT 16
55
62template<unsigned int dim> void NNcalc_csr(openfpm::vector<std::pair<grid_key_dx<dim>,grid_key_dx<dim>>> & cNN)
63{
64 // Calculate the NNc_full array, it is a structure to get the neighborhood array
65
66 // compile-time array {0,0,0,....} {2,2,2,...} {1,1,1,...}
67
68 typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
69 typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
70
71 // Generate the sub-grid iterator
72
73 size_t div[dim];
74
75 // Calculate the divisions
76
77 for (size_t i = 0 ; i < dim ; i++)
78 div[i] = 4;
79
80 grid_sm<dim,void> gs(div);
81 grid_key_dx_iterator_sub<dim> gr_sub3(gs,NNzero::data,NNtwo::data);
82
83 grid_key_dx<dim> src_; // Source cell
84 for (size_t i = 0; i < dim; i++)
85 src_.set_d(i,1);
86
87 size_t middle = gs.LinId(src_);
88
89 // Calculate the symmetric crs array
90 while (gr_sub3.isNext())
91 {
92 auto dst = gr_sub3.get();
93 grid_key_dx<dim> src = src_;
94
95 if ((long int)middle > gs.LinId(dst))
96 {
97 ++gr_sub3;
98 continue;
99 }
100
101 // Here we adjust src and dst to be in the positive quadrant
102
103 for (size_t i = 0 ; i < dim; i++)
104 {
105 if (dst.get(i) == 0)
106 {
107 src.set_d(i,src.get(i) + 1);
108 dst.set_d(i,dst.get(i) + 1);
109 }
110 }
111
112 src -= src_;
113 dst -= src_;
114
115 cNN.add(std::pair<grid_key_dx<dim>,grid_key_dx<dim>>(src,dst));
116
117 ++gr_sub3;
118
119 }
120};
121
128template<unsigned int dim> void NNcalc_sym(openfpm::vector<grid_key_dx<dim>> & cNN)
129{
130 // Calculate the NNc_full array, it is a structure to get the neighborhood array
131
132 // compile-time array {0,0,0,....} {2,2,2,...} {1,1,1,...}
133
134 typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
135 typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
136
137 // Generate the sub-grid iterator
138
139 size_t div[dim];
140
141 // Calculate the divisions
142
143 for (size_t i = 0 ; i < dim ; i++)
144 div[i] = 4;
145
146 grid_sm<dim,void> gs(div);
147 grid_key_dx_iterator_sub<dim> gr_sub3(gs,NNzero::data,NNtwo::data);
148
149 grid_key_dx<dim> src_; // Source cell
150 for (size_t i = 0; i < dim; i++)
151 src_.set_d(i,1);
152
153 size_t middle = gs.LinId(src_);
154
155 // Calculate the symmetric array
156 while (gr_sub3.isNext())
157 {
158 auto dst = gr_sub3.get();
159
160 if ((long int)middle > gs.LinId(dst))
161 {
162 ++gr_sub3;
163 continue;
164 }
165
166 cNN.add(dst - src_);
167
168 ++gr_sub3;
169
170 }
171};
172
179template<unsigned int dim> void NNcalc_full(openfpm::vector<grid_key_dx<dim>> & cNN)
180{
181 // Calculate the NNc_full array, it is a structure to get the neighborhood array
182
183 // compile-time array {0,0,0,....} {2,2,2,...} {1,1,1,...}
184
185 typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
186 typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
187
188 // Generate the sub-grid iterator
189
190 size_t div[dim];
191
192 // Calculate the divisions
193
194 for (size_t i = 0 ; i < dim ; i++)
195 {div[i] = 4;}
196
197 grid_sm<dim,void> gs(div);
198 grid_key_dx_iterator_sub<dim> gr_sub3(gs,NNzero::data,NNtwo::data);
199
200 grid_key_dx<dim> src_; // Source cell
201 for (size_t i = 0; i < dim; i++)
202 src_.set_d(i,1);
203
204 // Calculate the symmetric crs array
205 while (gr_sub3.isNext())
206 {
207 auto dst = gr_sub3.get();
208
209 cNN.add(dst - src_);
210
211 ++gr_sub3;
212 }
213};
214
215
249template<unsigned int dim, typename T>
250void NNcalc_rad(T r_cut, openfpm::vector<long int> & NNcell, const Box<dim,T> & cell_box, const grid_sm<dim,void> & gs)
251{
252 size_t n_cell[dim];
253 size_t n_cell_mid[dim];
254
255 Point<dim,T> spacing = cell_box.getP2();
256
257 for (size_t i = 0 ; i < dim ; i++)
258 {
259 n_cell[i] = 2*(std::ceil(r_cut / spacing.get(i)))+1;
260 n_cell_mid[i] = n_cell[i] / 2;
261 }
262
263 grid_sm<dim,void> gsc(n_cell);
265
266 Box<dim,T> cell_zero;
267
268 for (unsigned int i = 0 ; i < dim ; i++)
269 {
270 cell_zero.setLow(i,n_cell_mid[i]*spacing.get(i));
271 cell_zero.setHigh(i,(n_cell_mid[i]+1)*spacing.get(i));
272 }
273
274 NNcell.clear();
275 while (gkdi.isNext())
276 {
277 auto key = gkdi.get();
278
279 Box<dim,T> cell;
280
281 for (unsigned int i = 0 ; i < dim ; i++)
282 {
283 cell.setLow(i,key.get(i)*spacing.get(i));
284 cell.setHigh(i,(key.get(i)+1)*spacing.get(i));
285 }
286
287 // here we check if the cell is in the radius.
288 T min_distance = cell.min_distance(cell_zero);
289 if (min_distance > r_cut)
290 {++gkdi;continue;}
291
292 for (size_t i = 0 ; i < dim ; i++)
293 {key.set_d(i,key.get(i) - n_cell_mid[i]);}
294
295 NNcell.add(gs.LinId(key));
296
297 ++gkdi;
298 }
299}
300
301/* NOTE all the implementations
302 *
303 * has complexity O(1) in getting the cell id and the elements in a cell
304 * but with different constants
305 *
306 */
307
355template<unsigned int dim, typename T, typename Mem_type, typename transform = no_transform<dim,T>, typename vector_pos_type = openfpm::vector<Point<dim,T>>>
356class CellList : public CellDecomposer_sm<dim,T,transform>, public Mem_type
357{
358protected:
360 //
361 // * * *
362 // * x *
363 // * * *
364
365
366 NNc_array<dim,(unsigned int)openfpm::math::pow(3,dim)> NNc_full;
367
369 //
370 // * * *
371 // x *
372 //
373// long int NNc_sym[openfpm::math::pow(3,dim)/2+1];
374 NNc_array<dim,(unsigned int)openfpm::math::pow(3,dim)/2+1> NNc_sym;
375
376private:
377
380
383
386 size_t n_dec;
387
390
391
392
394 void InitializeStructures(const size_t (& div)[dim], size_t tot_n_cell, size_t slot=STARTING_NSLOT)
395 {
396 Mem_type::init_to_zero(slot,tot_n_cell);
397
398 NNc_full.set_size(div);
400
401 NNc_sym.set_size(div);
403 }
404
405 void setCellDecomposer(CellDecomposer_sm<dim,T,transform> & cd, const CellDecomposer_sm<dim,T,transform> & cd_sm, const Box<dim,T> & dom_box, size_t pad) const
406 {
407 size_t bc[dim];
408
409 for (size_t i = 0 ; i < dim ; i++)
410 {bc[i] = NON_PERIODIC;}
411
412 Box<dim,long int> bx = cd_sm.convertDomainSpaceIntoCellUnits(dom_box,bc);
413
414 size_t div[dim];
415 size_t div_big[dim];
416
417 for (size_t i = 0 ; i < dim ; i++)
418 {
419 div[i] = bx.getHigh(i) - bx.getLow(i);
420 div_big[i] = cd_sm.getDiv()[i] - 2*cd_sm.getPadding(i);
421 }
422
423 cd.setDimensions(cd_sm.getDomain(),div_big,div, pad, bx.getP1());
424 }
425
426public:
427
429 typedef Mem_type Mem_type_type;
430
432
434 typedef typename Mem_type::local_index_type value_type;
435
437 typedef T stype;
438
440 typedef vector_pos_type internal_vector_pos_type;
441
448 {
449 return CellDecomposer_sm<dim,T,transform>::getGrid();
450 }
451
465 void Initialize(CellDecomposer_sm<dim,T,transform> & cd_sm, const Box<dim,T> & dom_box,const size_t pad = 1, size_t slot=STARTING_NSLOT)
466 {
467 size_t bc[dim];
468 for (size_t i = 0 ; i < dim ; i++) {bc[i] = NON_PERIODIC;}
469
470 Box<dim,long int> bx = cd_sm.convertDomainSpaceIntoCellUnits(dom_box,bc);
471
472 setCellDecomposer(*this,cd_sm,dom_box,pad);
473
474 size_t div_w_pad[dim];
475 size_t tot_cell = 1;
476
477 for (size_t i = 0 ; i < dim ; i++)
478 {
479 div_w_pad[i] = bx.getHigh(i) - bx.getLow(i) + 2*pad;
480 tot_cell *= div_w_pad[i];
481 }
482
483 // here we set the cell-shift for the CellDecomposer
484
485 InitializeStructures(div_w_pad,tot_cell);
486
487 // Initialized from CellDecomposer
488 from_cd = true;
489 }
490
499 void Initialize(const Box<dim,T> & box, const size_t (&div)[dim], const size_t pad = 1, size_t slot=STARTING_NSLOT)
500 {
501 SpaceBox<dim,T> sbox(box);
502
503 // Initialize point transformation
504
505 Initialize(sbox,div,pad,slot);
506 }
507
516 void Initialize(const SpaceBox<dim,T> & box, const size_t (&div)[dim], const size_t pad = 1, size_t slot=STARTING_NSLOT)
517 {
518 Matrix<dim,T> mat;
519
520 CellDecomposer_sm<dim,T,transform>::setDimensions(box,div, mat, pad);
521 Mem_type::set_slot(slot);
522
523 // create the array that store the number of particle on each cell and se it to 0
524 InitializeStructures(this->gr_cell.getSize(),this->gr_cell.size());
525
526 from_cd = false;
527 }
528
531
532 :Mem_type(STARTING_NSLOT)
533 {};
534
537 :Mem_type(STARTING_NSLOT)
538 {
539 this->operator=(cell);
540 }
541
544 :Mem_type(STARTING_NSLOT)
545 {
546 this->operator=(cell);
547 }
548
549
559 CellList(Box<dim,T> & box, const size_t (&div)[dim], Matrix<dim,T> mat, const size_t pad = 1, size_t slot=STARTING_NSLOT)
560 :Mem_type(slot),CellDecomposer_sm<dim,T,transform>(box,div,mat,box.getP1(),pad)
561 {
562 SpaceBox<dim,T> sbox(box);
563 Initialize(sbox,div,pad,slot);
564 }
565
574 CellList(Box<dim,T> & box, const size_t (&div)[dim], const size_t pad = 1, size_t slot=STARTING_NSLOT)
575 :Mem_type(slot),n_dec(0)
576 {
577 SpaceBox<dim,T> sbox(box);
578 Initialize(sbox,div,pad,slot);
579 }
580
589 CellList(SpaceBox<dim,T> & box, const size_t (&div)[dim], const size_t pad = 1, size_t slot=STARTING_NSLOT)
590 :Mem_type(slot)
591 {
592 Initialize(box,div,pad,slot);
593 }
594
605 CellList(CellDecomposer_sm<dim,T,transform> & cd_sm, const Box<dim,T> & box, const size_t pad = 1, size_t slot=STARTING_NSLOT)
606 :Mem_type(slot),n_dec(0)
607 {
608 Initialize(cd_sm,box,pad,slot);
609 }
610
616 {}
617
626 {
627 std::copy(&cell.NNc_full[0],&cell.NNc_full[openfpm::math::pow(3,dim)],&NNc_full[0]);
628 std::copy(&cell.NNc_sym[0],&cell.NNc_sym[openfpm::math::pow(3,dim)/2+1],&NNc_sym[0]);
629
630 Mem_type::swap(static_cast<Mem_type &&>(cell));
631
632 static_cast<CellDecomposer_sm<dim,T,transform> &>(*this).swap(cell);
633
634 n_dec = cell.n_dec;
635 from_cd = cell.from_cd;
636
637 return *this;
638 }
639
648 {
649 NNc_full = cell.NNc_full;
650 NNc_sym = cell.NNc_sym;
651
652 Mem_type::operator=(static_cast<const Mem_type &>(cell));
653
654 static_cast<CellDecomposer_sm<dim,T,transform> &>(*this) = static_cast<const CellDecomposer_sm<dim,T,transform> &>(cell);
655
656 n_dec = cell.n_dec;
657 from_cd = cell.from_cd;
658
659 return *this;
660 }
661
669 template<typename Mem_type2>
671 {
672 NNc_full = cell.private_get_NNc_full();
673 NNc_sym = cell.private_get_NNc_sym();
674
675 Mem_type::copy_general(static_cast<const Mem_type2 &>(cell));
676
677 static_cast<CellDecomposer_sm<dim,T,transform> &>(*this) = static_cast<const CellDecomposer_sm<dim,T,transform> &>(cell);
678
679 n_dec = cell.get_ndec();
680 from_cd = cell.private_get_from_cd();
681
682 return *this;
683 }
684
690 void setRadius(T radius)
691 {
692 NNcalc_rad(radius,nnc_rad,this->getCellBox(),this->getGrid());
693 }
694
703 {
704 ParticleIt_Cells<dim,CellList<dim,T,Mem_fast<>,transform>> it(*this,dom_cells);
705
706 return it;
707 }
708
715 inline void addCell(size_t cell_id, typename Mem_type::local_index_type ele)
716 {
717 Mem_type::addCell(cell_id,ele);
718 }
719
726 inline void add(const T (& pos)[dim], typename Mem_type::local_index_type ele)
727 {
728 // calculate the Cell id
729 size_t cell_id = this->getCell(pos);
730
731 Mem_type::add(cell_id,ele);
732 }
733
740 inline void add(const Point<dim,T> & pos, typename Mem_type::local_index_type ele)
741 {
742 // calculate the Cell id
743 size_t cell_id = this->getCell(pos);
744
745 Mem_type::add(cell_id,ele);
746 }
747
748
757 inline void addDom(const T (& pos)[dim], typename Mem_type::local_index_type ele)
758 {
759 // calculate the Cell id
760
761 size_t cell_id = this->getCellDom(pos);
762
763 // add the element to the cell
764
765 addCell(cell_id,ele);
766 }
767
776 inline void addDom(const Point<dim,T> & pos, typename Mem_type::local_index_type ele)
777 {
778 // calculate the Cell id
779
780 size_t cell_id = this->getCellDom(pos);
781
782 // add the element to the cell
783
784 addCell(cell_id,ele);
785 }
786
795 inline void addPad(const T (& pos)[dim], typename Mem_type::local_index_type ele)
796 {
797 // calculate the Cell id
798
799 size_t cell_id = this->getCellPad(pos);
800
801 // add the element to the cell
802
803 addCell(cell_id,ele);
804 }
805
814 inline void addPad(const Point<dim,T> & pos, typename Mem_type::local_index_type ele)
815 {
816 // calculate the Cell id
817
818 size_t cell_id = this->getCell(pos);
819
820 // add the element to the cell
821
822 addCell(cell_id,ele);
823 }
824
831 inline void remove(size_t cell, size_t ele)
832 {
833 Mem_type::remove(cell,ele);
834 }
835
840 inline size_t getNCells() const
841 {
842 return Mem_type::size();
843 }
844
852 inline size_t getNelements(const size_t cell_id) const
853 {
854 return Mem_type::getNelements(cell_id);
855 }
856
867 inline auto get(size_t cell, size_t ele) -> decltype(this->Mem_type::get(cell,ele))
868 {
869 return Mem_type::get(cell,ele);
870 }
871
882 inline auto get(size_t cell, size_t ele) const -> decltype(this->Mem_type::get(cell,ele))
883 {
884 return Mem_type::get(cell,ele);
885 }
886
893 {
895 NNc_sym.swap(cl.NNc_sym);
896
897 Mem_type::swap(static_cast<Mem_type &>(cl));
898
899 static_cast<CellDecomposer_sm<dim,T,transform> &>(*this).swap(static_cast<CellDecomposer_sm<dim,T,transform> &>(cl));
900
901 n_dec = cl.n_dec;
902 from_cd = cl.from_cd;
903 }
904
913 {
915 }
916
937 template<unsigned int impl=NO_CHECK> inline CellNNIteratorRadius<dim,CellList<dim,T,Mem_type,transform>,impl> getNNIteratorRadius(size_t cell)
938 {
940 return cln;
941 }
942
963 template<unsigned int impl=NO_CHECK>
964 __attribute__((always_inline)) inline CellNNIterator<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,(int)FULL,impl> getNNIterator(size_t cell)
965 {
967 return cln;
968
969 }
970
981 template<unsigned int impl=NO_CHECK>
983 {
984 openfpm::vector<long int> & NNc = rcache[r_cut];
985
986 if (NNc.size() == 0)
987 {NNcalc_rad(r_cut,NNc,this->getCellBox(),this->getGrid());}
988
990
991 return cln;
992 }
993
994
995
1016 template<unsigned int impl>
1017 __attribute__((always_inline)) inline CellNNIteratorSym<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,vector_pos_type,(unsigned int)SYM,impl>
1018 getNNIteratorSym(size_t cell, size_t p, const vector_pos_type & v)
1019 {
1020#ifdef SE_CLASS1
1021 if (from_cd == false)
1022 {std::cerr << __FILE__ << ":" << __LINE__ << " Warning when you try to get a symmetric neighborhood iterator, you must construct the Cell-list in a symmetric way" << std::endl;}
1023#endif
1024
1025 CellNNIteratorSym<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,vector_pos_type,SYM,impl> cln(cell,p,NNc_sym,*this,v);
1026 return cln;
1027 }
1028
1051 template<unsigned int impl, typename vector_pos_type2>
1052 __attribute__((always_inline)) inline CellNNIteratorSymMP<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,vector_pos_type2,(unsigned int)SYM,impl>
1053 getNNIteratorSymMP(size_t cell, size_t p, const vector_pos_type2 & v_p1, const vector_pos_type2 & v_p2)
1054 {
1055#ifdef SE_CLASS1
1056 if (from_cd == false)
1057 std::cerr << __FILE__ << ":" << __LINE__ << " Warning when you try to get a symmetric neighborhood iterator, you must construct the Cell-list in a symmetric way" << std::endl;
1058#endif
1059
1060 CellNNIteratorSymMP<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,vector_pos_type2,SYM,impl> cln(cell,p,NNc_sym,*this,v_p1,v_p2);
1061 return cln;
1062 }
1063
1069 const NNc_array<dim,(unsigned int)openfpm::math::pow(3,dim)/2+1> & getNNc_sym() const
1070 {
1071 return NNc_sym;
1072 }
1073
1081 size_t getPadding(size_t i) const
1082 {
1083 return CellDecomposer_sm<dim,T,transform>::getPadding(i);
1084 }
1085
1092 size_t (& getPadding())[dim]
1093 {
1094 return CellDecomposer_sm<dim,T,transform>::getPadding();
1095 }
1096
1100 void clear()
1101 {
1102 Mem_type::clear();
1103 }
1104
1108 void destroy()
1109 {
1110 Mem_type::destroy();
1111 }
1112
1120 __attribute__((always_inline)) inline const typename Mem_type::local_index_type & getStartId(typename Mem_type::local_index_type cell_id) const
1121 {
1122 return Mem_type::getStartId(cell_id);
1123 }
1124
1132 __attribute__((always_inline)) inline const typename Mem_type::local_index_type & getStopId(typename Mem_type::local_index_type cell_id) const
1133 {
1134 return Mem_type::getStopId(cell_id);
1135 }
1136
1144 __attribute__((always_inline)) inline const typename Mem_type::local_index_type & get_lin(const typename Mem_type::local_index_type * part_id) const
1145 {
1146 return Mem_type::get_lin(part_id);
1147 }
1148
1150
1152 size_t g_m = 0;
1153
1159 inline size_t get_gm()
1160 {
1161 return g_m;
1162 }
1163
1169 inline void set_gm(size_t g_m)
1170 {
1171 this->g_m = g_m;
1172 }
1173
1174#ifdef CUDA_GPU
1175
1177 {
1178 typedef typename Mem_type::local_index_type ids_type;
1179 typedef typename Mem_type::local_index_type cnt_type;
1180
1184
1185 for (size_t i = 0 ; i < dim ; i++)
1186 {
1187 spacing_c[i] = CellDecomposer_sm<dim,T,transform>::getCellBox().getHigh(i);
1188 div_c[i] = CellDecomposer_sm<dim,T,transform>::getDiv()[i];
1189 off[i] = CellDecomposer_sm<dim,T,transform>::getPadding(i);
1190 }
1191
1193 spacing_c,
1194 div_c,
1195 off,
1196 this->gr_cell,
1197 this->cell_shift,
1198 this->box_unit,
1199 CellDecomposer_sm<dim,T,transform>::getTransform());
1200
1201 return cl;
1202 }
1203
1204
1205 void hostToDevice()
1206 {
1207 Mem_type::hostToDevice();
1208 }
1209
1210#endif
1211
1212 const NNc_array<dim,(unsigned int)openfpm::math::pow(3,dim)> & private_get_NNc_full () const
1213 {
1214 return NNc_full;
1215 }
1216
1217 const NNc_array<dim,(unsigned int)openfpm::math::pow(3,dim)/2+1> & private_get_NNc_sym () const
1218 {
1219 return NNc_sym;
1220 }
1221
1222 bool private_get_from_cd() const
1223 {
1224 return from_cd;
1225 }
1226
1228
1229 void re_setBoxNN()
1230 {}
1231
1233
1239 void set_ndec(size_t n_dec)
1240 {
1241 this->n_dec = n_dec;
1242 }
1243
1249 size_t get_ndec() const
1250 {
1251 return n_dec;
1252 }
1253
1255};
1256
1265template<unsigned int dim, typename St> static inline void cl_param_calculate(Box<dim, St> & pbox, size_t (&div)[dim], St r_cut, const Ghost<dim, St> & enlarge)
1266{
1267 // calculate the parameters of the cell list
1268
1269 // extend by the ghost
1270 pbox.enlarge(enlarge);
1271
1272 // Calculate the division array and the cell box
1273 for (size_t i = 0; i < dim; i++)
1274 {
1275 div[i] = static_cast<size_t>((pbox.getP2().get(i) - pbox.getP1().get(i)) / r_cut);
1276 div[i]++;
1277 pbox.setHigh(i,pbox.getLow(i) + div[i]*r_cut);
1278 }
1279}
1280
1290template<unsigned int dim, typename St> static
1291inline void cl_param_calculateSym(const Box<dim,St> & dom,
1292 CellDecomposer_sm<dim,St,shift<dim,St>> & cd_sm,
1293 Ghost<dim,St> g,
1294 St r_cut,
1295 size_t & pad)
1296{
1297 size_t div[dim];
1298
1299 for (size_t i = 0 ; i < dim ; i++)
1300 div[i] = (dom.getHigh(i) - dom.getLow(i)) / r_cut;
1301
1302 g.magnify(1.013);
1303
1304 // Calculate the maximum padding
1305 for (size_t i = 0 ; i < dim ; i++)
1306 {
1307 size_t tmp = std::ceil(fabs(g.getLow(i)) / r_cut);
1308 pad = (pad > tmp)?pad:tmp;
1309
1310 tmp = std::ceil(fabs(g.getHigh(i)) / r_cut);
1311 pad = (pad > tmp)?pad:tmp;
1312 }
1313
1314 cd_sm.setDimensions(dom,div,pad);
1315}
1316
1317
1327template<unsigned int dim, typename St>
1328static inline void cl_param_calculateSym(const Box<dim,St> & dom,
1329 CellDecomposer_sm<dim,St,shift<dim,St>> & cd_sm,
1330 Ghost<dim,St> g,
1331 size_t & pad)
1332{
1333 size_t div[dim];
1334
1335 for (size_t i = 0 ; i < dim ; i++)
1336 div[i] = (dom.getHigh(i) - dom.getLow(i)) / g.getHigh(i);
1337
1338 g.magnify(1.013);
1339
1340 pad = 1;
1341
1342 cd_sm.setDimensions(dom,div,pad);
1343}
1344
1345
1346#endif /* CELLLIST_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
Point< dim, T > getP2() const
Get the point p2.
Definition Box.hpp:722
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition Box.hpp:556
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition Box.hpp:567
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
Definition Box.hpp:823
void magnify(T mg)
Magnify the box.
Definition Box.hpp:889
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition Box.hpp:544
Point< dim, T > getP1() const
Get the point p1.
Definition Box.hpp:708
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition Box.hpp:533
it iterate through the elements of a cell
Class for FAST cell list implementation.
Definition CellList.hpp:357
const NNc_array< dim,(unsigned int) openfpm::math::pow(3, dim)/2+1 > & getNNc_sym() const
Get the symmetric neighborhood.
size_t getNelements(const size_t cell_id) const
Return the number of elements in the cell.
Definition CellList.hpp:852
auto get(size_t cell, size_t ele) const -> decltype(this->Mem_type::get(cell, ele))
Get an element in the cell.
Definition CellList.hpp:882
wrap_unordered_map< T, openfpm::vector< long int > > rcache
Caching of r_cutoff radius.
Definition CellList.hpp:379
NNc_array< dim,(unsigned int) openfpm::math::pow(3, dim)/2+1 > NNc_sym
The array contain the neighborhood of the cell-id in case of symmetric interaction.
Definition CellList.hpp:374
const grid_sm< dim, void > & getGrid()
Return the underlying grid information of the cell list.
Definition CellList.hpp:447
auto get(size_t cell, size_t ele) -> decltype(this->Mem_type::get(cell, ele))
Get an element in the cell.
Definition CellList.hpp:867
void add(const T(&pos)[dim], typename Mem_type::local_index_type ele)
Add an element in the cell list.
Definition CellList.hpp:726
CellList< dim, T, Mem_type, transform > & operator=(CellList< dim, T, Mem_type, transform > &&cell)
Constructor from a temporal object.
Definition CellList.hpp:625
CellNNIteratorRadius< dim, CellList< dim, T, Mem_type, transform >, impl > getNNIteratorRadius(size_t cell)
Get the Neighborhood iterator.
Definition CellList.hpp:937
void addPad(const Point< dim, T > &pos, typename Mem_type::local_index_type ele)
Add an element in the cell list forcing to be in the padding cells.
Definition CellList.hpp:814
ParticleIt_Cells< dim, CellList< dim, T, Mem_fast<>, transform > > getDomainIterator(openfpm::vector< size_t > &dom_cells)
Get an iterator over particles following the cell structure.
Definition CellList.hpp:702
NNc_array< dim,(unsigned int) openfpm::math::pow(3, dim)> NNc_full
The array contain the neighborhood of the cell-id in case of asymmetric interaction.
Definition CellList.hpp:366
Mem_type Mem_type_type
Type of internal memory structure.
Definition CellList.hpp:429
void clear()
Clear the cell list.
bool from_cd
True if has been initialized from CellDecomposer.
Definition CellList.hpp:382
void InitializeStructures(const size_t(&div)[dim], size_t tot_n_cell, size_t slot=STARTING_NSLOT)
Initialize the structures of the data structure.
Definition CellList.hpp:394
void addDom(const Point< dim, T > &pos, typename Mem_type::local_index_type ele)
Add an element in the cell list forcing to be in the domain cells.
Definition CellList.hpp:776
__attribute__((always_inline)) inline const typename Mem_type size_t get_gm()
Return the starting point of the cell p.
void set_ndec(size_t n_dec)
Set the n_dec number.
void set_gm(size_t g_m)
Set the ghost marker.
CellList< dim, T, Mem_type, transform, vector_pos_type > & operator=(const CellList< dim, T, Mem_type, transform, vector_pos_type > &cell)
Constructor from a temporal object.
Definition CellList.hpp:647
size_t getNCells() const
Get the number of cells this cell-list contain.
Definition CellList.hpp:840
CellList(Box< dim, T > &box, const size_t(&div)[dim], Matrix< dim, T > mat, const size_t pad=1, size_t slot=STARTING_NSLOT)
Cell list constructor.
Definition CellList.hpp:559
void destroy()
Litterary destroy the memory of the cell list, including the retained one.
__attribute__((always_inline)) inline CellNNIterator< dim
Get the Neighborhood iterator.
size_t(& getPadding())[dim]
Return the number of padding cells of the Cell decomposer as an array.
CellIterator< CellList< dim, T, Mem_type, transform > > getCellIterator(size_t cell)
Get the Cell iterator.
Definition CellList.hpp:912
void Initialize(const SpaceBox< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
Definition CellList.hpp:516
size_t n_dec
Definition CellList.hpp:386
__attribute__((always_inline)) inline CellNNIteratorSymMP< dim
Get the symmetric Neighborhood iterator.
void swap(CellList< dim, T, Mem_type, transform, vector_pos_type > &cl)
Swap the memory.
Definition CellList.hpp:892
~CellList()
Destructor.
Definition CellList.hpp:615
void Initialize(const Box< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
Definition CellList.hpp:499
__attribute__((always_inline)) inline CellNNIteratorSym< dim
Get the symmetric Neighborhood iterator.
CellList< dim, T, Mem_type, transform, vector_pos_type > & operator=(const CellList< dim, T, Mem_type2, transform, vector_pos_type > &cell)
Constructor from a temporal object.
Definition CellList.hpp:670
void remove(size_t cell, size_t ele)
remove an element from the cell
Definition CellList.hpp:831
CellList(CellDecomposer_sm< dim, T, transform > &cd_sm, const Box< dim, T > &box, const size_t pad=1, size_t slot=STARTING_NSLOT)
Cell list constructor from a cell decomposer.
Definition CellList.hpp:605
CellList(CellList< dim, T, Mem_type, transform, vector_pos_type > &&cell)
Copy constructor.
Definition CellList.hpp:543
void addDom(const T(&pos)[dim], typename Mem_type::local_index_type ele)
Add an element in the cell list forcing to be in the domain cells.
Definition CellList.hpp:757
void setRadius(T radius)
Set the radius for the getNNIteratorRadius.
Definition CellList.hpp:690
size_t getPadding(size_t i) const
Return the number of padding cells of the Cell decomposer.
T stype
Type of the coordinate space (double float)
Definition CellList.hpp:437
CellList(const CellList< dim, T, Mem_type, transform, vector_pos_type > &cell)
Copy constructor.
Definition CellList.hpp:536
size_t get_ndec() const
Set the n_dec number.
void addPad(const T(&pos)[dim], typename Mem_type::local_index_type ele)
Add an element in the cell list forcing to be in the padding cells.
Definition CellList.hpp:795
CellList(Box< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
Cell list constructor.
Definition CellList.hpp:574
void add(const Point< dim, T > &pos, typename Mem_type::local_index_type ele)
Add an element in the cell list.
Definition CellList.hpp:740
__attribute__((always_inline)) inline CellNNIteratorRadius< dim
Get the symmetric Neighborhood iterator.
void Initialize(CellDecomposer_sm< dim, T, transform > &cd_sm, const Box< dim, T > &dom_box, const size_t pad=1, size_t slot=STARTING_NSLOT)
Definition CellList.hpp:465
CellList()
Default Constructor.
Definition CellList.hpp:530
openfpm::vector< long int > nnc_rad
Cells for the neighborhood radius.
Definition CellList.hpp:389
Mem_type::local_index_type value_type
Object type that the structure store.
Definition CellList.hpp:434
void addCell(size_t cell_id, typename Mem_type::local_index_type ele)
Add to the cell.
Definition CellList.hpp:715
CellList(SpaceBox< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
Cell list constructor.
Definition CellList.hpp:589
Iterator for the neighborhood of the cell structures with free radius.
Symmetric iterator for the neighborhood of the cell structures.
Symmetric iterator for the neighborhood of the cell structures.
Iterator for the neighborhood of the cell structures.
This class implement an NxN (dense) matrix.
Definition Matrix.hpp:33
void swap(NNc_array< dim, size, thr > &nnc)
swap NNc_array
void init_sym()
Initialize the NNc array with symmetric neighborhood cells indexes.
void init_full()
Initialize the NNc array with full neighborhood cells indexes.
Definition NNc_array.hpp:76
void set_size(const size_t(&sz)[dim])
Set the size in each.
Definition NNc_array.hpp:47
This iterator iterate across the particles of a Cell-list following the Cell structure.
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition Point.hpp:172
This class represent an N-dimensional box.
Definition SpaceBox.hpp:27
Declaration grid_key_dx_iterator_sub.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition grid_key.hpp:516
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition grid_key.hpp:503
Declaration grid_sm.
Definition grid_sm.hpp:167
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition grid_sm.hpp:454
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
Wrapper of the unordered map.
Definition CellList.hpp:35
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data