OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
40template<typename local_index = size_t>
42{
45
47 // that store the elements in the cell
49
51 local_index invalid;
52
53public:
54
55 typedef void toKernel_type;
56
58 typedef local_index local_index_type;
59
66 inline void init_to_zero(size_t slot, size_t tot_n_cell)
67 {
68 //resize the vector to needed number of cells
69
70 cl_base.resize(tot_n_cell);
71 clear();
72 }
73
81 inline Mem_bal & operator=(const Mem_bal & cell)
82 {
83 cl_base = cell.cl_base;
84
85 return *this;
86 }
87
94 inline void addCell(size_t cell_id, typename base::value_type ele)
95 {
96 //add another neighbor element
97
98 cl_base.get(cell_id).add(ele);
99 }
100
107 inline void add(size_t cell_id, typename base::value_type ele)
108 {
109 this->addCell(cell_id,ele);
110 }
111
118 inline void remove(local_index cell, local_index ele)
119 {
120 cl_base.get(cell).remove(ele);
121 }
122
130 inline local_index getNelements(const local_index cell_id) const
131 {
132 return cl_base.get(cell_id).size();
133 }
134
143 inline auto get(local_index cell, local_index ele) -> decltype(cl_base.get(0).get(0)) &
144 {
145 return cl_base.get(cell).get(ele);
146 }
147
156 inline auto get(local_index cell, local_index ele) const -> decltype(cl_base.get(0).get(0)) &
157 {
158 return cl_base.get(cell).get(ele);
159 }
160
166 inline void swap(Mem_bal & cl)
167 {
168 cl_base.swap(cl.cl_base);
169 }
170
176 inline void swap(Mem_bal && cell)
177 {
178 cl_base.swap(cell.cl_base);
179 }
180
185 inline void clear()
186 {
187 for (size_t i = 0 ; i < cl_base.size() ; i++)
188 cl_base.get(i).clear();
189 }
190
196 inline const local_index & getStartId(local_index part_id) const
197 {
198 if (cl_base.get(part_id).size() == 0)
199 return invalid;
200
201 return cl_base.get(part_id).get(0);
202 }
203
209 inline const local_index & getStopId(local_index part_id) const
210 {
211 if (cl_base.get(part_id).size() == 0)
212 return invalid;
213
214 return *(&cl_base.get(part_id).last() + 1);
215 }
216
226 inline const local_index & get_lin(const local_index * part_id) const
227 {
228 return *part_id;
229 }
230
231public:
232
233 inline Mem_bal(size_t slot)
234 :invalid(0)
235 {}
236
237 inline void set_slot(size_t slot)
238 {}
239
240};
241
242
243#endif /* CELLLISTBAL_HPP_ */
Class for BALANCED cell list implementation.
local_index local_index_type
expose the type of the local index
openfpm::vector< base > cl_base
each cell has a pointer to a dynamic structure
const local_index & get_lin(const local_index *part_id) const
get_lin
void addCell(size_t cell_id, typename base::value_type ele)
Add an element to the cell.
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.
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.
local_index invalid
Invalid element.
void add(size_t cell_id, typename base::value_type ele)
Add an element to the cell.
void remove(local_index cell, local_index ele)
Remove an element from the cell.
openfpm::vector< local_index > base
vector that store the information
const local_index & getStopId(local_index part_id) const
Get the stop index of the selected element.
const local_index & getStartId(local_index part_id) const
Get the start index of the selected element.
void init_to_zero(size_t slot, size_t tot_n_cell)
Initialize all to zero.
void swap(Mem_bal &cl)
Swap two Mem_bal.
Mem_bal & operator=(const Mem_bal &cell)
Copy mem balanced.
void clear()
Reset the object.
Implementation of 1-D std::vector like structure.