OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
VerletList_test.hpp
1/*
2 * VerletList_test.hpp
3 *
4 * Created on: Aug 16, 2016
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLIST_TEST_HPP_
9#define OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLIST_TEST_HPP_
10
11#include "NN/VerletList/VerletList.hpp"
12#include "NN/VerletList/VerletListM.hpp"
13
20template<unsigned int dim, typename T> void create_particles_on_grid(grid_sm<dim,void> & g_info, SpaceBox<dim,T> & box, openfpm::vector<Point<dim,T>> & v)
21{
22 // Create a grid iterator
23 grid_key_dx_iterator<dim> g_it(g_info);
24
25 // Usefull definition of points
26 Point<dim,T> end = box.getP2() - box.getP1();
27
28 Point<dim,T> middle;
29 Point<dim,T> spacing;
30
31 for (size_t i = 0 ; i < dim ; i++)
32 {
33 middle.get(i) = end.get(i) / g_info.size(i) / 2.0;
34 spacing.get(i) = end.get(i) / g_info.size(i);
35 }
36
37 while (g_it.isNext())
38 {
39 // Add 2 particles on each cell
40
41 Point<dim,T> key = Point<dim,T>(g_it.get().toPoint());
42 key = pmul(key,spacing) + box.getP1() + middle;
43
44 v.add(key);
45
46 ++g_it;
47 }
48}
49
56template<unsigned int dim, typename T> void create_particles_on_gridM(grid_sm<dim,void> & g_info,
57 T r_cut,
58 SpaceBox<dim,T> & box,
61{
62 // Create a grid iterator
63 grid_key_dx_iterator<dim> g_it(g_info);
64
65 // Usefull definition of points
66 Point<dim,T> end = box.getP2() - box.getP1();
67
68 Point<dim,T> middle;
69 Point<dim,T> spacing;
70
71 Point<dim,T> offset[dim];
72
73 size_t div[dim];
74 for (size_t i = 0 ; i < dim ; i++)
75 {
76 offset[i] = middle;
77 div[i] = 20 - 1;
78 }
79
80 for (size_t i = 0 ; i < dim ; i++)
81 offset[i].get(i) += (1.0 / g_info.size(i)) / 32.0;
82
83 for (size_t i = 0 ; i < dim ; i++)
84 {
85 middle.get(i) = end.get(i) / g_info.size(i) / 2.0;
86 spacing.get(i) = end.get(i) / g_info.size(i);
87 }
88
89 cl.Initialize(box,div);
90
91 while (g_it.isNext())
92 {
93 // Add 2 particles on each cell
94
95 Point<dim,T> key = Point<dim,T>(g_it.get().toPoint());
96 key = pmul(key,spacing) + box.getP1() + middle;
97
98 v.get(0).pos.add(Point<dim,T>(key + offset[0]));
99 v.get(1).pos.add(Point<dim,T>(key + offset[1]));
100 v.get(2).pos.add(Point<dim,T>(key + offset[2]));
101
102 cl.add(Point<dim,T>(key + offset[0]),v.get(0).pos.size()-1,0);
103 cl.add(Point<dim,T>(key + offset[1]),v.get(1).pos.size()-1,1);
104 cl.add(Point<dim,T>(key + offset[2]),v.get(2).pos.size()-1,2);
105
106 ++g_it;
107 }
108}
109
115template<unsigned int dim, typename T, typename VerS> void Verlet_list_s(SpaceBox<dim,T> & box)
116{
117 T r_cut = 1.506 * (box.getHigh(0) - box.getLow(0)) / 20;
118
119 for (size_t k = 0 ; k < 5; k++)
120 {
121 // id Cell list
122
123 size_t div[dim];
124 for (size_t i = 0 ; i < dim ; i++)
125 div[i] = 20;
126
127 grid_sm<3,void> ginfo(div);
128
130 create_particles_on_grid(ginfo,box,pos);
131
132 VerS vl1;
133
134 Box<dim,T> innerBox;
135 for (size_t i = 0 ; i < dim ; i++)
136 {
137 innerBox.setLow(i,r_cut);
138 innerBox.setHigh(i,1.0-r_cut);
139 }
140
141 vl1.Initialize(box,box,r_cut,pos,pos.size());
142
143 // Check that the verlet is consistent
144 for (size_t i = 0 ; i < pos.size() ; i++)
145 {
146 if (innerBox.isInside(pos.get(i)) == false)
147 continue;
148
149 Point<dim,T> p = pos.get(i);
150
151 if (k == 0)
152 {BOOST_REQUIRE_EQUAL(vl1.getNNPart(i),19ul);}
153
154 auto NN = vl1.getNNIterator(i);
155
156 bool ret = true;
157
158 while (NN.isNext())
159 {
160 auto k = NN.get();
161
162 T dist = p.distance(Point<dim,T>(pos.get(k)));
163
164 ret &= (dist < r_cut);
165
166 ++NN;
167 }
168
169 BOOST_REQUIRE_EQUAL(ret,true);
170 }
171
172 r_cut += 0.075;
173 }
174
175 r_cut = 1.506 * (box.getHigh(0) - box.getLow(0)) / 20;
176
177 size_t div[dim];
178 for (size_t i = 0 ; i < dim ; i++)
179 div[i] = 20-1;
180
181 grid_sm<3,void> ginfo(div);
182
184 create_particles_on_grid(ginfo,box,pos);
185
187
188 // Initialize an external cell-list
190 Box<dim,T> bt = box;
191
192 // Calculate the divisions for the Cell-lists
193 cl_param_calculate(bt,div,r_cut,Ghost<dim,T>(0.0));
194
195 // Initialize a cell-list
196 cli.Initialize(bt,div,5);
197
198 for (size_t i = 0; i < pos.size() ; i++)
199 cli.add(pos.get(i), i);
200
202
203 // Create cell-list
204
205 for (size_t k = 0 ; k < 4; k++)
206 {
208
209 VerS vl1;
210 vl1.Initialize(cli,r_cut,pos,pos,pos.size());
211
213
215
216 VerS vl2;
217 vl2.Initialize(box,box,r_cut,pos,pos.size());
218
220
221 Box<dim,T> innerBox;
222 for (size_t i = 0 ; i < dim ; i++)
223 {
224 innerBox.setLow(i,r_cut);
225 innerBox.setHigh(i,1.0-r_cut);
226 }
227
228 // Check that the verlet is consistent
229 for (size_t i = 0 ; i < pos.size() ; i++)
230 {
231 if (innerBox.isInside(pos.get(i)) == false)
232 continue;
233
234 Point<dim,T> p = pos.get(i);
235
236 if (k == 0)
237 {BOOST_REQUIRE_EQUAL(vl1.getNNPart(i),19ul);}
238 BOOST_REQUIRE_EQUAL(vl1.getNNPart(i),vl2.getNNPart(i));
239
242
244
245 bool ret = true;
246 auto NN = vl1.getNNIterator(i);
247 while (NN.isNext())
248 {
249 auto k = NN.get();
250
251 T dist = p.distance(Point<dim,T>(pos.get(k)));
252
253 ret &= (dist < r_cut);
254
255 v1.add(k);
256
257 ++NN;
258 }
259
261
262 auto NN2 = vl2.getNNIterator(i);
263 while (NN2.isNext())
264 {
265 auto k = NN2.get();
266
267 v2.add(k);
268
269 ++NN2;
270 }
271
272 ret = true;
273 v1.sort();
274 v2.sort();
275 for (size_t i = 0 ; i < v1.size(); i++)
276 {
277 ret &= v1.get(i) == v2.get(i);
278 }
279
280 BOOST_REQUIRE_EQUAL(ret,true);
281 }
282
283 r_cut += 0.075;
284 }
285}
286
287
293template<unsigned int dim, typename T, typename VerS> void Verlet_list_sM(SpaceBox<dim,T> & box)
294{
295 T r_cut = (box.getHigh(0) - box.getLow(0)) / 20;
296
297 for (size_t k = 0 ; k <= 0 ; k++)
298 {
299 // id Cell list
300
301 size_t div[dim];
302 for (size_t i = 0 ; i < dim ; i++)
303 div[i] = 31;
304
305 grid_sm<3,void> ginfo(div);
306
310
312 pos2.add(pos_v<openfpm::vector<Point<dim,T>>>(ps1));
313 pos2.add(pos_v<openfpm::vector<Point<dim,T>>>(ps2));
314 pos2.add(pos_v<openfpm::vector<Point<dim,T>>>(ps3));
315
317 create_particles_on_gridM(ginfo,r_cut,box,pos2,cl);
318
319 VerS vl1;
320
321 Box<dim,T> innerBox;
322 for (size_t i = 0 ; i < dim ; i++)
323 {
324 innerBox.setLow(i,r_cut);
325 innerBox.setHigh(i,1.0-r_cut);
326 }
327
328 vl1.Initialize(cl,0,r_cut,pos2.get(0).pos,pos2,pos2.get(0).pos.size());
329
330 // Check that the verlet is consistent
331 for (size_t i = 0 ; i < pos2.get(0).pos.size() ; i++)
332 {
333 if (innerBox.isInside(pos2.get(0).pos.get(i)) == false)
334 continue;
335
336 Point<dim,T> p = pos2.get(0).pos.get(i);
337
338 if (k == 0)
339 {BOOST_REQUIRE_EQUAL(vl1.getNNPart(i),57ul);}
340
341 auto NN = vl1.getNNIterator(i);
342
343 bool ret = true;
344
345 while (NN.isNext())
346 {
347 auto k = NN.getP();
348 auto v = NN.getV();
349
350 T dist = p.distance(Point<dim,T>(pos2.get(v).pos.get(k)));
351
352 ret &= (dist < r_cut);
353
354 ++NN;
355 }
356
357 BOOST_REQUIRE_EQUAL(ret,true);
358 }
359
360 r_cut += 0.075;
361 }
362
363 r_cut = (box.getHigh(0) - box.getLow(0)) / 20;
364
365 size_t div[dim];
366 for (size_t i = 0 ; i < dim ; i++)
367 div[i] = 31;
368
369 grid_sm<3,void> ginfo(div);
370
371 // Initialize an external cell-list
373
374
378
380 pos2.add(pos_v<openfpm::vector<Point<dim,T>>>(ps1));
381 pos2.add(pos_v<openfpm::vector<Point<dim,T>>>(ps2));
382 pos2.add(pos_v<openfpm::vector<Point<dim,T>>>(ps3));
383
384 create_particles_on_gridM(ginfo,r_cut,box,pos2,cli);
385
387
389
390 // Create cell-list
391
392 for (size_t k = 0 ; k <= 0 ; k++)
393 {
395
396 VerS vl1;
397 vl1.Initialize(cli,0,r_cut,pos2.get(0).pos,pos2,pos2.get(0).pos.size());
398
400
402
403 VerS vl2;
404 vl2.Initialize(cli,0,r_cut,pos2.get(0).pos,pos2,pos2.get(0).pos.size());
405
407
408 Box<dim,T> innerBox;
409 for (size_t i = 0 ; i < dim ; i++)
410 {
411 innerBox.setLow(i,r_cut);
412 innerBox.setHigh(i,1.0-r_cut);
413 }
414
415 // Check that the verlet is consistent
416 for (size_t i = 0 ; i < pos2.get(0).pos.size() ; i++)
417 {
418 if (innerBox.isInside(pos2.get(0).pos.get(i)) == false)
419 continue;
420
421 Point<dim,T> p = pos2.get(0).pos.get(i);
422
423 if (k == 0)
424 {BOOST_REQUIRE_EQUAL(vl1.getNNPart(i),57ul);}
425 BOOST_REQUIRE_EQUAL(vl1.getNNPart(i),vl2.getNNPart(i));
426
429
431
432 bool ret = true;
433 auto NN = vl1.getNNIterator(i);
434 while (NN.isNext())
435 {
436 auto k = NN.getP();
437 auto v = NN.getV();
438
439 T dist = p.distance(Point<dim,T>(pos2.get(v).pos.get(k)));
440
441 ret &= (dist < r_cut);
442
443 v1.add(NN.get());
444
445 ++NN;
446 }
447
449
450 auto NN2 = vl2.getNNIterator(i);
451 while (NN2.isNext())
452 {
453 auto k = NN2.get();
454
455 v2.add(k);
456
457 ++NN2;
458 }
459
460 ret = true;
461 v1.sort();
462 v2.sort();
463 for (size_t i = 0 ; i < v1.size(); i++)
464 {
465 ret &= v1.get(i) == v2.get(i);
466 }
467
468 BOOST_REQUIRE_EQUAL(ret,true);
469 }
470
471 r_cut += 0.075;
472 }
473}
474
475
476BOOST_AUTO_TEST_SUITE( VerletList_test )
477
478BOOST_AUTO_TEST_CASE( VerletList_use)
479{
480 std::cout << "Test verlet list" << "\n";
481
482 SpaceBox<3,double> box({0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f});
483 SpaceBox<3,double> box2({-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f});
484// Verlet_list_s<3,double,VerletList<3,double,FAST,shift<3,double>>>(box);
485// Verlet_list_s<3,double,VerletList<3,double,FAST,shift<3,double>> >(box2);
486 Verlet_list_sM<3,double,VerletListM<3,double,2>>(box);
487// Verlet_list_sM<3,double,CellListM<3,double,8>>(box2);
488
489 std::cout << "End verlet list" << "\n";
490
491 // Test the cell list
492}
493
494BOOST_AUTO_TEST_SUITE_END()
495
496
497
498#endif /* OPENFPM_DATA_SRC_NN_VERLETLIST_VERLETLIST_TEST_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
Point< dim, T > getP2() const
Get the point p2.
Definition Box.hpp:722
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition Box.hpp:556
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition Box.hpp:567
__host__ __device__ bool isInside(const Point< dim, T > &p) const
Check if the point is inside the box.
Definition Box.hpp:1004
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition Box.hpp:544
Point< dim, T > getP1() const
Get the point p1.
Definition Box.hpp:708
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition Box.hpp:533
Class for Multi-Phase cell-list.
Definition CellListM.hpp:52
void add(const T(&pos)[dim], size_t ele, size_t v_id)
Add an element in the cell list.
Class for FAST cell list implementation.
Definition CellList.hpp:357
void add(const T(&pos)[dim], typename Mem_type::local_index_type ele)
Add an element in the cell list.
Definition CellList.hpp:726
void Initialize(CellDecomposer_sm< dim, T, transform > &cd_sm, const Box< dim, T > &dom_box, const size_t pad=1, size_t slot=STARTING_NSLOT)
Definition CellList.hpp:465
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
__device__ __host__ T distance(const Point< dim, T > &q) const
It calculate the distance between 2 points.
Definition Point.hpp:250
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition Point.hpp:172
This class represent an N-dimensional box.
Definition SpaceBox.hpp:27
Declaration grid_sm.
Definition grid_sm.hpp:167
__device__ __host__ size_t size() const
Return the size of the grid.
Definition grid_sm.hpp:657
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
Structure that contain a reference to a vector of particles.