OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
grid_dist_key.hpp
1 #ifndef GRID_DIST_KEY_DX_HPP
2 #define GRID_DIST_KEY_DX_HPP
3 
10 template<unsigned int dim>
12 {
14 
15  size_t g_c;
16 
18 
20 
21 public:
22 
28  inline void setSub(size_t sub)
29  {
30  g_c = sub;
31  }
32 
38  inline size_t getSub() const
39  {
40  return g_c;
41  }
42 
48  inline grid_key_dx<dim> getKey() const
49  {
50  return key;
51  }
52 
53 
60  {
61  return key;
62  }
63 
64  /* \brief Check if two key are the same
65  *
66  * \param key_t key to check
67  *
68  * \return true if the two key are equal
69  *
70  */
71 
72  inline bool operator==(const grid_dist_key_dx<dim> & key_t)
73  {
74  if (g_c != key_t.g_c)
75  return false;
76 
77  // Check the two key index by index
78 
79  return getKey() == key_t.getKey();
80  }
81 
90  inline grid_dist_key_dx<dim> move(size_t i,size_t s) const
91  {
93  key.set_d(i,key.get(i) + s);
95  }
96 
104  inline grid_dist_key_dx<dim> move(const comb<dim> & c) const
105  {
107  for (size_t i = 0 ; i < dim ; i++)
108  key.set_d(i,key.get(i) + c[i]);
109  return grid_dist_key_dx<dim>(getSub(),key);
110  }
111 
119  :g_c(g_c),key(key)
120  {
121  }
122 
124  inline grid_dist_key_dx(){}
125 
130  std::string to_string()
131  {
132  std::stringstream str;
133 
134  str << "sub_domain=" << g_c << " ";
135 
136  for (size_t i = 0 ; i < dim ; i++)
137  str << "x[" << i << "]=" << key.get(i) << " ";
138 
139  str << "\n";
140 
141  return str.str();
142  }
143 };
144 
151 {
153  size_t g_c;
154 
156  size_t key;
157 
158 public:
159 
165  inline void setSub(size_t sub)
166  {
167  g_c = sub;
168  }
169 
175  inline size_t getSub() const
176  {
177  return g_c;
178  }
179 
185  inline size_t getKey() const
186  {
187  return key;
188  }
189 
190 
196  inline size_t & getKeyRef()
197  {
198  return key;
199  }
200 
201  /* \brief Check if two key are the same
202  *
203  * \param key_t key to check
204  *
205  * \return true if the two key are equal
206  *
207  */
208 
209  inline bool operator==(const grid_dist_lin_dx & key_t)
210  {
211  if (g_c != key_t.g_c)
212  return false;
213 
214  // Check the two key index by index
215 
216  return getKey() == key_t.getKey();
217  }
218 
219 
226  inline grid_dist_lin_dx(int g_c, size_t key)
227  :g_c(g_c),key(key)
228  {
229  }
230 
232  inline grid_dist_lin_dx(){}
233 
238  std::string to_string()
239  {
240  std::stringstream str;
241 
242  str << "sub_domain=" << g_c << " ";
243  str << "lin_id=" << key << " ";
244 
245  str << "\n";
246 
247  return str.str();
248  }
249 };
250 
256 template<typename device_grid>
258 {
260  device_grid * dg;
261 
263  size_t key;
264 
265 public:
266 
271  inline device_grid * getSub()
272  {
273  return dg;
274  }
275 
276 
282  inline size_t getKey() const
283  {
284  return key;
285  }
286 
287 
293  inline size_t & getKeyRef()
294  {
295  return key;
296  }
297 
298  /* \brief Check if two key are the same
299  *
300  * \param key_t key to check
301  *
302  * \return true if the two key are equal
303  *
304  */
305 
306  inline bool operator==(const grid_dist_g_dx & key_t)
307  {
308  if (dg != key_t.dg)
309  return false;
310 
311  // Check the two key index by index
312 
313  return getKey() == key_t.getKey();
314  }
315 
316 
323  inline grid_dist_g_dx(device_grid * dg, size_t key)
324  :dg(dg),key(key)
325  {
326  }
327 
329  inline grid_dist_g_dx(){}
330 
336  std::string to_string()
337  {
338  std::stringstream str;
339 
340  str << "sub_domain=" << dg << " ";
341  str << "lin_id=" << key << " ";
342 
343  str << "\n";
344 
345  return str.str();
346  }
347 };
348 
349 #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.
grid_key_dx< dim > & getKeyRef()
Get the reference key.
size_t & getKeyRef()
Get the reference key.
size_t & getKeyRef()
Get the reference key.
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
Position of the element of dimension d in the hyper-cube of dimension dim.
Definition: comb.hpp:34
Distributed linearized key.
grid_dist_key_dx(int g_c, const grid_key_dx< dim > &key)
Constructor set the sub-domain grid and the position in local coordinates.
grid_dist_key_dx< dim > move(size_t i, size_t s) const
Create a new key moving the old one.
size_t getKey() const
Get the key.
grid_key_dx< dim > key
Local grid iterator.
grid_dist_key_dx()
Constructor.
grid_dist_g_dx()
Constructor.
device_grid * dg
grid list counter
Grid key for a distributed grid.
size_t g_c
grid list counter
size_t g_c
grid list counter
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:394
size_t getSub() const
Get the local grid.
device_grid * getSub()
return the sub-domain grid
std::string to_string()
convert the key to string
std::string to_string()
convert the key to string
void setSub(size_t sub)
Set the local grid.
grid_dist_lin_dx()
Constructor.
size_t key
Local grid iterator.
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
size_t getKey() const
Get the key.
void setSub(size_t sub)
Set the local grid.
grid_dist_g_dx(device_grid *dg, size_t key)
Constructor.
size_t key
Local grid iterator.
grid_dist_key_dx< dim > move(const comb< dim > &c) const
Create a new key moving the old one.
void set_d(size_t i, mem_id id)
Set the i index.
Definition: grid_key.hpp:407
size_t getSub() const
Get the local grid.
grid_key_dx< dim > getKey() const
Get the key.
Distributed linearized key.