OpenFPM  5.2.0
Project that contain the implementation of distributed structures
MemMemoryWise.hpp
1 /*
2  * MemMemoryWise.hpp
3  *
4  * Created on: Mar 22, 2015
5  * Last modified: June 25, 2015
6  * Authors: Pietro Incardona, Yaroslav Zaluzhnyi
7  */
8 
9 #ifndef CELLISTMEM_HPP_
10 #define CELLISTMEM_HPP_
11 
12 
32 template<typename local_index = size_t>
33 class Mem_mw
34 {
37 
40  std::unordered_map<local_index,base> cl_base;
41 
43  typename std::remove_reference<decltype(std::declval<openfpm::vector<local_index>>().get(0))>::type invalid;
44 
46  std::unordered_map<local_index,size_t> ghostMarkers;
47 
48 public:
49 
50  typedef void toKernel_type;
51 
53  typedef local_index local_index_type;
54 
63  inline void init_to_zero(local_index slot, local_index tot_n_cell)
64  {
65  clear();
66  }
67 
75  inline Mem_mw & operator=(const Mem_mw & cell)
76  {
77  cl_base = cell.cl_base;
79  return *this;
80  }
81 
88  inline void addCell(local_index cell_id, typename base::value_type ele)
89  {
90  //add another neighbor element
91 
92  cl_base[cell_id].add(ele);
93  }
94 
101  inline void remove(local_index cell, local_index ele)
102  {
103  cl_base[cell].remove(ele);
104  }
105 
113  inline size_t getNelements(const local_index cell_id) const
114  {
115  auto it = cl_base.find(cell_id);
116  if (it == cl_base.end())
117  return 0;
118 
119  return it->second.size();
120  }
121 
122  inline auto get(local_index cell, local_index ele) -> decltype(cl_base[0].get(0)) &
123  {
124  auto it = cl_base.find(cell);
125  if (it == cl_base.end())
126  return invalid;
127 
128  return it->second.get(ele);
129  }
130 
131  inline auto get(local_index cell, local_index ele) const -> decltype(cl_base.find(cell)->second.get(0)) &
132  {
133  auto it = cl_base.find(cell);
134  if (it == cl_base.end())
135  return invalid;
136 
137  return it->second.get(ele);
138  }
139 
146  inline void addCellGhostMarkers()
147  {
148  for (auto it = cl_base.begin(); it != cl_base.end(); it++) {
149  ghostMarkers[it->first] = it->second.size();
150  }
151  }
152 
156  inline size_t getGhostMarker(local_index cell_id) const
157  {
158  auto it = ghostMarkers.find(cell_id);
159  if (it == ghostMarkers.end())
160  return invalid;
161 
162  return it->second;
163  }
164 
165  inline void swap(Mem_mw & cl)
166  {
167  cl_base.swap(cl.cl_base);
168  ghostMarkers.swap(cl.ghostMarkers);
169  }
170 
171  inline void swap(Mem_mw && cell)
172  {
173  cl_base.swap(cell.cl_base);
174  ghostMarkers.swap(cell.ghostMarkers);
175  }
176 
177  inline void clear()
178  {
179  cl_base.clear();
180  ghostMarkers.clear();
181  }
182 
183  inline const local_index & getStartId(size_t cell_id) const
184  {
185  auto it = cl_base.find(cell_id);
186  if (it == cl_base.end())
187  return invalid;
188 
189  return it->second.get(0);
190  }
191 
192  inline const local_index & getGhostId(size_t cell_id) const
193  {
194  auto gm_it = ghostMarkers.find(cell_id);
195  if (gm_it == ghostMarkers.end())
196  return invalid;
197 
198  auto cell_it = cl_base.find(cell_id);
199  if (cell_it == cl_base.end())
200  return invalid;
201 
202  return cell_it->second.get(gm_it->second);
203  }
204 
205  inline const local_index & getStopId(size_t cell_id) const
206  {
207  auto it = cl_base.find(cell_id);
208  if (it == cl_base.end())
209  return invalid;
210 
211  return *(&it->second.last() + 1);
212  }
213 
214  inline const local_index & get_lin(const local_index * cell_id) const
215  {
216  return *cell_id;
217  }
218 
219 public:
220 
226  inline Mem_mw(size_t slot)
227  :invalid(0)
228  {
229  }
230 
236  inline void set_slot(size_t slot)
237  {}
238 
239 };
240 
241 
242 #endif /* CELLISTMEM_HPP_ */
Class for MEMORY-WISE cell list implementation.
std::unordered_map< local_index, size_t > ghostMarkers
ghost marker for every cell (non-ghost particles < gm (ghost marker))
void init_to_zero(local_index slot, local_index tot_n_cell)
Initialize the data structure to zeros.
Mem_mw(size_t slot)
constructor
void addCell(local_index cell_id, typename base::value_type ele)
Add an element to the cell.
void set_slot(size_t slot)
Set the number of slots.
Mem_mw & operator=(const Mem_mw &cell)
Copy two data-structure.
openfpm::vector< local_index > base
Base type storing information.
void addCellGhostMarkers()
Add ghost marker to the cell.
void remove(local_index cell, local_index ele)
Remove an element from the cell.
std::unordered_map< local_index, base > cl_base
std::remove_reference< decltype(std::declval< openfpm::vector< local_index >>().get(0))>::type invalid
In case of invalid element return this.
size_t getNelements(const local_index cell_id) const
Get the number of elements in the cell.
local_index local_index_type
expose the type of the local index
size_t getGhostMarker(local_index cell_id) const
Get ghost marker of the cell.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:204