OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
CellListFast_gen.hpp
1 /*
2  * CellListFast_hilb.hpp
3  *
4  * Created on: May 17, 2016
5  * Author: Yaroslav Zaluzhnyi
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTFAST_GEN_HPP_
9 #define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTFAST_GEN_HPP_
10 
11 //#define HILBERT 1
12 
13 #include "CellList.hpp"
14 #include "ProcKeys.hpp"
15 
16 /* \brief Cell list implementation with particle iterator over cells
17  *
18  * \see CellList<dim,T,FAST,transform,base>
19  *
20  * \tparam dim Dimensionality of the space
21  * \tparam T type of the space float, double, complex
22  * \tparam Prock indicate the cell iterator over the Cell
23  * \tparam Mem_type indicate how the Cell-list are implemented in memory
24  * \tparam base Base structure that store the information
25  *
26  */
27 template<unsigned int dim,
28  typename T,
29  template <unsigned int, typename> class Prock,
30  typename Mem_type = Mem_fast<>,
31  typename transform = no_transform<dim,T>,
32  typename vector_pos_type = openfpm::vector<Point<dim,T>>>
33 class CellList_gen : public CellList<dim,T,Mem_type,transform,vector_pos_type>
34 {
35 private:
36 
38  size_t g_m = 0;
39 
42  Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,vector_pos_type>> SFC;
43 
45  bool init_sfc;
46 
52  void initialize_sfc(size_t pad)
53  {
54  size_t sz[dim];
55 
56  //Get grid_sm without padding (gs_small)
57  for (size_t i = 0; i < dim ; i++)
58  sz[i] = this->getGrid().size(i) - 2*pad;
59 
60  grid_sm<dim,void> gs_small(sz);
61 
62  size_t a = gs_small.size(0);
63 
64  for (size_t i = 1 ; i < dim ; i++)
65  {
66  if (a < gs_small.size(i))
67  a = gs_small.size(i);
68  }
69 
70  size_t m;
71 
72  //Calculate an hilberts curve order
73  for (m = 0; ; m++)
74  {
75  if ((1ul << m) >= a)
76  break;
77  }
78 
79  grid_key_dx_iterator<dim> it(gs_small);
80 
81  while (it.isNext())
82  {
83  auto gk = it.get();
84 
85  // Get a key of each cell and add to 'keys' vector
86  SFC.get_hkey(*this,gk,m);
87 
88  ++it;
89  }
90 
91  // Sort and linearize keys
92  SFC.linearize_hkeys(*this,m);
93  }
94 
95 public:
96 
97  CellList_gen()
98  :CellList<dim,T,Mem_type,transform,vector_pos_type>(),init_sfc(false)
99  {};
100 
101 
107  const Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,vector_pos_type>> & getCellSFC() const
108  {
109  return SFC;
110  }
111 
115  inline void init_SFC()
116  {
117  // Initialize SFC
118  if (init_sfc == false)
119  {
120  initialize_sfc(this->getPadding(0));
121  init_sfc = true;
122  }
123  }
124 
130  inline typename Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,vector_pos_type>>::Pit getIterator()
131  {
132  init_SFC();
133 
134  return typename Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,vector_pos_type>>::Pit(*this);
135  }
136 
146  void Initialize(const Box<dim,T> & box, const size_t (&div)[dim], const size_t pad = 1, size_t slot=STARTING_NSLOT)
147  {
149  }
150 
151 
158  {
159  return SFC.getKeys();
160  }
161 
167  inline size_t get_gm()
168  {
169  return g_m;
170  }
171 
176  inline void set_gm(size_t g_m)
177  {
178  this->g_m = g_m;
179  }
180 };
181 
182 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTFAST_GEN_HPP_ */
size_t g_m
Ghost marker.
void set_gm(size_t g_m)
Set the ghost marker.
__device__ __host__ size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:637
No transformation.
Prock< dim, CellList_gen< dim, T, Prock, Mem_type, transform, vector_pos_type > >::Pit getIterator()
return the celllist iterator (across cells)
void Initialize(const Box< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
size_t get_gm()
return the ghost marker
const grid_sm< dim, void > & getGrid()
Return the underlying grid information of the cell list.
Definition: CellList.hpp:447
void init_SFC()
Initialize Space-filling-curve (SFC)
size_t(& getPadding())[dim]
Return the number of padding cells of the Cell decomposer as an array.
Definition: CellList.hpp:1092
const openfpm::vector< size_t > & getKeys()
Return cellkeys vector.
const grid_key_dx< dim > & get() const
Get the actual key.
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
This class represent an N-dimensional box.
Definition: Box.hpp:60
Prock< dim, CellList_gen< dim, T, Prock, Mem_type, transform, vector_pos_type > > SFC
bool init_sfc
Init SFC.
const Prock< dim, CellList_gen< dim, T, Prock, Mem_type, transform, vector_pos_type > > & getCellSFC() const
Get the space filling curve object.
void initialize_sfc(size_t pad)
Initialize the space-filling-curve.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:202
Class for FAST cell list implementation.
Definition: CellList.hpp:356
bool isNext()
Check if there is the next element.