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 | |
37 | //! Ghost marker |
38 | size_t g_m = 0; |
39 | |
40 | //! It is an object that indicate which space filling curve to use for the |
41 | //! iteration across cells |
42 | Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,vector_pos_type>> SFC; |
43 | |
44 | //! Init SFC |
45 | bool init_sfc; |
46 | |
47 | /*! \brief Initialize the space-filling-curve |
48 | * |
49 | * \param pad padding of the cell-list |
50 | * |
51 | */ |
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 | |
102 | /*! \brief Get the space filling curve object |
103 | * |
104 | * \return the SFC object |
105 | * |
106 | */ |
107 | const Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,vector_pos_type>> & getCellSFC() const |
108 | { |
109 | return SFC; |
110 | } |
111 | |
112 | /*! \brief Initialize Space-filling-curve (SFC) |
113 | * |
114 | */ |
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 | |
125 | /*! \brief return the celllist iterator (across cells) |
126 | * |
127 | * \return an iterator |
128 | * |
129 | */ |
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 | |
137 | /*! Initialize the cell list |
138 | * |
139 | * \param box Domain where this cell list is living |
140 | * \param div grid size on each dimension |
141 | * \param g_m_new A ghost marker |
142 | * \param pad padding cell |
143 | * \param slot maximum number of slot |
144 | * |
145 | */ |
146 | void Initialize(const Box<dim,T> & box, const size_t (&div)[dim], const size_t pad = 1, size_t slot=STARTING_NSLOT) |
147 | { |
148 | CellList<dim,T,Mem_type,transform,vector_pos_type>::Initialize(box,div,pad,slot); |
149 | } |
150 | |
151 | |
152 | /*! \brief Return cellkeys vector |
153 | * |
154 | * \return vector of cell keys |
155 | * |
156 | */ |
157 | inline const openfpm::vector<size_t> & getKeys() |
158 | { |
159 | return SFC.getKeys(); |
160 | } |
161 | |
162 | /*! \brief return the ghost marker |
163 | * |
164 | * \return ghost marker |
165 | * |
166 | */ |
167 | inline size_t get_gm() |
168 | { |
169 | return g_m; |
170 | } |
171 | |
172 | /*! \brief Set the ghost marker |
173 | * |
174 | * |
175 | */ |
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_ */ |
183 | |