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 
19 int main(int argc, char* argv[])
20 {
34 
36  openfpm_init(&argc,&argv);
37  Vcluster & v_cl = create_vcluster();
38 
39  // we will place the particles on a grid like way with 128 particles on each direction
40  size_t sz[3] = {128,128,128};
41 
42  // The domain
43  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
44 
45  // Boundary conditions
46  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
47 
48  // ghost, big enough to contain the interaction radius
49  Ghost<3,float> ghost(1.0/(128-2));
50 
52 
68 
71 
73 
142 
144  auto it = vd.getGridIterator(sz);
145 
146  // For all the particles
147  while (it.isNext())
148  {
149  vd.add();
150 
151  auto key = it.get();
152 
153  // The position of the particle is given by the point-index (0,0,0) ; (0,0,1) ... (127,127,127)
154  // multiplied by the spacing
155  vd.getLastPos()[0] = key.get(0) * it.getSpacing(0);
156  vd.getLastPos()[1] = key.get(1) * it.getSpacing(1);
157  vd.getLastPos()[2] = key.get(2) * it.getSpacing(2);
158 
159  // next point
160  ++it;
161  }
162 
164 
197 
199  vd.ghost_get<0,1,2>();
200 
202 
230 
232  float r_cut = 1.0/(128-2);
233 
234  // Get cell list
235  auto NN = vd.getCellList(r_cut);
236 
237  // Get the iterator
238  auto it2 = vd.getDomainIterator();
239 
240  // For each particle ...
241  while (it2.isNext())
242  {
243  // ... p
244  auto p = it2.get();
245 
246  // Get the position of the particle p
247  Point<3,float> xp = vd.getPos(p);
248 
249  // Get an iterator of all the particles neighborhood of p
250  auto Np = NN.getNNIterator(NN.getCell(vd.getPos(p)));
251 
252  // For each particle near p
253  while (Np.isNext())
254  {
255  // Get the particle q near to p
256  auto q = Np.get();
257 
258  // Get the position of the particle q
259  Point<3,float> xq = vd.getPos(q);
260 
261  // Calculate the distance vector between p and q
262  Point<3,float> f = (xp - xq);
263 
264  // we sum the distance of all the particles
265  vd.template getProp<0>(p) += f.norm();;
266 
267  // we sum the distance of all the particles
268  vd.template getProp<1>(p)[0] += f.get(0);
269  vd.template getProp<1>(p)[1] += f.get(1);
270  vd.template getProp<1>(p)[2] += f.get(2);
271 
272  // Moment of inertia
273  vd.template getProp<2>(p)[0][0] += (xp.get(0) - xq.get(0)) * (xp.get(0) - xq.get(0));
274  vd.template getProp<2>(p)[0][1] += (xp.get(0) - xq.get(0)) * (xp.get(1) - xq.get(1));
275  vd.template getProp<2>(p)[0][2] += (xp.get(0) - xq.get(0)) * (xp.get(2) - xq.get(2));
276  vd.template getProp<2>(p)[1][0] += (xp.get(1) - xq.get(1)) * (xp.get(0) - xq.get(0));
277  vd.template getProp<2>(p)[1][1] += (xp.get(1) - xq.get(1)) * (xp.get(1) - xq.get(1));
278  vd.template getProp<2>(p)[1][2] += (xp.get(1) - xq.get(1)) * (xp.get(2) - xq.get(2));
279  vd.template getProp<2>(p)[2][0] += (xp.get(2) - xq.get(2)) * (xp.get(0) - xq.get(0));
280  vd.template getProp<2>(p)[2][1] += (xp.get(2) - xq.get(2)) * (xp.get(1) - xq.get(1));
281  vd.template getProp<2>(p)[2][2] += (xp.get(2) - xq.get(2)) * (xp.get(2) - xq.get(2));
282 
283  ++Np;
284  }
285 
286  // Next particle p
287  ++it2;
288  }
289 
291 
311 
313  auto verlet = vd.getVerlet(r_cut);
314 
315  auto it3 = vd.getDomainIterator();
316 
317  // For each particle i verlet.size() == Number of particles
318  while (it3.isNext())
319  {
320  auto p = it3.get();
321 
322  // get the position of the particle i
323  Point<3,float> xp = vd.getPos(p);
324 
325  // get the Neighborhood of p
326  auto NNp = verlet.getNNIterator(p.getKey());
327 
328  // for each neighborhood j of particle to i
329  while (NNp.isNext())
330  {
331  size_t q = NNp.get();
332 
333  // Get the position of the particle neighborhood if i
334  Point<3,float> xq = vd.getPos(q);
335 
336  // Calculate the distance vector between p and q
337  Point<3,float> f = (xp - xq);
338 
339  // we sum the distance of all the particles
340  vd.template getProp<0>(p) += f.norm();;
341 
342  // we sum the distance of all the particles
343  vd.template getProp<1>(p)[0] += f.get(0);
344  vd.template getProp<1>(p)[1] += f.get(1);
345  vd.template getProp<1>(p)[2] += f.get(2);
346 
347  // Moment of inertia
348  vd.template getProp<2>(p)[0][0] += (xp.get(0) - xq.get(0)) * (xp.get(0) - xq.get(0));
349  vd.template getProp<2>(p)[0][1] += (xp.get(0) - xq.get(0)) * (xp.get(1) - xq.get(1));
350  vd.template getProp<2>(p)[0][2] += (xp.get(0) - xq.get(0)) * (xp.get(2) - xq.get(2));
351  vd.template getProp<2>(p)[1][0] += (xp.get(1) - xq.get(1)) * (xp.get(0) - xq.get(0));
352  vd.template getProp<2>(p)[1][1] += (xp.get(1) - xq.get(1)) * (xp.get(1) - xq.get(1));
353  vd.template getProp<2>(p)[1][2] += (xp.get(1) - xq.get(1)) * (xp.get(2) - xq.get(2));
354  vd.template getProp<2>(p)[2][0] += (xp.get(2) - xq.get(2)) * (xp.get(0) - xq.get(0));
355  vd.template getProp<2>(p)[2][1] += (xp.get(2) - xq.get(2)) * (xp.get(1) - xq.get(1));
356  vd.template getProp<2>(p)[2][2] += (xp.get(2) - xq.get(2)) * (xp.get(2) - xq.get(2));
357 
358  ++NNp;
359  }
360 
361  ++it3;
362  }
363 
365 
392 
394  // Get cell list
395  auto NN4 = vd.getCellList<CELL_MEMBAL(3,float)>(r_cut);
396  auto NN5 = vd.getCellList<CELL_MEMMW(3,float)>(r_cut);
397 
399 
411 
413  openfpm_finalize();
414 
416 
425 }
426 
427 
428 
429 
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
T norm()
norm of the vector
Definition: Point.hpp:202
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
Distributed vector.