OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
grid_dist_key.hpp
1 #ifndef GRID_DIST_KEY_DX_HPP
2 #define GRID_DIST_KEY_DX_HPP
3 
4 #include "Grid/map_grid.hpp"
5 template<unsigned int dim, typename base_key = grid_key_dx<dim>>
7 
8 template<bool impl, typename grid_key_base, unsigned int dim>
9 class move_impl
10 {
11 public:
12  static grid_dist_key_dx<dim,grid_key_base> move(grid_key_base & key, size_t sub, size_t i, int s)
13  {
14  key.set_d(i,key.get(i) + s);
16  }
17 };
18 
19 template<typename grid_key_base, unsigned int dim>
20 class move_impl<false,grid_key_base,dim>
21 {
22 public:
23  static grid_dist_key_dx<dim> move(grid_key_base & key, size_t sub, size_t i, int s)
24  {
25  std::cout << __FILE__ << ":" << __LINE__ << " Error move a key is not supported"
26  " directly acting on the grid key, please use the move function from the grid method" << std::endl;
27 
28  grid_key_dx<dim> zero;
29  zero.zero();
30 
31  return grid_dist_key_dx<dim>(0,zero);
32  }
33 };
34 
35 
42 template<unsigned int dim, typename base_key>
43 class grid_dist_key_dx
44 {
46 
47  size_t g_c;
48 
50 
51  base_key key;
52 
53 public:
54 
60  inline void setSub(size_t sub)
61  {
62  g_c = sub;
63  }
64 
70  inline size_t getSub() const
71  {
72  return g_c;
73  }
74 
80  inline base_key getKey() const
81  {
82  return key;
83  }
84 
85 
91  inline base_key & getKeyRef()
92  {
93  return key;
94  }
95 
101  inline const base_key & getKeyRef() const
102  {
103  return key;
104  }
105 
106  /* \brief Check if two key are the same
107  *
108  * \param key_t key to check
109  *
110  * \return true if the two key are equal
111  *
112  */
113 
114  inline bool operator==(const grid_dist_key_dx<dim> & key_t)
115  {
116  if (g_c != key_t.g_c)
117  return false;
118 
119  // Check the two key index by index
120 
121  return getKey() == key_t.getKey();
122  }
123 
132  inline grid_dist_key_dx<dim,base_key> move(size_t i,int s) const
133  {
134  auto key = getKey();
135 
137  decltype(this->getKey()),
138  dim>::move(key,getSub(),i,s);
139  }
140 
148  inline grid_dist_key_dx<dim> move(const comb<dim> & c) const
149  {
151  for (size_t i = 0 ; i < dim ; i++)
152  key.set_d(i,key.get(i) + c[i]);
153  return grid_dist_key_dx<dim>(getSub(),key);
154  }
155 
162  inline grid_dist_key_dx(int g_c, const base_key & key)
163  :g_c(g_c),key(key)
164  {
165  }
166 
168  inline grid_dist_key_dx(){}
169 
174  std::string to_string()
175  {
176  std::stringstream str;
177 
178  str << "sub_domain=" << g_c << " ";
179 
180  for (size_t i = 0 ; i < dim ; i++)
181  str << "x[" << i << "]=" << key.get(i) << " ";
182 
183  str << "\n";
184 
185  return str.str();
186  }
187 };
188 
195 {
197  size_t g_c;
198 
200  size_t key;
201 
202 public:
203 
209  inline void setSub(size_t sub)
210  {
211  g_c = sub;
212  }
213 
219  inline size_t getSub() const
220  {
221  return g_c;
222  }
223 
229  inline size_t getKey() const
230  {
231  return key;
232  }
233 
234 
240  inline size_t & getKeyRef()
241  {
242  return key;
243  }
244 
245  /* \brief Check if two key are the same
246  *
247  * \param key_t key to check
248  *
249  * \return true if the two key are equal
250  *
251  */
252 
253  inline bool operator==(const grid_dist_lin_dx & key_t)
254  {
255  if (g_c != key_t.g_c)
256  return false;
257 
258  // Check the two key index by index
259 
260  return getKey() == key_t.getKey();
261  }
262 
263 
270  inline grid_dist_lin_dx(int g_c, size_t key)
271  :g_c(g_c),key(key)
272  {
273  }
274 
276  inline grid_dist_lin_dx(){}
277 
282  std::string to_string()
283  {
284  std::stringstream str;
285 
286  str << "sub_domain=" << g_c << " ";
287  str << "lin_id=" << key << " ";
288 
289  str << "\n";
290 
291  return str.str();
292  }
293 };
294 
300 template<typename device_grid>
302 {
305 
307  size_t key;
308 
309 public:
310 
315  inline device_grid * getSub() const
316  {
317  return dg;
318  }
319 
320 
326  inline size_t getKey() const
327  {
328  return key;
329  }
330 
331 
337  inline size_t & getKeyRef()
338  {
339  return key;
340  }
341 
342  /* \brief Check if two key are the same
343  *
344  * \param key_t key to check
345  *
346  * \return true if the two key are equal
347  *
348  */
349 
350  inline bool operator==(const grid_dist_g_dx & key_t)
351  {
352  if (dg != key_t.dg)
353  return false;
354 
355  // Check the two key index by index
356 
357  return getKey() == key_t.getKey();
358  }
359 
360 
367  inline grid_dist_g_dx(device_grid * dg, size_t key)
368  :dg(dg),key(key)
369  {
370  }
371 
373  inline grid_dist_g_dx(){}
374 
380  std::string to_string()
381  {
382  std::stringstream str;
383 
384  str << "sub_domain=" << dg << " ";
385  str << "lin_id=" << key << " ";
386 
387  str << "\n";
388 
389  return str.str();
390  }
391 };
392 
393 #endif
std::string to_string()
convert the key to string
grid_dist_lin_dx(int g_c, size_t key)
Constructor set the sub-domain grid and the position in local coordinates.
size_t & getKeyRef()
Get the reference key.
size_t & getKeyRef()
Get the reference key.
base_key & getKeyRef()
Get the reference key.
Position of the element of dimension d in the hyper-cube of dimension dim.
Definition: comb.hpp:34
Distributed linearized key.
base_key getKey() const
Get the key.
grid_dist_key_dx()
Constructor.
grid_dist_g_dx()
Constructor.
device_grid * dg
grid list counter
Grid key for a distributed grid.
device_grid * getSub() const
return the sub-domain grid
size_t g_c
grid list counter
grid_dist_key_dx< dim, base_key > move(size_t i, int s) const
Create a new key moving the old one.
grid_dist_key_dx< dim > move(const comb< dim > &c) const
Create a new key moving the old one.
const base_key & getKeyRef() const
Get the reference key.
void setSub(size_t sub)
Set the local grid.
grid_dist_key_dx(int g_c, const base_key &key)
Constructor set the sub-domain grid and the position in local coordinates.
std::string to_string()
convert the key to string
void setSub(size_t sub)
Set the local grid.
std::string to_string()
convert the key to string
grid_dist_lin_dx()
Constructor.
size_t key
Local grid iterator.
base_key key
Local grid iterator.
size_t getKey() const
Get the key.
grid_dist_g_dx(device_grid *dg, size_t key)
Constructor.
size_t getSub() const
Get the local grid.
size_t key
Local grid iterator.
void zero()
Set to zero the key.
Definition: grid_key.hpp:170
size_t getKey() const
Get the key.
size_t getSub() const
Get the local grid.
size_t g_c
grid list counter
Distributed linearized key.