OpenFPM_pdata  1.0.0
Project that contain the implementation of distributed structures
 All Data Structures Functions Variables Typedefs Enumerations Friends Pages
vector_dist_NN_tests.hpp
1 /*
2  * vector_dist_NN_tests.hpp
3  *
4  * Created on: Aug 20, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef SRC_VECTOR_VECTOR_DIST_NN_TESTS_HPP_
9 #define SRC_VECTOR_VECTOR_DIST_NN_TESTS_HPP_
10 
11 
12 BOOST_AUTO_TEST_CASE( vector_dist_full_NN )
13 {
14  Vcluster & v_cl = create_vcluster();
15 
16  if (v_cl.getProcessingUnits() > 12)
17  return;
18 
19  // set the seed
20  // create the random generator engine
21  std::srand(v_cl.getProcessUnitID());
22  std::default_random_engine eg;
23  std::uniform_real_distribution<float> ud(0.0f, 1.0f);
24 
25 #ifdef TEST_COVERAGE_MODE
26  long int k = 50 * v_cl.getProcessingUnits();
27 #else
28  long int k = 750 * v_cl.getProcessingUnits();
29 #endif
30 
31  long int big_step = k / 4;
32  big_step = (big_step == 0)?1:big_step;
33 
34  print_test("Testing 3D full NN search k=",k);
35  BOOST_TEST_CHECKPOINT( "Testing 3D full NN search k=" << k );
36 
37  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
38 
39  // Boundary conditions
40  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
41 
42  for (double r_cut = 0.1 ; r_cut < 1.0; r_cut += 0.1)
43  {
44  // ghost
45  Ghost<3,float> ghost(r_cut*1.001);
46 
47  typedef aggregate<float> part_prop;
48 
49  // Distributed vector
50  vector_dist<3,float, part_prop > vd(k,box,bc,ghost);
51 
52  auto it = vd.getIterator();
53 
54  while (it.isNext())
55  {
56  auto key = it.get();
57 
58  vd.getPos(key)[0] = ud(eg);
59  vd.getPos(key)[1] = ud(eg);
60  vd.getPos(key)[2] = ud(eg);
61 
62  // Fill some properties randomly
63 
64  vd.getProp<0>(key) = 0.0;
65 
66  ++it;
67  }
68 
69  vd.map();
70 
71  // sync the ghost
72  vd.ghost_get<0>();
73 
76 
77  list_idx.resize(vd.size_local());
78  list_idx2.resize(vd.size_local());
79 
80  for (size_t i = 0 ; i < vd.size_local() ; i++)
81  {
82  Point<3,float> p = vd.getPos(i);
83 
84  for (size_t j = 0 ; j < vd.size_local_with_ghost(); j++)
85  {
86  Point<3,float> q = vd.getPos(j);
87 
88  if (p.distance2(q) < r_cut * r_cut)
89  list_idx.get(i).add(j);
90  }
91 
92  list_idx.get(i).sort();
93  }
94 
95  auto NN = vd.getCellList(r_cut);
96 
97  it = vd.getDomainIterator();
98 
99  while (it.isNext())
100  {
101  Point<3,float> xp = vd.getPos(it.get());
102  auto Np = NN.getNNIterator<NO_CHECK>(NN.getCell(xp));
103 
104  while (Np.isNext())
105  {
106  auto q = Np.get();
107 
108  Point<3,float> xq = vd.getPos(q);
109 
110  if (xp.distance2(xq) < r_cut * r_cut)
111  list_idx2.get(it.get().getKey()).add(q);
112 
113  ++Np;
114  }
115 
116  list_idx2.get(it.get().getKey()).sort();
117 
118  ++it;
119  }
120 
121  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
122 
123  bool ret;
124  for (size_t i = 0 ; i < list_idx.size() ; i++)
125  {
126  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
127 
128  ret = true;
129  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
130  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
131 
132  BOOST_REQUIRE_EQUAL(ret,true);
133  }
134 
136 
137  auto NNv = vd.getVerlet(r_cut*1.0001);
138 
139  it = vd.getDomainIterator();
140 
141  while (it.isNext())
142  {
143  Point<3,float> xp = vd.getPos(it.get());
144  auto Np = NNv.getNNIterator<NO_CHECK>(it.get().getKey());
145 
146  list_idx2.get(it.get().getKey()).clear();
147 
148  while (Np.isNext())
149  {
150  auto q = Np.get();
151 
152  Point<3,float> xq = vd.getPos(q);
153 
154  if (xp.distance2(xq) < r_cut * r_cut)
155  list_idx2.get(it.get().getKey()).add(q);
156 
157  ++Np;
158  }
159 
160  list_idx2.get(it.get().getKey()).sort();
161 
162  ++it;
163  }
164 
165  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
166 
167  for (size_t i = 0 ; i < list_idx.size() ; i++)
168  {
169  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
170 
171  ret = true;
172  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
173  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
174 
175  BOOST_REQUIRE_EQUAL(ret,true);
176  }
177 
179 
180  NNv.clear();
181  vd.updateVerlet(NNv,r_cut*1.0001);
182 
183  it = vd.getDomainIterator();
184 
185  while (it.isNext())
186  {
187  Point<3,float> xp = vd.getPos(it.get());
188  auto Np = NNv.getNNIterator<NO_CHECK>(it.get().getKey());
189 
190  list_idx2.get(it.get().getKey()).clear();
191 
192  while (Np.isNext())
193  {
194  auto q = Np.get();
195 
196  Point<3,float> xq = vd.getPos(q);
197 
198  if (xp.distance2(xq) < r_cut * r_cut)
199  list_idx2.get(it.get().getKey()).add(q);
200 
201  ++Np;
202  }
203 
204  list_idx2.get(it.get().getKey()).sort();
205 
206  ++it;
207  }
208 
209  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
210 
211  for (size_t i = 0 ; i < list_idx.size() ; i++)
212  {
213  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
214 
215  ret = true;
216  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
217  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
218 
219  BOOST_REQUIRE_EQUAL(ret,true);
220  }
221  }
222 }
223 
224 BOOST_AUTO_TEST_CASE( vector_dist_particle_iteration )
225 {
226  Vcluster & v_cl = create_vcluster();
227 
228  if (v_cl.getProcessingUnits() > 12)
229  return;
230 
231  // set the seed
232  // create the random generator engine
233  std::srand(v_cl.getProcessUnitID());
234  std::default_random_engine eg;
235  std::uniform_real_distribution<float> ud(0.0f, 1.0f);
236 
237  long int k = 750 * v_cl.getProcessingUnits();
238 
239  print_test("Testing 3D particle cell iterator=",k);
240  BOOST_TEST_CHECKPOINT( "Testing 3D full NN search k=" << k );
241 
242  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
243 
244  // Boundary conditions
245  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
246 
247  float r_cut = 0.1;
248 
249  // ghost
250  Ghost<3,float> ghost(r_cut);
251 
252  typedef aggregate<float> part_prop;
253 
254  // Distributed vector
255  vector_dist<3,float, part_prop > vd(k,box,bc,ghost,BIND_DEC_TO_GHOST);
256 
257  auto it = vd.getIterator();
258 
259  while (it.isNext())
260  {
261  auto key = it.get();
262 
263  vd.getPos(key)[0] = ud(eg);
264  vd.getPos(key)[1] = ud(eg);
265  vd.getPos(key)[2] = ud(eg);
266 
267  // Fill some properties randomly
268 
269  vd.getProp<0>(key) = 0.0;
270 
271  ++it;
272  }
273 
274  vd.map();
275 
276  // sync the ghost
277  vd.ghost_get<0>();
278 
280  ids.resize(vd.size_local());
281 
282  auto NN = vd.getCellListSym(r_cut);
283 
284  auto it_pcell = vd.getDomainIteratorCells(NN);
285 
286  size_t count = 0;
287  while (it_pcell.isNext())
288  {
289  count++;
290 
291  size_t id = it_pcell.get();
292  ids.get(id) = 1;
293 
294  BOOST_REQUIRE(id < vd.size_local());
295 
296  ++it_pcell;
297  }
298 
299  v_cl.sum(count);
300  v_cl.execute();
301 
302  BOOST_REQUIRE_EQUAL((long int)count,k);
303 }
304 
305 #endif /* SRC_VECTOR_VECTOR_DIST_NN_TESTS_HPP_ */
void sum(T &num)
Sum the numbers across all processors and get the result.
size_t getProcessUnitID()
Get the process unit id.
void execute()
Execute all the requests.
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:37
Implementation of VCluster class.
Definition: VCluster.hpp:36
const T & get(int i) const
Get coordinate.
Definition: Point.hpp:142
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
T distance2(const Point< dim, T > &q)
It calculate the square distance between 2 points.
Definition: Point.hpp:240
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
size_t getProcessingUnits()
Get the total number of processors.