OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
main.cpp
1 
2 #include "Vector/vector_dist.hpp"
3 #include "Decomposition/CartDecomposition.hpp"
4 #include "data_type/aggregate.hpp"
5 #include "NN/CellList/CellListM.hpp"
6 #include "Vector/vector_dist_multiphase_functions.hpp"
7 
22 int main(int argc, char* argv[])
23 {
41 
43  openfpm_init(&argc,&argv);
44 
45  // Vcluster for general usage
46  Vcluster & v_cl = create_vcluster();
47 
48  // The domain
49  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
50 
51  // Boundary conditions
52  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
53 
54  // cut-off radius
55  float r_cut = 0.05;
56 
57  // ghost, big enough to contain the interaction radius
58  Ghost<3,float> ghost(r_cut);
59 
60  // The set of phases
62 
63  // first phase
64  phases.add( vector_dist<3,float, aggregate<double,double>>(4096,box,bc,ghost) );
65 
66  // The other 3 phases
67  phases.add( vector_dist<3,float, aggregate<double,double>>(phases.get(0).getDecomposition(),4096) );
68  phases.add( vector_dist<3,float, aggregate<double,double>>(phases.get(0).getDecomposition(),4096) );
69  phases.add( vector_dist<3,float, aggregate<double,double>>(phases.get(0).getDecomposition(),4096) );
70 
71 
73 
74 
92 
94  // An iterator over the particles of the phase0
95  auto it = phases.get(0).getDomainIterator();
96 
97  // For all the particles of phase0
98  while (it.isNext())
99  {
100  // particle p
101  auto p = it.get();
102 
103  // Assign the position of the particles to each phase
104  for (size_t i = 0 ; i < phases.size(); i++)
105  {
106  // Assign random position
107  phases.get(i).getPos(p)[0] = (float)rand() / RAND_MAX;
108  phases.get(i).getPos(p)[1] = (float)rand() / RAND_MAX;
109  phases.get(i).getPos(p)[2] = (float)rand() / RAND_MAX;
110  }
111 
112  // Next particle
113  ++it;
114  }
115 
116 
117  // Redistribute and sync all the phases
118  for (size_t i = 0 ; i < 4 ; i++)
119  {
120  phases.get(i).map();
121  phases.get(i).ghost_get<>();
122  }
123 
125 
150 
152  {
153 
154  // Get the cell list of the phase1
155  auto CL_phase1 = phases.get(1).getCellList(r_cut);
156 
157  // This function create a Verlet-list between phases 0 and 1
158  auto NN_ver01 = createVerlet(phases.get(0),phases.get(1),CL_phase1,r_cut);
159 
161 
174 
176  // Get an iterator of the particles of the phase0
177  it = phases.get(0).getDomainIterator();
178 
179  // For each particle of the phase0
180  while (it.isNext())
181  {
182  // Get the particle p
183  auto p = it.get();
184 
185  // reset the counter
186  phases.get(0).getProp<0>(p) = 0;
187 
188  // Get an iterator over the neighborhood particles for the particle p
189  auto Np = NN_ver01.template getNNIterator<NO_CHECK>(p.getKey());
190 
191  // For each neighborhood of the particle p
192  while (Np.isNext())
193  {
194  // Neighborhood particle q
195  auto q = Np.get();
196 
197  // Count the number of particles
198  // Here in general we can do our computation
199  phases.get(0).getProp<0>(p)++;
200 
201  // Next particle
202  ++Np;
203  }
204 
205  // Next particle
206  ++it;
207  }
208 
209  }
210 
212 
237 
239  // This function create an "Empty" Multiphase Cell List from all the phases
240 
241  // We just create a cell list with slightly bigget r_cut to avoid error in Verlet creation
242  // because of round off errors
243  float r_cut2 = r_cut*1.00001;
244  auto CL_all = createCellListM<2>(phases,r_cut2);
245 
246  // This create a Verlet-list between phase0 and all the other phases
247  auto NNver0_all = createVerletM<2>(0,phases.get(0),phases,CL_all,r_cut);
248 
250 
263 
265  // Get an iterator for the phase0 particles
266  it = phases.get(0).getDomainIterator();
267 
268  while (it.isNext())
269  {
270  // Get the particle p
271  auto p = it.get();
272 
273  // Get an interator over the neighborhood of the particle p
274  auto Np = NNver0_all.template getNNIterator<NO_CHECK>(p.getKey());
275 
276  // reset the counter
277  phases.get(0).getProp<0>(p) = 0;
278 
279  // For each neighborhood of the particle p
280  while (Np.isNext())
281  {
282  // Get the particle q near to p
283  auto q = Np.getP();
284 
285  // Get from which phase it come from
286  auto ph_q = Np.getV();
287 
288  // count
289  phases.get(0).getProp<0>(p)++;
290 
291  // Next particle
292  ++Np;
293  }
294 
295  // Next particle
296  ++it;
297  }
298 
300 
322  {
324 
325  // Get the cell list of the phase1
326  auto CL_phase1 = phases.get(1).getCellListSym(r_cut);
327 
328  // This function create a Verlet-list between phases 0 and 1
329  auto NN_ver01 = createVerletSym(phases.get(0),phases.get(1),CL_phase1,r_cut);
330 
331  // Get an iterator over the real and ghost particles
332  it = phases.get(0).getDomainAndGhostIterator();
333 
334  // For each particles
335  while (it.isNext())
336  {
337  // Get the particle p
338  auto p = it.get();
339 
340  // Reset the counter
341  phases.get(0).getProp<0>(p) = 0;
342 
343  // Next particle
344  ++it;
345  }
346 
347  // Compute interaction from phase0 to phase1
348 
349  // Get an iterator over the real particles of phase0
350  it = phases.get(0).getDomainIterator();
351 
352  // For each particle of the phase0
353  while (it.isNext())
354  {
355  // get particle p
356  auto p = it.get();
357 
358  // Get the neighborhood of particle p
359  auto Np = NN_ver01.template getNNIterator<NO_CHECK>(p.getKey());
360 
361  // For each neighborhood of the particle p
362  while (Np.isNext())
363  {
364  // Neighborhood particle q of p
365  auto q = Np.get();
366 
367  // increment the counter for the phase 0 and 1
368  phases.get(0).getProp<0>(p)++;
369  phases.get(1).getProp<0>(q)++;
370 
371  // Next particle
372  ++Np;
373  }
374 
375  // Next particle
376  ++it;
377  }
378 
379  // Merge the information of the ghost with the real particles
380  phases.get(0).ghost_put<add_,0>();
381  phases.get(1).ghost_put<add_,0>();
382 
383  }
384 
386 
408 
410  // Get an iterator over the phase0
411  it = phases.get(0).getDomainAndGhostIterator();
412 
413  // For each particle of the phase 0
414  while (it.isNext())
415  {
416  // get the particle p
417  auto p = it.get();
418 
419  // Reset the counter for the domain and ghost particles
420  phases.get(0).getProp<0>(p) = 0;
421  phases.get(1).getProp<0>(p) = 0;
422  phases.get(2).getProp<0>(p) = 0;
423  phases.get(3).getProp<0>(p) = 0;
424 
425  // next particle
426  ++it;
427  }
428 
429  // This function create an "Empty" Multiphase Cell List
430  CL_all = createCellListSymM<2>(phases,r_cut);
431 
432  // Type of the multiphase Verlet-list
433  typedef decltype(createVerletSymM<2>(0,phases.get(0),phases,CL_all,r_cut)) verlet_type;
434 
435  // for each phase we create one Verlet-list that contain the neighborhood
436  // from all the phases
437  verlet_type NNver_all[4];
438 
439  // Here we create a Verlet-list between each phases
440 
441  // 0 to all
442  NNver_all[0] = createVerletSymM<2>(0,phases.get(0),phases,CL_all,r_cut);
443 
444  // 1 to all
445  NNver_all[1] = createVerletSymM<2>(1,phases.get(1),phases,CL_all,r_cut);
446 
447  // 2 to all
448  NNver_all[2] = createVerletSymM<2>(2,phases.get(2),phases,CL_all,r_cut);
449 
450  // 3 to all
451  NNver_all[3] = createVerletSymM<2>(3,phases.get(3),phases,CL_all,r_cut);
452 
453  // For each phase
454  for (size_t i = 0 ; i < phases.size() ; i++)
455  {
456  // Get an iterator over the particles of that phase
457  it = phases.get(i).getDomainIterator();
458 
459  // for each particle of the phase
460  while (it.isNext())
461  {
462  // Get the particle p
463  auto p = it.get();
464 
465  // Get an iterator for neighborhood of the particle p
466  auto Np = NNver_all[i].template getNNIterator<NO_CHECK>(p.getKey());
467 
468  // For each neighborhood particle
469  while (Np.isNext())
470  {
471  // Get the particle q near to p
472  auto q = Np.getP();
473 
474  // Get from which phase it come from
475  auto ph_q = Np.getV();
476 
477  // increment the counter on both p and q
478  phases.get(i).getProp<0>(p)++;
479  phases.get(ph_q).getProp<0>(q)++;
480 
481  // Next particle
482  ++Np;
483  }
484 
485  // Next particle
486  ++it;
487  }
488  }
489 
490  // Merge the ghost part with the real particles
491  phases.get(0).ghost_put<add_,0>();
492  phases.get(1).ghost_put<add_,0>();
493  phases.get(2).ghost_put<add_,0>();
494  phases.get(3).ghost_put<add_,0>();
495 
497 
511 
513  // we create a reference to phase0 particle for convenience
514  vector_dist<3,float, aggregate<double,double> > & current_phase = phases.get(0);
515 
516  // Get the iterator of the particles of phase 0
517  auto it2 = current_phase.getIterator();
518 
519  // For each particle ...
520  while (it2.isNext())
521  {
522  // ... p
523  auto p = it2.get();
524 
525  // Get the position of the particle p
526  Point<3,float> xp = current_phase.getPos(p);
527 
528  // Reset to zero the propety 0
529  current_phase.getProp<0>(p) = 0.0;
530 
531  // Get an iterator of all the particles neighborhood of p
532  auto Np = CL_all.getNNIterator(CL_all.getCell(current_phase.getPos(p)));
533 
534  // For each particle near p
535  while (Np.isNext())
536  {
537  // Get the particle q near to p
538  auto q = Np.getP();
539 
540  // Get from which phase it come from
541  auto ph_q = Np.getV();
542 
543  Point<3,float> xq = phases.get(ph_q).getPos(q);
544 
545  // we accumulate all the distances
546  current_phase.getProp<0>(p) = norm(xp - xq);
547 
548  ++Np;
549  }
550 
551  // Next particle p
552  ++it2;
553  }
554 
556 
568 
570  openfpm_finalize();
571 
573 
582 }
583 
584 
585 
586 
This structure define the operation add to use with copy general.
size_t size()
Stub size.
Definition: map_vector.hpp:70
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
Definition: Ghost.hpp:39
Implementation of VCluster class.
Definition: VCluster.hpp:36
const T & get(size_t i) const
Get coordinate.
Definition: Point.hpp:142
vector_dist_iterator getIterator()
Get an iterator that traverse domain and ghost particles.
Distributed vector.
vect_dist_key_dx get()
Get the actual key.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:81
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61