vector_dist_NN_tests.hpp 6.04 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * vector_dist_NN_tests.hpp
 *
 *  Created on: Aug 20, 2016
 *      Author: i-bird
 */

#ifndef SRC_VECTOR_VECTOR_DIST_NN_TESTS_HPP_
#define SRC_VECTOR_VECTOR_DIST_NN_TESTS_HPP_


BOOST_AUTO_TEST_CASE( vector_dist_full_NN )
{
	Vcluster & v_cl = create_vcluster();

	if (v_cl.getProcessingUnits() > 12)
		return;

    // set the seed
	// create the random generator engine
	std::srand(v_cl.getProcessUnitID());
    std::default_random_engine eg;
    std::uniform_real_distribution<float> ud(0.0f, 1.0f);

incardon's avatar
incardon committed
25
26
27
#ifdef TEST_COVERAGE_MODE
    long int k = 50 * v_cl.getProcessingUnits();
#else
Pietro Incardona's avatar
Pietro Incardona committed
28
    long int k = 750 * v_cl.getProcessingUnits();
incardon's avatar
incardon committed
29
#endif
Pietro Incardona's avatar
Pietro Incardona committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

	long int big_step = k / 4;
	big_step = (big_step == 0)?1:big_step;

	print_test("Testing 3D full NN search k=",k);
	BOOST_TEST_CHECKPOINT( "Testing 3D full NN search k=" << k );

	Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});

	// Boundary conditions
	size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};

	for (double r_cut = 0.1 ; r_cut < 1.0; r_cut += 0.1)
	{
		// ghost
		Ghost<3,float> ghost(r_cut*1.001);

		typedef  aggregate<float> part_prop;

		// Distributed vector
		vector_dist<3,float, part_prop > vd(k,box,bc,ghost);

		auto it = vd.getIterator();

		while (it.isNext())
		{
			auto key = it.get();

			vd.getPos(key)[0] = ud(eg);
			vd.getPos(key)[1] = ud(eg);
			vd.getPos(key)[2] = ud(eg);

			// Fill some properties randomly

			vd.getProp<0>(key) = 0.0;

			++it;
		}

		vd.map();

		// sync the ghost
		vd.ghost_get<0>();

		openfpm::vector<openfpm::vector<size_t>> list_idx;
		openfpm::vector<openfpm::vector<size_t>> list_idx2;

		list_idx.resize(vd.size_local());
		list_idx2.resize(vd.size_local());

		for (size_t i = 0 ; i < vd.size_local() ; i++)
		{
			Point<3,float> p = vd.getPos(i);

			for (size_t j = 0 ; j < vd.size_local_with_ghost(); j++)
			{
				Point<3,float> q = vd.getPos(j);

				if (p.distance2(q) < r_cut * r_cut)
					list_idx.get(i).add(j);
			}

			list_idx.get(i).sort();
		}

		auto NN = vd.getCellList(r_cut);

		it = vd.getDomainIterator();

		while (it.isNext())
		{
			Point<3,float> xp = vd.getPos(it.get());
			auto Np = NN.getNNIterator<NO_CHECK>(NN.getCell(xp));

			while (Np.isNext())
			{
				auto q = Np.get();

				Point<3,float> xq = vd.getPos(q);

				if (xp.distance2(xq) < r_cut * r_cut)
					list_idx2.get(it.get().getKey()).add(q);

				++Np;
			}

			list_idx2.get(it.get().getKey()).sort();

			++it;
		}

		BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());

		bool ret;
		for (size_t i = 0 ; i < list_idx.size() ; i++)
		{
			BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());

			ret = true;
			for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
				ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);

			BOOST_REQUIRE_EQUAL(ret,true);
		}

		///////////////////////////////////

		auto NNv = vd.getVerlet(r_cut*1.0001);

		it = vd.getDomainIterator();

		while (it.isNext())
		{
			Point<3,float> xp = vd.getPos(it.get());
			auto Np = NNv.getNNIterator<NO_CHECK>(it.get().getKey());

			list_idx2.get(it.get().getKey()).clear();

			while (Np.isNext())
			{
				auto q = Np.get();

				Point<3,float> xq = vd.getPos(q);

				if (xp.distance2(xq) < r_cut * r_cut)
					list_idx2.get(it.get().getKey()).add(q);

				++Np;
			}

			list_idx2.get(it.get().getKey()).sort();

			++it;
		}

		BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());

		for (size_t i = 0 ; i < list_idx.size() ; i++)
		{
			BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());

			ret = true;
			for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
				ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);

			BOOST_REQUIRE_EQUAL(ret,true);
		}

		//////////////////////////////////////////

		NNv.clear();
		vd.updateVerlet(NNv,r_cut*1.0001);

		it = vd.getDomainIterator();

		while (it.isNext())
		{
			Point<3,float> xp = vd.getPos(it.get());
			auto Np = NNv.getNNIterator<NO_CHECK>(it.get().getKey());

			list_idx2.get(it.get().getKey()).clear();

			while (Np.isNext())
			{
				auto q = Np.get();

				Point<3,float> xq = vd.getPos(q);

				if (xp.distance2(xq) < r_cut * r_cut)
					list_idx2.get(it.get().getKey()).add(q);

				++Np;
			}

			list_idx2.get(it.get().getKey()).sort();

			++it;
		}

		BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());

		for (size_t i = 0 ; i < list_idx.size() ; i++)
		{
			BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());

			ret = true;
			for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
				ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);

			BOOST_REQUIRE_EQUAL(ret,true);
		}
	}
}

incardon's avatar
incardon committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
BOOST_AUTO_TEST_CASE( vector_dist_particle_iteration )
{
	Vcluster & v_cl = create_vcluster();

	if (v_cl.getProcessingUnits() > 12)
		return;

    // set the seed
	// create the random generator engine
	std::srand(v_cl.getProcessUnitID());
    std::default_random_engine eg;
    std::uniform_real_distribution<float> ud(0.0f, 1.0f);

    long int k = 750 * v_cl.getProcessingUnits();

	print_test("Testing 3D particle cell iterator=",k);
	BOOST_TEST_CHECKPOINT( "Testing 3D full NN search k=" << k );

	Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});

	// Boundary conditions
	size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};

incardon's avatar
incardon committed
247
	float r_cut = 0.1;
incardon's avatar
incardon committed
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303

	// ghost
	Ghost<3,float> ghost(r_cut);

	typedef  aggregate<float> part_prop;

	// Distributed vector
	vector_dist<3,float, part_prop > vd(k,box,bc,ghost,BIND_DEC_TO_GHOST);

		auto it = vd.getIterator();

		while (it.isNext())
		{
			auto key = it.get();

			vd.getPos(key)[0] = ud(eg);
			vd.getPos(key)[1] = ud(eg);
			vd.getPos(key)[2] = ud(eg);

			// Fill some properties randomly

			vd.getProp<0>(key) = 0.0;

			++it;
		}

	vd.map();

	// sync the ghost
	vd.ghost_get<0>();

	openfpm::vector<size_t> ids;
	ids.resize(vd.size_local());

	auto NN = vd.getCellListSym(r_cut);

	auto it_pcell = vd.getDomainIteratorCells(NN);

	size_t count = 0;
	while (it_pcell.isNext())
	{
		count++;

		size_t id = it_pcell.get();
		ids.get(id) = 1;

		BOOST_REQUIRE(id < vd.size_local());

		++it_pcell;
	}

	v_cl.sum(count);
	v_cl.execute();

	BOOST_REQUIRE_EQUAL((long int)count,k);
}
Pietro Incardona's avatar
Pietro Incardona committed
304
305

#endif /* SRC_VECTOR_VECTOR_DIST_NN_TESTS_HPP_ */