nn_processor_unit_test.hpp 11.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * nn_processor_unit_test.hpp
 *
 *  Created on: Dec 16, 2015
 *      Author: i-bird
 */

#ifndef SRC_DECOMPOSITION_NN_PROCESSOR_UNIT_TEST_HPP_
#define SRC_DECOMPOSITION_NN_PROCESSOR_UNIT_TEST_HPP_

incardon's avatar
incardon committed
11
#include "VCluster/VCluster.hpp"
12

13
void create_decomposition2x2(openfpm::vector<openfpm::vector<long unsigned int>> & box_nn_processor, openfpm::vector<SpaceBox<2,float>> & sub_domains)
14
{
15
	Vcluster<> & v_cl = create_vcluster();
16

17
	box_nn_processor.add();
18

19
20
21
22
23
	if (v_cl.getProcessUnitID() == 0)
	{
		box_nn_processor.get(0).add(1);
		box_nn_processor.get(0).add(2);
		box_nn_processor.get(0).add(3);
24

25
26
27
28
29
30
31
		sub_domains.add(Box<2,float>({0.0,0.0},{0.5,0.5}));
	}
	else if (v_cl.getProcessUnitID() == 1)
	{
		box_nn_processor.get(0).add(0);
		box_nn_processor.get(0).add(2);
		box_nn_processor.get(0).add(3);
32

33
34
35
36
37
38
39
		sub_domains.add(Box<2,float>({0.5,0.0},{1.0,0.5}));
	}
	else if (v_cl.getProcessUnitID() == 2)
	{
		box_nn_processor.get(0).add(1);
		box_nn_processor.get(0).add(0);
		box_nn_processor.get(0).add(3);
40

41
42
43
44
45
46
47
		sub_domains.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
	}
	else if (v_cl.getProcessUnitID() == 3)
	{
		box_nn_processor.get(0).add(1);
		box_nn_processor.get(0).add(2);
		box_nn_processor.get(0).add(0);
48

49
50
51
		sub_domains.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
	}
}
52

53
BOOST_AUTO_TEST_SUITE( nn_processor_test )
54

55
56
BOOST_AUTO_TEST_CASE( nn_processor_np_test)
{
57
	Vcluster<> & v_cl = create_vcluster();
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

	/*!
	 *
	 * We test this situation
	 *
	 * \verbatim
		+-------+-------+
		|       |       |
		|   0   |   1   |
		|       |       |
		|       |       |
		+---------------+
		|       |       |
		|   2   |   3   |
		|       |       |
		|       |       |
		+-------+-------+

	 * \endverbatim
	 *
	 *
	 */

	if (v_cl.getProcessingUnits() != 4)
		return;

	openfpm::vector<openfpm::vector<long unsigned int>> box_nn_processor;
	openfpm::vector<SpaceBox<2,float>> sub_domains;

	create_decomposition2x2(box_nn_processor,sub_domains);

	nn_prcs<2,float> nnp(v_cl);
	nnp.create(box_nn_processor, sub_domains);
91

Pietro Incardona's avatar
Pietro Incardona committed
92
	BOOST_REQUIRE_EQUAL(nnp.getNNProcessors(),3ul);
93

94
	if (v_cl.getProcessUnitID() == 0)
95
	{
Pietro Incardona's avatar
Pietro Incardona committed
96
97
98
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(1),1ul);
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(2),1ul);
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(3),1ul);
99

100
101
102
		const openfpm::vector< ::Box<2,float> > & nsubs1 = nnp.getNearSubdomains(1);
		const openfpm::vector< ::Box<2,float> > & nsubs2 = nnp.getNearSubdomains(2);
		const openfpm::vector< ::Box<2,float> > & nsubs3 = nnp.getNearSubdomains(3);
103

104
105
106
		SpaceBox<2,float> b1_a = nsubs1.get(0);
		SpaceBox<2,float> b2_a = nsubs2.get(0);
		SpaceBox<2,float> b3_a = nsubs3.get(0);
107
108


109
110
111
		SpaceBox<2,float> b1_b = Box<2,float>({0.5,0.0},{1.0,0.5});
		SpaceBox<2,float> b2_b = Box<2,float>({0.0,0.5},{0.5,1.0});
		SpaceBox<2,float> b3_b = Box<2,float>({0.5,0.5},{1.0,1.0});
112

113
114
115
		bool ret1 = b1_a == b1_b;
		bool ret2 = b2_a == b2_b;
		bool ret3 = b3_a == b3_b;
116

117
118
119
120
121
122
		BOOST_REQUIRE_EQUAL(ret1,true);
		BOOST_REQUIRE_EQUAL(ret2,true);
		BOOST_REQUIRE_EQUAL(ret3,true);
	}
	else if (v_cl.getProcessUnitID() == 1)
	{
Pietro Incardona's avatar
Pietro Incardona committed
123
124
125
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(0),1ul);
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(2),1ul);
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(3),1ul);
126

127
128
129
		const openfpm::vector< ::Box<2,float> > & nsubs1 = nnp.getNearSubdomains(0);
		const openfpm::vector< ::Box<2,float> > & nsubs2 = nnp.getNearSubdomains(2);
		const openfpm::vector< ::Box<2,float> > & nsubs3 = nnp.getNearSubdomains(3);
130

131
132
133
		SpaceBox<2,float> b1_a = nsubs1.get(0);
		SpaceBox<2,float> b2_a = nsubs2.get(0);
		SpaceBox<2,float> b3_a = nsubs3.get(0);
134
135


136
137
138
		SpaceBox<2,float> b1_b = Box<2,float>({0.0,0.0},{0.5,0.5});
		SpaceBox<2,float> b2_b = Box<2,float>({0.0,0.5},{0.5,1.0});
		SpaceBox<2,float> b3_b = Box<2,float>({0.5,0.5},{1.0,1.0});
139

140
141
142
		bool ret1 = b1_a == b1_b;
		bool ret2 = b2_a == b2_b;
		bool ret3 = b3_a == b3_b;
143

144
145
146
		BOOST_REQUIRE_EQUAL(ret1,true);
		BOOST_REQUIRE_EQUAL(ret2,true);
		BOOST_REQUIRE_EQUAL(ret3,true);
147
	}
148
	else if (v_cl.getProcessUnitID() == 2)
149
	{
Pietro Incardona's avatar
Pietro Incardona committed
150
151
152
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(1),1ul);
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(0),1ul);
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(3),1ul);
153

154
155
156
		const openfpm::vector< ::Box<2,float> > & nsubs1 = nnp.getNearSubdomains(1);
		const openfpm::vector< ::Box<2,float> > & nsubs2 = nnp.getNearSubdomains(0);
		const openfpm::vector< ::Box<2,float> > & nsubs3 = nnp.getNearSubdomains(3);
157

158
159
160
		SpaceBox<2,float> b1_a = nsubs1.get(0);
		SpaceBox<2,float> b2_a = nsubs2.get(0);
		SpaceBox<2,float> b3_a = nsubs3.get(0);
161

162
163
164
		SpaceBox<2,float> b1_b = Box<2,float>({0.5,0.0},{1.0,0.5});
		SpaceBox<2,float> b2_b = Box<2,float>({0.0,0.0},{0.5,0.5});
		SpaceBox<2,float> b3_b = Box<2,float>({0.5,0.5},{1.0,1.0});
165

166
167
168
		bool ret1 = b1_a == b1_b;
		bool ret2 = b2_a == b2_b;
		bool ret3 = b3_a == b3_b;
169

170
171
172
		BOOST_REQUIRE_EQUAL(ret1,true);
		BOOST_REQUIRE_EQUAL(ret2,true);
		BOOST_REQUIRE_EQUAL(ret3,true);
173
	}
174
175
	else if (v_cl.getProcessUnitID() == 3)
	{
Pietro Incardona's avatar
Pietro Incardona committed
176
177
178
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(0),1ul);
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(1),1ul);
		BOOST_REQUIRE_EQUAL(nnp.getNRealSubdomains(2),1ul);
179

180
181
182
		const openfpm::vector< ::Box<2,float> > & nsubs1 = nnp.getNearSubdomains(0);
		const openfpm::vector< ::Box<2,float> > & nsubs2 = nnp.getNearSubdomains(1);
		const openfpm::vector< ::Box<2,float> > & nsubs3 = nnp.getNearSubdomains(2);
183

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
		SpaceBox<2,float> b1_a = nsubs1.get(0);
		SpaceBox<2,float> b2_a = nsubs2.get(0);
		SpaceBox<2,float> b3_a = nsubs3.get(0);

		SpaceBox<2,float> b1_b = Box<2,float>({0.0,0.0},{0.5,0.5});
		SpaceBox<2,float> b2_b = Box<2,float>({0.5,0.0},{1.0,0.5});
		SpaceBox<2,float> b3_b = Box<2,float>({0.0,0.5},{0.5,1.0});

		bool ret1 = b1_a == b1_b;
		bool ret2 = b2_a == b2_b;
		bool ret3 = b3_a == b3_b;

		BOOST_REQUIRE_EQUAL(ret1,true);
		BOOST_REQUIRE_EQUAL(ret2,true);
		BOOST_REQUIRE_EQUAL(ret3,true);
199
200
201
202
203
	}
}

BOOST_AUTO_TEST_CASE( nn_processor_box_periodic_test)
{
Pietro Incardona's avatar
Pietro Incardona committed
204
	// Vcluster
205
	Vcluster<> & v_cl = create_vcluster();
206

Pietro Incardona's avatar
Pietro Incardona committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
	/*!
	 *
	 * We test this situation
	 *
	 * \verbatim
		+-------+-------+
		|       |       |
		|   0   |   1   |
		|       |       |
		|       |       |
		+---------------+
		|       |       |
		|   2   |   3   |
		|       |       |
		|       |       |
		+-------+-------+
223

Pietro Incardona's avatar
Pietro Incardona committed
224
225
226
227
	 * \endverbatim
	 *
	 *
	 */
228

Pietro Incardona's avatar
Pietro Incardona committed
229
230
	if (v_cl.getProcessingUnits() != 4)
		return;
231

Pietro Incardona's avatar
Pietro Incardona committed
232
233
	Box<2,float> domain({0.0,0.0},{1.0,1.0});
	const size_t bc[2] = {PERIODIC,PERIODIC};
234

Pietro Incardona's avatar
Pietro Incardona committed
235
	Ghost<2,float> ghost(0.01);
236

Pietro Incardona's avatar
Pietro Incardona committed
237
238
	openfpm::vector<openfpm::vector<long unsigned int>> box_nn_processor;
	openfpm::vector<SpaceBox<2,float>> sub_domains;
239

Pietro Incardona's avatar
Pietro Incardona committed
240
	create_decomposition2x2(box_nn_processor,sub_domains);
241

Pietro Incardona's avatar
Pietro Incardona committed
242
	//////////////
243

Pietro Incardona's avatar
Pietro Incardona committed
244
245
246
247
	nn_prcs<2,float> nnp(v_cl);
	nnp.create(box_nn_processor, sub_domains);

	// check that nn_processor contain the correct boxes
248

Pietro Incardona's avatar
Pietro Incardona committed
249
250
251
	nnp.applyBC(domain,ghost,bc);

	if (v_cl.getProcessUnitID() == 0)
252
	{
Pietro Incardona's avatar
Pietro Incardona committed
253
254
255
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(1).size(),4ul);
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(2).size(),4ul);
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(3).size(),4ul);
256

Pietro Incardona's avatar
Pietro Incardona committed
257
		openfpm::vector<Box<2,float>> bv;
258

Pietro Incardona's avatar
Pietro Incardona committed
259
260
261
262
		bv.add(Box<2,float>({0.5,0},{1.0,0.5}));
		bv.add(Box<2,float>({-0.5,0.0},{0.0,0.5}));
		bv.add(Box<2,float>({0.5,1.0},{1.0,1.5}));
		bv.add(Box<2,float>({-0.5,1.0},{0.0,1.5}));
263

Pietro Incardona's avatar
Pietro Incardona committed
264
265
		bool ret = nnp.getNearSubdomains(1) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);
266

Pietro Incardona's avatar
Pietro Incardona committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
		bv.clear();

		bv.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
		bv.add(Box<2,float>({1.0,0.5},{1.5,1.0}));
		bv.add(Box<2,float>({0.0,-0.5},{0.5,0.0}));
		bv.add(Box<2,float>({1.0,-0.5},{1.5,0.0}));

		ret = nnp.getNearSubdomains(2) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);

		bv.clear();

		bv.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
		bv.add(Box<2,float>({-0.5,0.5},{0.0,1.0}));
		bv.add(Box<2,float>({0.5,-0.5},{1.0,0.0}));
		bv.add(Box<2,float>({-0.5,-0.5},{0.0,0.0}));

		ret = nnp.getNearSubdomains(3) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);
286
	}
Pietro Incardona's avatar
Pietro Incardona committed
287
288
	else if (v_cl.getProcessUnitID() == 1)
	{
Pietro Incardona's avatar
Pietro Incardona committed
289
290
291
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(0).size(),4ul);
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(2).size(),4ul);
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(3).size(),4ul);
Pietro Incardona's avatar
Pietro Incardona committed
292
293
294
295
296
297
298
299
300
301

		openfpm::vector<Box<2,float>> bv;

		bv.add(Box<2,float>({0.0,0},{0.5,0.5}));
		bv.add(Box<2,float>({1.0,0.0},{1.5,0.5}));
		bv.add(Box<2,float>({0.0,1.0},{0.5,1.5}));
		bv.add(Box<2,float>({1.0,1.0},{1.5,1.5}));

		bool ret = nnp.getNearSubdomains(0) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);
302

Pietro Incardona's avatar
Pietro Incardona committed
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
		bv.clear();

		bv.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
		bv.add(Box<2,float>({1.0,0.5},{1.5,1.0}));
		bv.add(Box<2,float>({0.0,-0.5},{0.5,0.0}));
		bv.add(Box<2,float>({1.0,-0.5},{1.5,0.0}));

		ret = nnp.getNearSubdomains(2) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);

		bv.clear();

		bv.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
		bv.add(Box<2,float>({-0.5,0.5},{0.0,1.0}));
		bv.add(Box<2,float>({0.5,-0.5},{1.0,0.0}));
		bv.add(Box<2,float>({-0.5,-0.5},{0.0,0.0}));

		ret = nnp.getNearSubdomains(3) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);
	}
	else if (v_cl.getProcessUnitID() == 2)
324
	{
Pietro Incardona's avatar
Pietro Incardona committed
325
326
327
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(0).size(),4ul);
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(1).size(),4ul);
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(3).size(),4ul);
328

Pietro Incardona's avatar
Pietro Incardona committed
329
		openfpm::vector<Box<2,float>> bv;
330

Pietro Incardona's avatar
Pietro Incardona committed
331
332
333
334
		bv.add(Box<2,float>({0.0,0},{0.5,0.5}));
		bv.add(Box<2,float>({1.0,0.0},{1.5,0.5}));
		bv.add(Box<2,float>({0.0,1.0},{0.5,1.5}));
		bv.add(Box<2,float>({1.0,1.0},{1.5,1.5}));
335

Pietro Incardona's avatar
Pietro Incardona committed
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
		bool ret = nnp.getNearSubdomains(0) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);

		bv.clear();

		bv.add(Box<2,float>({0.5,0},{1.0,0.5}));
		bv.add(Box<2,float>({-0.5,0.0},{0.0,0.5}));
		bv.add(Box<2,float>({0.5,1.0},{1.0,1.5}));
		bv.add(Box<2,float>({-0.5,1.0},{0.0,1.5}));

		ret = nnp.getNearSubdomains(1) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);

		bv.clear();

		bv.add(Box<2,float>({0.5,0.5},{1.0,1.0}));
		bv.add(Box<2,float>({-0.5,0.5},{0.0,1.0}));
		bv.add(Box<2,float>({0.5,-0.5},{1.0,0.0}));
		bv.add(Box<2,float>({-0.5,-0.5},{0.0,0.0}));

		ret = nnp.getNearSubdomains(3) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);
	}
	else if (v_cl.getProcessUnitID() == 3)
360
	{
Pietro Incardona's avatar
Pietro Incardona committed
361
362
363
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(0).size(),4ul);
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(1).size(),4ul);
		BOOST_REQUIRE_EQUAL(nnp.getNearSubdomains(2).size(),4ul);
Pietro Incardona's avatar
Pietro Incardona committed
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396

		openfpm::vector<Box<2,float>> bv;

		bv.add(Box<2,float>({0.0,0},{0.5,0.5}));
		bv.add(Box<2,float>({1.0,0.0},{1.5,0.5}));
		bv.add(Box<2,float>({0.0,1.0},{0.5,1.5}));
		bv.add(Box<2,float>({1.0,1.0},{1.5,1.5}));

		bool ret = nnp.getNearSubdomains(0) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);

		bv.clear();

		bv.add(Box<2,float>({0.5,0},{1.0,0.5}));
		bv.add(Box<2,float>({-0.5,0.0},{0.0,0.5}));
		bv.add(Box<2,float>({0.5,1.0},{1.0,1.5}));
		bv.add(Box<2,float>({-0.5,1.0},{0.0,1.5}));

		ret = nnp.getNearSubdomains(1) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);

		bv.clear();

		bv.add(Box<2,float>({0.0,0.5},{0.5,1.0}));
		bv.add(Box<2,float>({1.0,0.5},{1.5,1.0}));
		bv.add(Box<2,float>({0.0,-0.5},{0.5,0.0}));
		bv.add(Box<2,float>({1.0,-0.5},{1.5,0.0}));

/*		for (size_t i = 0 ; i < nnp.getNearSubdomains(2).size() ; i++)
		{
			Box<2,float> b = nnp.getNearSubdomains(2).get(i);
			std::cout << "BOX: " << b.toString() << std::endl;
		}*/
397

Pietro Incardona's avatar
Pietro Incardona committed
398
399
		ret = nnp.getNearSubdomains(2) == bv;
		BOOST_REQUIRE_EQUAL(ret,true);
400
	}
401
402
403
404
405
}

BOOST_AUTO_TEST_SUITE_END()

#endif /* SRC_DECOMPOSITION_NN_PROCESSOR_UNIT_TEST_HPP_ */