OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
vector_dist_subset.hpp
1 //
2 // Created by Abhinav Singh on 24.02.20.
3 //
4 
5 #ifndef OPENFPM_PDATA_VECTOR_DIST_SUBSET_HPP
6 #define OPENFPM_PDATA_VECTOR_DIST_SUBSET_HPP
7 
8 #include "vector_dist.hpp"
9 
10 template<unsigned int dim,
11  typename St,
12  typename prop,
14  typename Memory = HeapMemory,
15  template<typename> class layout_base = memory_traits_lin>
16 class vector_dist_ws : public vector_dist<dim,St,typename AggregateAppend<int,prop>::type,Decomposition,Memory,layout_base>
17 {
18  public:
19 
20  typedef prop value_type;
21 
23 
24  typedef boost::mpl::int_<AggregateAppend<int,prop>::type::max_prop-1> flag_prop;
25 
26  void setSubset(vect_dist_key_dx key, int sub_id)
27  {
28  this->template getProp<flag_prop::value>(key) = sub_id;
29  }
30 
31  void ghost_get_subset()
32  {
33  this->template ghost_get<flag_prop::value>(NO_POSITION | SKIP_LABELLING);
34  }
35 
36  void getLastSubset(int sub_id)
37  {
38  this->template getProp<flag_prop::value>(this->size_local()-1) = sub_id;
39  }
40 
41  inline bool write_frame(std::string out, size_t iteration, int opt = VTK_WRITER)
42  {
43  auto &prop_names=this->getPropNames();
44  if(prop_names.size()<prop::max_prop+1){
45  prop_names.add({"SubsetNumber"});
46  }
47 
48  return vector_dist<dim,St,typename AggregateAppend<int,prop>::type,Decomposition,Memory,layout_base>::write_frame(out,iteration,opt);
49  }
50 
51  inline bool write(std::string out,int opt = VTK_WRITER)
52  {
53  auto &prop_names=this->getPropNames();
54  if(prop_names.size()<prop::max_prop+1){
55  prop_names.add({"SubsetNumber"});
56  }
57 
58  return vector_dist<dim,St,typename AggregateAppend<int,prop>::type,Decomposition,Memory,layout_base>::write(out,"",opt);
59  }
60 
61 };
62 
63 template<unsigned int dim,
64  typename St,
65  typename prop,
67  typename Memory = HeapMemory,
68  template<typename> class layout_base = memory_traits_lin>
70 {
72 
73  typedef boost::mpl::int_<AggregateAppend<int,prop>::type::max_prop-1> flag_prop;
74 
75  ivector_dist & vd;
76 
78 
79  size_t sub_id;
80 
81 #ifdef SE_CLASS1
82  int subsetUpdate_ctr=0;
83 #endif
84 
85  void check_gm()
86  {
87  #ifdef SE_CLASS1
88  for (size_t i = 0 ; i < pid.size() ; i++)
89  {
90  if (pid.template get<0>(i) >= vd.size_local())
91  {
92  std::cout << __FILE__ << ":" << __LINE__ << " Error you have ghost particles in your subset" << std::endl;
93  }
94  }
95  #endif
96  }
97 
98 public:
99 
101  typedef typename ivector_dist::value_type value_type;
102 
104 
106 
108  typedef typename ivector_dist::stype stype;
109 
111  static const unsigned int dims = ivector_dist::dims;
112 
114  typedef int yes_i_am_vector_dist;
115 
117  typedef std::integral_constant<bool,true> is_it_a_subset;
118 
120  int sub_id)
121  :vd(vd),sub_id(sub_id)
122  {
123 #ifdef SE_CLASS1
124  subsetUpdate_ctr=vd.getMapCtr();
125 #endif
126  // construct pid vector
127 
128  auto it = vd.getDomainIterator();
129 
130  while (it.isNext())
131  {
132  auto p = it.get();
133 
134  if (vd.template getProp<flag_prop::value>(p) == sub_id)
135  {
136  pid.add();
137  pid.template get<0>(pid.size()-1) = p.getKey();
138  }
139 
140  ++it;
141  }
142 
143  check_gm();
144  }
145 
146  void ghost_get_subset()
147  {
148  vd.template ghost_get<flag_prop::value>(NO_POSITION | SKIP_LABELLING);
149  }
150 
157  {
158  return pid;
159  }
160 
161 #ifdef SE_CLASS1
162  int getUpdateCtr() const{
163  return subsetUpdate_ctr;
164  }
165  int getMapCtr()
166  {
167  return vd.getMapCtr();
168  }
169 #endif
170 
174  inline void update()
175  {
176 #ifdef SE_CLASS1
177  subsetUpdate_ctr=vd.getMapCtr();
178 #endif
179 
180  ghost_get_subset();
181 
182  pid.clear();
183 
184  auto it = vd.getDomainIterator();
185 
186  while (it.isNext())
187  {
188  auto p = it.get();
189 
190  if (vd.template getProp<flag_prop::value>(p) == sub_id)
191  {
192  pid.add();
193  pid.template get<0>(pid.size()-1) = p.getKey();
194  }
195 
196  ++it;
197  }
198 
199  check_gm();
200  }
201 
208  {
209  return vd.getDecomposition();
210  }
211 
217  inline const Decomposition & getDecomposition() const
218  {
219  return vd.getDecomposition();
220  }
221 
227  size_t size_local() const
228  {
229  return pid.size();
230  }
231 
237  size_t size_local_orig() const
238  {
239  return vd.size_local();
240  }
241 
242 #ifndef ONLY_READWRITE_GETTER
243 
253  inline auto getPos(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
254  {
255  return vd.getPos(vect_dist_key_dx(pid.template get<0>(vec_key.getKey())));
256  }
257 
267  inline auto getPos(vect_dist_key_dx vec_key) const -> decltype(vd.getPos(vec_key))
268  {
269  return vd.getPos(vect_dist_key_dx(pid.template get<0>(vec_key.getKey())));
270  }
271 
281  inline auto getPosOrig(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
282  {
283  return vd.getPos(vec_key.getKey());
284  }
285 
295  inline auto getPosOrig(vect_dist_key_dx vec_key) const -> decltype(vd.getPos(vec_key))
296  {
297  return vd.getPos(vec_key.getKey());
298  }
299 
310  template<unsigned int id> inline auto getProp(vect_dist_key_dx vec_key) -> decltype(vd.template getProp<id>(vec_key))
311  {
312  return vd.template getProp<id>(vect_dist_key_dx(pid.template get<0>(vec_key.getKey())));
313  }
314 
325  template<unsigned int id> inline auto getProp(vect_dist_key_dx vec_key) const -> decltype(vd.template getProp<id>(vec_key))
326  {
327  return vd.template getProp<id>(vect_dist_key_dx(pid.template get<0>(vec_key.getKey())));
328  }
329 
330 
331  vect_dist_key_dx getOriginKey(vect_dist_key_dx vec_key)
332  {
333  return vect_dist_key_dx(pid.template get<0>(vec_key.getKey()));
334  }
335 
336 #endif
337 
344  {
345 #ifdef SE_CLASS3
346  se3.getIterator();
347 #endif
348 
349  return vector_dist_iterator_subset(0,pid.size(),pid);
350  }
351 
362  template<typename CellL = CellList_gen<dim, St, Process_keys_lin, Mem_fast<>, shift<dim, St>, typename std::remove_reference<decltype(vd.getPosVector())>::type > >
363  CellL getCellList(St r_cut, bool no_se3 = false)
364  {
365 #ifdef SE_CLASS3
366  if (no_se3 == false)
367  {se3.getNN();}
368 #endif
369 
370  // Get ghost and anlarge by 1%
371  Ghost<dim,St> g = vd.getDecomposition().getGhost();
372  g.magnify(1.013);
373 
374  return getCellList<CellL>(r_cut, g,no_se3);
375  }
376 
382  bool isSubset() const
383  {
384  return true;
385  }
386 
403  template<typename CellL = CellList_gen<dim, St, Process_keys_lin, Mem_fast<>, shift<dim, St> > >
404  CellL getCellList(St r_cut, const Ghost<dim, St> & enlarge, bool no_se3 = false)
405  {
406 #ifdef SE_CLASS3
407  if (no_se3 == false)
408  {se3.getNN();}
409 #endif
410 
411  CellL cell_list;
412 
413  // Division array
414  size_t div[dim];
415 
416  // get the processor bounding box
417  Box<dim, St> pbox = vd.getDecomposition().getProcessorBounds();
418 
419  // Processor bounding box
420  cl_param_calculate(pbox, div, r_cut, enlarge);
421 
422  cell_list.Initialize(pbox, div);
423  cell_list.set_gm(pid.size());
424  cell_list.set_ndec(vd.getDecomposition().get_ndec());
425 
426  cell_list.clear();
427 
428  auto it = getDomainIterator();
429 
430  while (it.isNext())
431  {
432  auto key = it.get();
433 
434  Point<dim,St> pos = getPos(key);
435 
436  cell_list.add(pos,pid.template get<0>(key.getKey()));
437 
438  ++it;
439  }
440 
441  // Add also the ghost
442 
443  auto git = vd.getGhostIterator();
444 
445  while (git.isNext())
446  {
447  auto key = git.get();
448 
449  Point<dim,St> pos = vd.getPos(key);
450 
451  if (vd.template getProp<flag_prop::value>(key) == sub_id)
452  {
453  cell_list.add(pos,key.getKey());
454  }
455 
456  ++git;
457  }
458 
459  return cell_list;
460  }
461 
471  {
472  vd = v.vd;
473  pid = v.pid;
474 
475  return *this;
476  }
477 };
478 
479 
480 
481 #endif //OPENFPM_PDATA_VECTOR_DIST_SUBSET_HPP
bool isSubset() const
Indicate that this class is not a subset.
Decomposition & getDecomposition()
Get the decomposition.
Transform the boost::fusion::vector into memory specification (memory_traits)
openfpm::vector< aggregate< int > > & getIds()
Return the ids.
CellL getCellList(St r_cut, const Ghost< dim, St > &enlarge, bool no_se3=false)
Construct a cell list starting from the stored particles.
void magnify(T mg)
Magnify the box.
Definition: Box.hpp:889
const Decomposition & getDecomposition() const
Get the decomposition.
auto getPos(vect_dist_key_dx vec_key) -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
Grid key for a distributed grid.
size_t size()
Stub size.
Definition: map_vector.hpp:211
vector_dist_iterator getGhostIterator() const
Get the iterator across the position of the ghost particles.
This class allocate, and destroy CPU memory.
Definition: HeapMemory.hpp:39
auto getPos(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
Get the position of an element.
CellL getCellList(St r_cut, bool no_se3=false)
Construct a cell list starting from the stored particles.
This class define the domain decomposition interface.
std::integral_constant< bool, true > is_it_a_subset
Subset detection.
size_t size_local() const
return the local size of the vector
This class decompose a space into sub-sub-domains and distribute them across processors.
auto getProp(vect_dist_key_dx vec_key) -> decltype(vd.template getProp< id >(vec_key))
Get the property of an element.
auto getPos(vect_dist_key_dx vec_key) const -> decltype(vd.getPos(vec_key))
Get the position of an element.
ivector_dist::value_type value_type
property object
ivector_dist::stype stype
space type
vector_dist_subset< dim, St, prop, Decomposition, Memory, layout_base > & operator=(const vector_dist_subset< dim, St, prop, Decomposition, Memory, layout_base > &v)
Operator= for distributed vector.
Iterator that Iterate across particle indexes.
vector_dist_iterator_subset getDomainIterator() const
Get an iterator that traverse the particles in the domain.
__device__ __host__ size_t getKey() const
Get the key.
Distributed vector.
auto getPosOrig(vect_dist_key_dx vec_key) -> decltype(vd.getPos(vec_key))
Get the position of an element.
vect_dist_key_dx get()
Get the actual key.
size_t size_local_orig() const
return the local size of the original vector
void update()
Update the subset indexes.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:202
auto getProp(vect_dist_key_dx vec_key) const -> decltype(vd.template getProp< id >(vec_key))
Get the property of an element.
Class for FAST cell list implementation.
Definition: CellList.hpp:356
vector_dist_iterator getDomainIterator() const
Get an iterator that traverse the particles in the domain.
static const unsigned int dims
dimensions of space
Decomposition & getDecomposition()
Get the decomposition.
auto getPosOrig(vect_dist_key_dx vec_key) const -> decltype(vd.getPos(vec_key))
Get the position of an element.