OpenFPM_pdata  1.0.0
Project that contain the implementation of distributed structures
 All Data Structures Functions Variables Typedefs Enumerations Friends Pages
vector_dist_MP_unit_tests.hpp
1 /*
2  * vector_dist_MP_unit_tests.hpp
3  *
4  * Created on: Oct 14, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef SRC_VECTOR_VECTOR_DIST_MP_UNIT_TESTS_HPP_
9 #define SRC_VECTOR_VECTOR_DIST_MP_UNIT_TESTS_HPP_
10 
11 #include "Vector/vector_dist_multiphase_functions.hpp"
12 
13 BOOST_AUTO_TEST_SUITE( vector_dist_multiphase_test )
14 
15 BOOST_AUTO_TEST_CASE( vector_dist_multiphase_cell_list_test )
16 {
17  if (create_vcluster().getProcessingUnits() > 24)
18  return;
19 
20  size_t sz[3] = {60,60,40};
21 
22  // The domain
23  Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
24 
25  // Boundary conditions
26  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
27 
28  float r_cut = 51.0;
29 
30  // ghost, big enough to contain the interaction radius
31  Ghost<3,float> ghost(r_cut);
32 
34 
35  // first phase
36  phases.add( vector_dist<3,float, aggregate<double,double>>(0,box,bc,ghost) );
37 
38  // The other 3 phases
39  phases.add( vector_dist<3,float, aggregate<double,double>>(phases.get(0).getDecomposition(),0) );
40  phases.add( vector_dist<3,float, aggregate<double,double>>(phases.get(0).getDecomposition(),0) );
41  phases.add( vector_dist<3,float, aggregate<double,double>>(phases.get(0).getDecomposition(),0) );
42 
43  // Fill the phases with particles
44 
45  auto g_it = phases.get(0).getGridIterator(sz);
46 
47  while (g_it.isNext())
48  {
49  auto key = g_it.get();
50 
51  // Add a particle to all the phases
52  phases.get(0).add();
53  phases.get(1).add();
54  phases.get(2).add();
55  phases.get(3).add();
56 
57  phases.get(0).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
58  phases.get(0).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
59  phases.get(0).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
60 
61  phases.get(1).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
62  phases.get(1).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
63  phases.get(1).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
64 
65  phases.get(2).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
66  phases.get(2).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
67  phases.get(2).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
68 
69  phases.get(3).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
70  phases.get(3).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
71  phases.get(3).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
72 
73  ++g_it;
74  }
75 
76  // Sync all phases
77  for (size_t i = 0 ; i < 4 ; i++)
78  {
79  phases.get(i).map();
80  }
81 
82  // randomize a little the particles
83 
84  for (size_t p = 0 ; p < phases.size() ; p++)
85  {
87 
88  for (size_t j = 0 ; j < phases.get(p).size_local() ; j++)
89  {
90  vt.add(phases.get(p).getPos((j + p*133) % phases.get(p).size_local()));
91  }
92  phases.get(p).getPosVector().swap(vt);
93  }
94 
95  // Sync all phases
96  for (size_t i = 0 ; i < 4 ; i++)
97  {
98  phases.get(i).ghost_get<>();
99  }
100 
101  // Get the cell list of the phase 0 and 1
102  auto CL_phase0 = phases.get(0).getCellList(r_cut);
103  auto CL_phase1 = phases.get(1).getCellList(r_cut);
104 
105  // This function create a Verlet-list between phases 0 and 1
106  auto NN_ver01 = createVerlet(phases.get(0),phases.get(1),CL_phase1,r_cut);
107 
108  // Check NNver0_1
109 
110  bool ret = true;
111  auto it = phases.get(0).getDomainIterator();
112 
113  while (it.isNext())
114  {
115  auto p = it.get();
116  auto Np = NN_ver01.getNNIterator<NO_CHECK>(p.getKey());
117 
118  size_t nn_count = 0;
119 
120  // For each neighborhood of the particle p
121  while (Np.isNext())
122  {
123  // Count the number of particles
124  nn_count++;
125 
126  ++Np;
127  }
128 
129  ret &= nn_count == 7ul;
130 
131  ++it;
132  }
133 
134  BOOST_REQUIRE_EQUAL(ret,true);
135 
136  // Sync all phases
137  for (size_t i = 0 ; i < 4 ; i++)
138  {
139  phases.get(i).map();
140  phases.get(i).ghost_get<>();
141  }
142 
143  // NN_ver0_all
144 
145  // This function create an "Empty" Multiphase Cell List
146  auto CL_all = createCellListM<2>(phases,r_cut);
147 
148  // This create a Verlet-list between phase 0 and all the other phases
149  auto NNver0_all = createVerletM<2>(0,phases.get(0),phases,CL_all,r_cut);
150 
151  it = phases.get(0).getDomainIterator();
152 
153  while (it.isNext())
154  {
155  auto p = it.get();
156  auto Np = NNver0_all.getNNIterator<NO_CHECK>(p.getKey());
157 
158  size_t nn_cout[4] = {0,0,0,0};
159 
160  // For each neighborhood of the particle p
161  while (Np.isNext())
162  {
163  // Get from which phase it come from
164  auto ph_q = Np.getV();
165 
166  nn_cout[ph_q]++;
167 
168  ++Np;
169  }
170 
171  ret &= nn_cout[0] == 7;
172  ret &= nn_cout[1] == 7;
173  ret &= nn_cout[2] == 7;
174  ret &= nn_cout[3] == 7;
175 
176  ++it;
177  }
178 
179  BOOST_REQUIRE_EQUAL(ret,true);
180 }
181 
182 
183 BOOST_AUTO_TEST_CASE( vector_dist_multiphase_cell_list_sym_test )
184 {
185  if (create_vcluster().getProcessingUnits() > 24)
186  return;
187 
188  size_t sz[3] = {60,60,40};
189 
190  // The domain
191  Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
192 
193  // Boundary conditions
194  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
195 
196  float r_cut = 51.0;
197 
198  // ghost, big enough to contain the interaction radius
199  Ghost<3,float> ghost(r_cut);
200 
202 
203  // first phase
204  phases.add( vector_dist<3,float, aggregate<size_t>>(0,box,bc,ghost) );
205 
206  // The other 3 phases
207  phases.add( vector_dist<3,float, aggregate<size_t>>(phases.get(0).getDecomposition(),0) );
208  phases.add( vector_dist<3,float, aggregate<size_t>>(phases.get(0).getDecomposition(),0) );
209  phases.add( vector_dist<3,float, aggregate<size_t>>(phases.get(0).getDecomposition(),0) );
210 
211  // Fill the phases with particles
212 
213  auto g_it = phases.get(0).getGridIterator(sz);
214 
215  while (g_it.isNext())
216  {
217  auto key = g_it.get();
218 
219  // Add a particle to all the phases
220  phases.get(0).add();
221  phases.get(1).add();
222  phases.get(2).add();
223  phases.get(3).add();
224 
225  phases.get(0).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
226  phases.get(0).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
227  phases.get(0).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
228 
229  phases.get(1).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
230  phases.get(1).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
231  phases.get(1).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
232 
233  phases.get(2).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
234  phases.get(2).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
235  phases.get(2).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
236 
237  phases.get(3).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
238  phases.get(3).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
239  phases.get(3).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
240 
241  ++g_it;
242  }
243 
244  // Sync all phases
245  for (size_t i = 0 ; i < 4 ; i++)
246  {
247  phases.get(i).map();
248  }
249 
250  // randomize a little the particles
251 
252  for (size_t p = 0 ; p < phases.size() ; p++)
253  {
255 
256  for (size_t j = 0 ; j < phases.get(p).size_local() ; j++)
257  {
258  vt.add(phases.get(p).getPos((j + p*133) % phases.get(p).size_local()));
259  }
260  phases.get(p).getPosVector().swap(vt);
261  }
262 
263  // Sync all phases
264  for (size_t i = 0 ; i < 4 ; i++)
265  {
266  phases.get(i).ghost_get<>();
267  }
268 
269  // Get the cell list of the phase 0 and 1
270  auto CL_phase0 = phases.get(0).getCellListSym(r_cut);
271  auto CL_phase1 = phases.get(1).getCellListSym(r_cut);
272 
273  // This function create a Verlet-list between phases 0 and 1
274  auto NN_ver01 = createVerletSym(phases.get(0),phases.get(1),CL_phase1,r_cut);
275 
276  // Check NNver0_1
277 
278  bool ret = true;
279  auto it = phases.get(0).getDomainIterator();
280 
281  while (it.isNext())
282  {
283  auto p = it.get();
284  auto Np = NN_ver01.getNNIterator<NO_CHECK>(p.getKey());
285 
286  // For each neighborhood of the particle p
287  while (Np.isNext())
288  {
289  // Neighborhood particle q
290  auto q = Np.get();
291 
292  phases.get(0).getPropWrite<0>(p)++;
293  phases.get(1).getPropWrite<0>(q)++;
294 
295  ++Np;
296  }
297 
298  ++it;
299  }
300 
301  phases.get(0).ghost_put<add_,0>();
302  phases.get(1).ghost_put<add_,0>();
303 
304 #ifdef SE_CLASS3
305 
306  phases.get(1).getDomainIterator();
307 
308 #endif
309 
310  it = phases.get(0).getDomainIterator();
311  while (it.isNext())
312  {
313  auto p = it.get();
314 
315  ret &= phases.get(0).getPropRead<0>(p) == 7;
316  ret &= phases.get(1).getPropRead<0>(p) == 7;
317 
318  ++it;
319  }
320 
321  BOOST_REQUIRE_EQUAL(ret,true);
322 
323  // Sync all phases
324  for (size_t i = 0 ; i < 4 ; i++)
325  {
326  phases.get(i).map();
327  phases.get(i).ghost_get<>();
328  }
329 
330  // Reset counter on all phases
331 
332  for (size_t i = 0 ; i < phases.size() ; i++)
333  {
334  it = phases.get(i).getDomainAndGhostIterator();
335  while (it.isNext())
336  {
337  auto p = it.get();
338 
339  phases.get(i).getPropWrite<0>(p) = 0;
340 
341  ++it;
342  }
343  }
344 
345  // NN_ver0_all
346 
347  // This function create an "Empty" Multiphase Cell List
348  auto CL_all = createCellListSymM<2>(phases,r_cut);
349 
350  typedef decltype(createVerletSymM<2>(0,phases.get(0),phases,CL_all,r_cut)) verlet_type;
351 
352  verlet_type NNver_all[4];
353 
354  // This create a Verlet-list between each phase to all the other phases
355  NNver_all[0] = createVerletSymM<2>(0,phases.get(0),phases,CL_all,r_cut);
356  NNver_all[1] = createVerletSymM<2>(1,phases.get(1),phases,CL_all,r_cut);
357  NNver_all[2] = createVerletSymM<2>(2,phases.get(2),phases,CL_all,r_cut);
358  NNver_all[3] = createVerletSymM<2>(3,phases.get(3),phases,CL_all,r_cut);
359 
360  // all phases to all phases
361 
362  for (size_t i = 0 ; i < phases.size() ; i++)
363  {
364  it = phases.get(i).getDomainIterator();
365 
366  while (it.isNext())
367  {
368  auto p = it.get();
369  auto Np = NNver_all[i].getNNIterator<NO_CHECK>(p.getKey());
370 
371  // For each neighborhood of the particle p
372  while (Np.isNext())
373  {
374  // Get the particle q near to p
375  auto q = Np.getP();
376 
377  // Get from which phase it come from
378  auto ph_q = Np.getV();
379 
380  phases.get(i).getPropWrite<0>(p)++;
381  phases.get(ph_q).getPropWrite<0>(q)++;
382 
383  ++Np;
384  }
385 
386  ++it;
387  }
388  }
389 
390  phases.get(0).ghost_put<add_,0>();
391  phases.get(1).ghost_put<add_,0>();
392  phases.get(2).ghost_put<add_,0>();
393  phases.get(3).ghost_put<add_,0>();
394 
395 #ifdef SE_CLASS3
396 
397  it = phases.get(1).getDomainIterator();
398  it = phases.get(2).getDomainIterator();
399  it = phases.get(3).getDomainIterator();
400 
401 #endif
402 
403  it = phases.get(0).getDomainIterator();
404  while (it.isNext())
405  {
406  auto p = it.get();
407 
408  ret &= phases.get(0).getPropRead<0>(p) == 32;
409  ret &= phases.get(1).getPropRead<0>(p) == 32;
410  ret &= phases.get(2).getPropRead<0>(p) == 32;
411  ret &= phases.get(3).getPropRead<0>(p) == 32;
412 
413  if (ret == false)
414  {
415  std::cout << phases.get(0).getPropRead<0>(p) << std::endl;
416  std::cout << phases.get(1).getPropRead<0>(p) << std::endl;
417  std::cout << phases.get(2).getPropRead<0>(p) << std::endl;
418  std::cout << phases.get(3).getPropRead<0>(p) << std::endl;
419  }
420 
421  ++it;
422  }
423 
424  BOOST_REQUIRE_EQUAL(ret,true);
425 }
426 
427 BOOST_AUTO_TEST_SUITE_END()
428 
429 #endif /* SRC_VECTOR_VECTOR_DIST_MP_UNIT_TESTS_HPP_ */
This structure define the operation add to use with copy general.
size_t size()
Stub size.
Definition: map_vector.hpp:70
Definition: Ghost.hpp:37
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
Distributed vector.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:71
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61