OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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 "NN/CellList/CellList.hpp"
14 #include "Space/SpaceBox.hpp"
15 #include "util/mathutil.hpp"
16 #include "NN/CellList/CellNNIterator.hpp"
17 #include "Space/Shape/HyperCube.hpp"
18 
40 template<typename local_index = size_t>
41 class Mem_bal
42 {
45 
47  // that store the elements in the cell
49 
51  local_index invalid;
52 
53 public:
54 
56  typedef local_index loc_index;
57 
64  inline void init_to_zero(size_t slot, size_t tot_n_cell)
65  {
66  //resize the vector to needed number of cells
67 
68  cl_base.resize(tot_n_cell);
69  clear();
70  }
71 
79  inline Mem_bal & operator=(const Mem_bal & cell)
80  {
81  cl_base = cell.cl_base;
82 
83  return *this;
84  }
85 
92  inline void addCell(size_t cell_id, typename base::value_type ele)
93  {
94  //add another neighbor element
95 
96  cl_base.get(cell_id).add(ele);
97  }
98 
105  inline void add(size_t cell_id, typename base::value_type ele)
106  {
107  this->addCell(cell_id,ele);
108  }
109 
116  inline void remove(local_index cell, local_index ele)
117  {
118  cl_base.get(cell).remove(ele);
119  }
120 
128  inline local_index getNelements(const local_index cell_id) const
129  {
130  return cl_base.get(cell_id).size();
131  }
132 
141  inline auto get(local_index cell, local_index ele) -> decltype(cl_base.get(0).get(0)) &
142  {
143  return cl_base.get(cell).get(ele);
144  }
145 
154  inline auto get(local_index cell, local_index ele) const -> decltype(cl_base.get(0).get(0)) &
155  {
156  return cl_base.get(cell).get(ele);
157  }
158 
164  inline void swap(Mem_bal & cl)
165  {
166  cl_base.swap(cl.cl_base);
167  }
168 
174  inline void swap(Mem_bal && cell)
175  {
176  cl_base.swap(cell.cl_base);
177  }
178 
183  inline void clear()
184  {
185  for (size_t i = 0 ; i < cl_base.size() ; i++)
186  cl_base.get(i).clear();
187  }
188 
194  inline const local_index & getStartId(local_index part_id) const
195  {
196  if (cl_base.get(part_id).size() == 0)
197  return invalid;
198 
199  return cl_base.get(part_id).get(0);
200  }
201 
207  inline const local_index & getStopId(local_index part_id) const
208  {
209  if (cl_base.get(part_id).size() == 0)
210  return invalid;
211 
212  return *(&cl_base.get(part_id).last() + 1);
213  }
214 
224  inline const local_index & get_lin(const local_index * part_id) const
225  {
226  return *part_id;
227  }
228 
229 public:
230 
231  inline Mem_bal(size_t slot)
232  :invalid(0)
233  {}
234 
235  inline void set_slot(size_t slot)
236  {}
237 
238 };
239 
240 
241 #endif /* CELLLISTBAL_HPP_ */
local_index getNelements(const local_index cell_id) const
Get the number of elements in the cell.
void swap(Mem_bal &&cell)
Swap two Mem_bal.
void addCell(size_t cell_id, typename base::value_type ele)
Add an element to the cell.
Definition: MemBalanced.hpp:92
void add(size_t cell_id, typename base::value_type ele)
Add an element to the cell.
void init_to_zero(size_t slot, size_t tot_n_cell)
Initialize all to zero.
Definition: MemBalanced.hpp:64
Mem_bal & operator=(const Mem_bal &cell)
Copy mem balanced.
Definition: MemBalanced.hpp:79
openfpm::vector< local_index > base
vector that store the information
Definition: MemBalanced.hpp:44
const local_index & get_lin(const local_index *part_id) const
get_lin
void clear()
Reset the object.
const local_index & getStartId(local_index part_id) const
Get the start index of the selected element.
local_index invalid
Invalid element.
Definition: MemBalanced.hpp:51
local_index loc_index
expose the type of the local index
Definition: MemBalanced.hpp:56
openfpm::vector< base > cl_base
each cell has a pointer to a dynamic structure
Definition: MemBalanced.hpp:48
const local_index & getStopId(local_index part_id) const
Get the stop index of the selected element.
void swap(Mem_bal &cl)
Swap two Mem_bal.
Class for BALANCED cell list implementation.
Definition: MemBalanced.hpp:41