OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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 base=openfpm::vector<size_t>>
33 class CellList_gen : public CellList<dim,T,Mem_type,transform,base>
34 {
35 private:
36 
38  size_t g_m = 0;
39 
42  Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,base>> 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 
98  CellList_gen()
99  :CellList<dim,T,Mem_type,transform,base>(),init_sfc(false)
100  {};
101 
102 
108  const Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,base>> & getCellSFC() const
109  {
110  return SFC;
111  }
112 
116  inline void init_SFC()
117  {
118  // Initialize SFC
119  if (init_sfc == false)
120  {
121  initialize_sfc(this->getPadding(0));
122  init_sfc = true;
123  }
124  }
125 
131  inline typename Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,base>>::Pit getIterator()
132  {
133  init_SFC();
134 
135  return typename Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,base>>::Pit(*this);
136  }
137 
147  void Initialize(const Box<dim,T> & box, const size_t (&div)[dim], const size_t pad = 1, size_t slot=STARTING_NSLOT)
148  {
150  }
151 
152 
159  {
160  return SFC.getKeys();
161  }
162 
168  inline size_t get_gm()
169  {
170  return g_m;
171  }
172 
177  inline void set_gm(size_t g_m)
178  {
179  this->g_m = g_m;
180  }
181 };
182 
183 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTFAST_GEN_HPP_ */
size_t g_m
Ghost marker.
size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:572
No transformation.
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:434
void init_SFC()
Initialize Space-filling-curve (SFC)
void Initialize(const Box< dim, T > &box, const size_t(&div)[dim], const size_t pad=1, size_t slot=STARTING_NSLOT)
size_t(& getPadding())[dim]
Return the number of padding cells of the Cell decomposer as an array.
Definition: CellList.hpp:988
void initialize_sfc(size_t pad)
Initialize the space-filling-curve.
Prock< dim, CellList_gen< dim, T, Prock, Mem_type, transform, base > > SFC
const grid_key_dx< dim > & get() const
Get the actual key.
const Prock< dim, CellList_gen< dim, T, Prock, Mem_type, transform, base > > & getCellSFC() const
Get the space filling curve object.
bool isNext()
Check if there is the next element.
This class represent an N-dimensional box.
Definition: Box.hpp:56
const openfpm::vector< size_t > & getKeys()
Return cellkeys vector.
Prock< dim, CellList_gen< dim, T, Prock, Mem_type, transform, base > >::Pit getIterator()
return the celllist iterator (across cells)
const grid_sm< dim, void > & getGrid()
Return the underlying grid information of the cell list.
Definition: CellList.hpp:416
void set_gm(size_t g_m)
Set the ghost marker.
size_t get_gm()
return the ghost marker
bool init_sfc
Init SFC.
Class for FAST cell list implementation.
Definition: CellList.hpp:269