OpenFPM  5.2.0
Project that contain the implementation of distributed structures
MemBalanced.hpp
1 
2 /*
3  * MemBalanced.hpp
4  *
5  * Created on: Mar 22, 2015
6  * Last modified: June 25, 2015
7  * Authors: Pietro Incardona, Yaroslav Zaluzhnyi
8  */
9 
10 #ifndef CELLLISTBAL_HPP_
11 #define CELLLISTBAL_HPP_
12 
13 #include "Space/Shape/Box.hpp"
14 #include "util/mathutil.hpp"
15 #include "Space/Shape/HyperCube.hpp"
16 
38 template<typename local_index = size_t>
39 class Mem_bal
40 {
43 
45  // that store the elements in the cell
47 
50 
52  local_index invalid;
53 
54 public:
55 
56  typedef void toKernel_type;
57 
59  typedef local_index local_index_type;
60 
67  inline void init_to_zero(size_t slot, size_t tot_n_cell)
68  {
69  //resize the vector to needed number of cells
70 
71  cl_base.resize(tot_n_cell);
72  ghostMarkers.resize(tot_n_cell);
73  clear();
74  }
75 
83  inline Mem_bal & operator=(const Mem_bal & cell)
84  {
85  cl_base = cell.cl_base;
87 
88  return *this;
89  }
90 
97  inline void addCell(size_t cell_id, typename base::value_type ele)
98  {
99  //add another neighbor element
100 
101  cl_base.get(cell_id).add(ele);
102  }
103 
110  inline void remove(local_index cell, local_index ele)
111  {
112  cl_base.get(cell).remove(ele);
113  }
114 
122  inline local_index getNelements(const local_index cell_id) const
123  {
124  return cl_base.get(cell_id).size();
125  }
126 
135  inline auto get(local_index cell, local_index ele) -> decltype(cl_base.get(0).get(0)) &
136  {
137  return cl_base.get(cell).get(ele);
138  }
139 
148  inline auto get(local_index cell, local_index ele) const -> decltype(cl_base.get(0).get(0)) &
149  {
150  return cl_base.get(cell).get(ele);
151  }
152 
159  inline void addCellGhostMarkers()
160  {
161  ghostMarkers.resize(cl_base.size());
162 
163  for (int i = 0; i < cl_base.size(); ++i)
164  {
165  ghostMarkers.get(i) = cl_base.get(i).size();
166  }
167  }
168 
172  inline size_t getGhostMarker(local_index cell_id) const
173  {
174  return ghostMarkers.get(cell_id);
175  }
176 
182  inline void swap(Mem_bal & cl)
183  {
184  cl_base.swap(cl.cl_base);
185  ghostMarkers.swap(cl.ghostMarkers);
186  }
187 
193  inline void swap(Mem_bal && cell)
194  {
195  cl_base.swap(cell.cl_base);
196  ghostMarkers.swap(cell.ghostMarkers);
197  }
198 
203  inline void clear()
204  {
205  for (size_t i = 0 ; i < cl_base.size() ; i++) {
206  cl_base.get(i).clear();
207  ghostMarkers.get(i) = 0;
208  }
209  }
210 
216  inline const local_index & getStartId(local_index cell_id) const
217  {
218  if (cl_base.get(cell_id).size() == 0)
219  return invalid;
220 
221  return cl_base.get(cell_id).get(0);
222  }
223 
229  inline const local_index & getGhostId(local_index cell_id) const
230  {
231  if (cl_base.get(cell_id).size() == 0)
232  return invalid;
233 
234  return cl_base.get(cell_id).get(this->getGhostMarker(cell_id));
235  }
236 
242  inline const local_index & getStopId(local_index cell_id) const
243  {
244  if (cl_base.get(cell_id).size() == 0)
245  return invalid;
246 
247  return *(&cl_base.get(cell_id).last() + 1);
248  }
249 
259  inline const local_index & get_lin(const local_index * cell_id) const
260  {
261  return *cell_id;
262  }
263 
264 public:
265 
266  inline Mem_bal(size_t slot)
267  :invalid(0)
268  {}
269 
270  inline void set_slot(size_t slot)
271  {}
272 
273 };
274 
275 
276 #endif /* CELLLISTBAL_HPP_ */
Class for BALANCED cell list implementation.
Definition: MemBalanced.hpp:40
local_index local_index_type
expose the type of the local index
Definition: MemBalanced.hpp:59
openfpm::vector< base > cl_base
each cell has a pointer to a dynamic structure
Definition: MemBalanced.hpp:46
const local_index & getStartId(local_index cell_id) const
Get the start index of the selected element.
void addCell(size_t cell_id, typename base::value_type ele)
Add an element to the cell.
Definition: MemBalanced.hpp:97
local_index getNelements(const local_index cell_id) const
Get the number of elements in the cell.
const local_index & getGhostId(local_index cell_id) const
Get the index of the first ghost element.
void swap(Mem_bal &&cell)
Swap two Mem_bal.
auto get(local_index cell, local_index ele) -> decltype(cl_base.get(0).get(0)) &
Return an element from the cell.
auto get(local_index cell, local_index ele) const -> decltype(cl_base.get(0).get(0)) &
Return an element from the cell.
void addCellGhostMarkers()
Add ghost marker to the cell.
local_index invalid
Invalid element.
Definition: MemBalanced.hpp:52
const local_index & getStopId(local_index cell_id) const
Get the stop index of the selected element.
void remove(local_index cell, local_index ele)
Remove an element from the cell.
size_t getGhostMarker(local_index cell_id) const
Get ghost marker of the cell.
openfpm::vector< local_index > base
vector that store the information
Definition: MemBalanced.hpp:42
const local_index & get_lin(const local_index *cell_id) const
get_lin
void init_to_zero(size_t slot, size_t tot_n_cell)
Initialize all to zero.
Definition: MemBalanced.hpp:67
Mem_bal & operator=(const Mem_bal &cell)
Copy mem balanced.
Definition: MemBalanced.hpp:83
void swap(Mem_bal &cl)
Swap two Mem_bal.
openfpm::vector< size_t > ghostMarkers
ghost marker for every cell (non-ghost particles < gm (ghost marker))
Definition: MemBalanced.hpp:49
void clear()
Reset the object.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:204