CartDecomposition_unit_test.cpp 17.4 KB
Newer Older
incardon's avatar
incardon committed
1
2
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
incardon's avatar
incardon committed
3

incardon's avatar
incardon committed
4
#include "Decomposition/CartDecomposition.hpp"
5
#include "util/mathutil.hpp"
incardon's avatar
incardon committed
6

7
BOOST_AUTO_TEST_SUITE (CartDecomposition_test)
incardon's avatar
incardon committed
8

9
#define SUB_UNIT_FACTOR 1024
incardon's avatar
incardon committed
10

11
void setComputationCosts(CartDecomposition<2, float> &dec, size_t n_v, Point<2, float> center, float radius, size_t weight_h, size_t weight_l)
incardon's avatar
incardon committed
12
{
tonynsyde's avatar
tonynsyde committed
13
14
15
16
	float radius2 = pow(radius, 2);
	float eq;

	// Position structure for the single vertex
17
	float pos[2];
tonynsyde's avatar
tonynsyde committed
18

19
	for (size_t i = 0; i < n_v; i++)
tonynsyde's avatar
tonynsyde committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
	{
		dec.getSubSubDomainPosition(i, pos);

		eq = pow((pos[0] - center.get(0)), 2) + pow((pos[1] - center.get(1)), 2);

		if (eq <= radius2)
			dec.setSubSubDomainComputationCost(i, weight_h);
		else
			dec.setSubSubDomainComputationCost(i, weight_l);
	}
}

void setComputationCosts3D(CartDecomposition<3, float> &dec, size_t n_v, Point<3, float> center, float radius, size_t weight_h, size_t weight_l)
{
34
	float radius2 = radius * radius;
tonynsyde's avatar
tonynsyde committed
35
36
37
38
39
	float eq;

	// Position structure for the single vertex
	float pos[3];

40
	for (size_t i = 0; i < n_v; i++)
tonynsyde's avatar
tonynsyde committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	{
		dec.getSubSubDomainPosition(i, pos);

		eq = pow((pos[0] - center.get(0)), 2) + pow((pos[1] - center.get(1)), 2) + pow((pos[2] - center.get(2)), 2);

		if (eq <= radius2)
			dec.setSubSubDomainComputationCost(i, weight_h);
		else
			dec.setSubSubDomainComputationCost(i, weight_l);
	}
}



55
BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test)
Pietro Incardona's avatar
Pietro Incardona committed
56
57
{
	// Vcluster
58
	Vcluster<> & vcl = create_vcluster();
Pietro Incardona's avatar
Pietro Incardona committed
59

60
	CartDecomposition<3, float> dec(vcl);
Pietro Incardona's avatar
Pietro Incardona committed
61
62

	// Physical domain
63
	Box<3, float> box( { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 });
Pietro Incardona's avatar
Pietro Incardona committed
64
65
66
67
68
69
70
71
	size_t div[3];

	// Get the number of processor and calculate the number of sub-domain
	// for each processor (SUB_UNIT_FACTOR=64)
	size_t n_proc = vcl.getProcessingUnits();
	size_t n_sub = n_proc * SUB_UNIT_FACTOR;

	// Set the number of sub-domains on each dimension (in a scalable way)
72
73
	for (int i = 0; i < 3; i++)
	{	div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
Pietro Incardona's avatar
Pietro Incardona committed
74
75

	// Define ghost
76
	Ghost<3, float> g(0.01);
Pietro Incardona's avatar
Pietro Incardona committed
77
78

	// Boundary conditions
79
	size_t bc[] = { NON_PERIODIC, NON_PERIODIC, NON_PERIODIC };
Pietro Incardona's avatar
Pietro Incardona committed
80

incardon's avatar
incardon committed
81
	// Decompose
Pietro Incardona's avatar
Pietro Incardona committed
82
	dec.setParameters(div,box,bc,g);
Pietro Incardona's avatar
Pietro Incardona committed
83
	dec.decompose();
incardon's avatar
incardon committed
84

85
	// For each calculated ghost box
86
	for (size_t i = 0; i < dec.getNIGhostBox(); i++)
87
88
89
90
91
92
93
94
	{
		SpaceBox<3,float> b = dec.getIGhostBox(i);
		size_t proc = dec.getIGhostBoxProcessor(i);

		// sample one point inside the box
		Point<3,float> p = b.rnd();

		// Check that ghost_processorsID return that processor number
incardon's avatar
incardon committed
95
		const openfpm::vector<size_t> & pr = dec.ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
96
97
98

		bool found = false;

99
		for (size_t j = 0; j < pr.size(); j++)
100
101
		{
			if (pr.get(j) == proc)
102
			{	found = true; break;}
103
104
105
106
		}

		if (found == false)
		{
107
			const openfpm::vector<size_t> pr2 = dec.ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
108
109
110
111
		}

		BOOST_REQUIRE_EQUAL(found,true);
	}
incardon's avatar
incardon committed
112
113

	// Check the consistency
114

incardon's avatar
incardon committed
115
116
	bool val = dec.check_consistency();
	BOOST_REQUIRE_EQUAL(val,true);
117
118

	// We duplicate the decomposition
119
	CartDecomposition<3, float> dec2 = dec.duplicate();
incardon's avatar
incardon committed
120
121
	dec2.check_consistency();

122
	// check that dec and dec2 contain the same information
incardon's avatar
incardon committed
123
124
	bool ret = dec.is_equal(dec2);

incardon's avatar
incardon committed
125
	// We check if the two decomposition are equal
incardon's avatar
incardon committed
126
	BOOST_REQUIRE_EQUAL(ret,true);
incardon's avatar
incardon committed
127

128
129
130
	// We duplicate the decomposition redefining the ghost

	// Define ghost
131
	Ghost<3, float> g3(0.005);
132

133
	// We duplicate the decomposition redefining the ghost
134
	CartDecomposition<3, float> dec3 = dec.duplicate(g3);
incardon's avatar
incardon committed
135
136
137
138

	ret = dec3.check_consistency();
	BOOST_REQUIRE_EQUAL(ret,true);

139
	// Check that dec3 is equal to dec2 with the exception of the ghost part
incardon's avatar
incardon committed
140
141
	ret = dec3.is_equal_ng(dec2);
	BOOST_REQUIRE_EQUAL(ret,true);
incardon's avatar
incardon committed
142
143
}

144
145
BOOST_AUTO_TEST_CASE( CartDecomposition_periodic_test)
{
146
	// Vcluster
147
	Vcluster<> & vcl = create_vcluster();
148

149
	//! [Create CartDecomposition]
150
	CartDecomposition<3, float> dec(vcl);
151
152

	// Physical domain
153
	Box<3, float> box( { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 });
154
155
156
157
158
159
160
	size_t div[3];

	// Get the number of processor and calculate the number of sub-domain
	// for each processor (SUB_UNIT_FACTOR=64)
	size_t n_proc = vcl.getProcessingUnits();
	size_t n_sub = n_proc * SUB_UNIT_FACTOR;

161
	// Set the number of sub-domains on each dimension (in a scalable way)
162
163
	for (int i = 0; i < 3; i++)
	{	div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
164

165
	// Define ghost
166
	Ghost<3, float> g(0.01);
167
168

	// Boundary conditions
169
	size_t bc[] = { PERIODIC, PERIODIC, PERIODIC };
170
171
172

	// Decompose
	dec.setParameters(div,box,bc,g);
Pietro Incardona's avatar
Pietro Incardona committed
173
	dec.decompose();
174

175
176
177
	//! [Create CartDecomposition]

	// For each calculated ghost box
178
	for (size_t i = 0; i < dec.getNIGhostBox(); i++)
179
180
181
	{
		SpaceBox<3,float> b = dec.getIGhostBox(i);
		size_t proc = dec.getIGhostBoxProcessor(i);
182

183
184
		// sample one point inside the box
		Point<3,float> p = b.rnd();
185

186
		// Check that ghost_processorsID return that processor number
187
		const openfpm::vector<size_t> & pr = dec.ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
188

189
		bool found = false;
190

191
		for (size_t j = 0; j < pr.size(); j++)
192
193
		{
			if (pr.get(j) == proc)
194
			{	found = true; break;}
195
		}
196

197
		if (found == false)
198
		{
199
			const openfpm::vector<size_t> pr2 = dec.ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
200
201
		}

202
203
		BOOST_REQUIRE_EQUAL(found,true);
	}
204

205
206
207
	// Check the consistency
	bool val = dec.check_consistency();
	BOOST_REQUIRE_EQUAL(val,true);
208

209
	// We duplicate the decomposition
210
	CartDecomposition<3, float> dec2 = dec.duplicate();
211
	dec2.check_consistency();
212

213
	bool ret = dec.is_equal(dec2);
214

215
216
	// We check if the two decomposition are equal
	BOOST_REQUIRE_EQUAL(ret,true);
217

218
	// check that dec and dec2 contain the same information
219

220
	// We duplicate the decomposition redefining the ghost
221

222
	// Define ghost
223
	Ghost<3, float> g3(0.005);
224

225
	// We duplicate the decomposition refefining the ghost
226
	CartDecomposition<3, float> dec3 = dec.duplicate(g3);
227

228
229
	ret = dec3.check_consistency();
	BOOST_REQUIRE_EQUAL(ret,true);
230

231
232
233
	// Check that g3 is equal to dec2 with the exception of the ghost part
	ret = dec3.is_equal_ng(dec2);
	BOOST_REQUIRE_EQUAL(ret,true);
234
235
}

Pietro Incardona's avatar
Pietro Incardona committed
236
237
238
239
240
241

////////////////////////// CartDecomposition extended

BOOST_AUTO_TEST_CASE( CartDecomposition_ext_non_periodic_test)
{
	// Vcluster
242
	Vcluster<> & vcl = create_vcluster();
Pietro Incardona's avatar
Pietro Incardona committed
243
244
245
246
247
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

	CartDecomposition<3,float> dec(vcl);

	// Physical domain
	Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
	size_t div[3];

	// Get the number of processor and calculate the number of sub-domain
	// for each processor (SUB_UNIT_FACTOR=64)
	size_t n_proc = vcl.getProcessingUnits();
	size_t n_sub = n_proc * SUB_UNIT_FACTOR;

	// Set the number of sub-domains on each dimension (in a scalable way)
	for (int i = 0 ; i < 3 ; i++)
	{div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}

	// Define ghost
	Ghost<3,float> g(0.01);

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

	// Decompose
	dec.setParameters(div,box,bc,g);
	dec.decompose();

	//! [Extend CartDecomposition]

	Box<3,float> box_ext({-0.1,-0.1,-0.1},{1.1,1.1,1.1});

	// Use the old decomposition to extend on a bigger domain
274
275
276
	CartDecomposition_ext<3,float> dec_ext(vcl);

	dec_ext.setParameters(dec,g,box_ext);
Pietro Incardona's avatar
Pietro Incardona committed
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294

	//! [Extend CartDecomposition]

	// Check the new decomposition is fully contained in the new one, and there are
	// box not fully contained i the old box

	BOOST_REQUIRE_EQUAL(dec_ext.getNSubDomain(),dec.getNSubDomain());

	double volume = 0.0;
	for (size_t i = 0; i < dec_ext.getNSubDomain() ; i++)
	{
		volume += dec_ext.getSubDomain(i).getVolume();
		BOOST_REQUIRE_EQUAL(dec_ext.getSubDomain(i).isContained(dec.getSubDomain(i)),true);
	}

	vcl.sum(volume);
	vcl.execute();

295
	BOOST_REQUIRE_CLOSE(volume,1.728,0.0001);
Pietro Incardona's avatar
Pietro Incardona committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316

	BOOST_REQUIRE_EQUAL(dec.getNNProcessors(),dec_ext.getNNProcessors());

	double volume_g = 0.0;
	double volume_ge = 0.0;
	for (size_t p = 0; p < dec.getNNProcessors(); p++)
	{
		BOOST_REQUIRE_EQUAL(dec.getProcessorNEGhost(p),dec_ext.getProcessorNEGhost(p));
		for (size_t i = 0; i < dec.getProcessorNEGhost(p); i++)
		{
			volume_g += dec.getProcessorEGhostBox(p,i).getVolume();
			volume_ge += dec_ext.getProcessorEGhostBox(p,i).getVolume();

			BOOST_REQUIRE_EQUAL(dec_ext.getProcessorEGhostBox(p,i).isContained(dec_ext.getProcessorEGhostBox(p,i)),true);
		}
	}

	vcl.sum(volume_g);
	vcl.sum(volume_ge);
	vcl.execute();

Pietro Incardona's avatar
Pietro Incardona committed
317
318
319
320
	if (vcl.getProcessingUnits() > 1)
	{
		BOOST_REQUIRE(volume_ge > volume_g*1.05);
	}
Pietro Incardona's avatar
Pietro Incardona committed
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337

	volume_g = 0.0;
	volume_ge = 0.0;
	for (size_t p = 0; p < dec.getNNProcessors(); p++)
	{
		for (size_t i = 0; i< dec.getProcessorNIGhost(p); i++)
		{
			volume_g += dec.getProcessorIGhostBox(p,i).getVolume();
			volume_ge += dec_ext.getProcessorIGhostBox(p,i).getVolume();
			BOOST_REQUIRE_EQUAL(dec_ext.getProcessorIGhostBox(p,i).isContained(dec.getProcessorIGhostBox(p,i)),true);
		}
	}

	vcl.sum(volume_g);
	vcl.sum(volume_ge);
	vcl.execute();

Pietro Incardona's avatar
Pietro Incardona committed
338
339
340
341
	if (vcl.getProcessingUnits() > 1)
	{
		BOOST_REQUIRE(volume_ge > volume_g*1.05);
	}
Pietro Incardona's avatar
Pietro Incardona committed
342
343
}

344
345
346
BOOST_AUTO_TEST_CASE( CartDecomposition_check_cross_consistency_between_proc_idbc_and_ghost )
{
	// Vcluster
347
	Vcluster<> & vcl = create_vcluster();
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375

	if (vcl.size() != 3)
	{return;}

	CartDecomposition<3, double> dec(vcl);

	size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};

	// Physical domain
	Box<3, double> box( { -0.01, -0.01, 0.0 }, { 0.01, 0.01, 0.003 });

	Ghost<3,double> g(0.0015);

	dec.setGoodParameters(box, bc, g, 512);

	dec.decompose();

	// Now we check the point

	Point<3,double> p1({-0.0067499999999999999237,-0.0012499999999999995923,0.001250000000000000026});
	Point<3,double> p2({-0.0067499999999999999237,-0.0012499999999999993755,0.001250000000000000026});

	size_t proc1 = dec.processorIDBC(p1);
	size_t proc2 = dec.processorIDBC(p2);

	const openfpm::vector<std::pair<size_t, size_t>> & vp_id1 = dec.template ghost_processorID_pair<typename CartDecomposition<3, double>::lc_processor_id, typename CartDecomposition<3, double>::shift_id>(p1, UNIQUE);
	const openfpm::vector<std::pair<size_t, size_t>> & vp_id2 = dec.template ghost_processorID_pair<typename CartDecomposition<3, double>::lc_processor_id, typename CartDecomposition<3, double>::shift_id>(p2, UNIQUE);

incardon's avatar
incardon committed
376
	if (proc1 != proc2)
377
	{
incardon's avatar
incardon committed
378
379
380
381
382
		if (vcl.rank() == proc2)
		{
			BOOST_REQUIRE(vp_id2.size() != 0);
			BOOST_REQUIRE(vp_id1.size() == 0);
		}
383

incardon's avatar
incardon committed
384
385
386
387
388
		if (vcl.rank() == proc1)
		{
			BOOST_REQUIRE(vp_id2.size() == 0 );
			BOOST_REQUIRE(vp_id1.size() != 0 );
		}
389
390
	}
}
Pietro Incardona's avatar
Pietro Incardona committed
391

392
393
394
BOOST_AUTO_TEST_CASE( CartDecomposition_check_cross_consistency_between_proc_idbc_and_ghost2 )
{
	// Vcluster
395
	Vcluster<> & vcl = create_vcluster();
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

	CartDecomposition<3, double> dec(vcl);

	size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};

	// Physical domain
	Box<3, double> box( { -0.01, -0.01, 0.0 }, { 0.01, 0.01, 0.003 });

	Ghost<3,double> g(0.0015);

	dec.setGoodParameters(box, bc, g, 512);

	dec.decompose();

	// Now we check the point

	for (size_t j = 0 ; j < 3 ; j++ )
	{
		for (size_t i = 0 ; i < dec.getNSubDomain() ; i++)
		{
			Point<3,double> p1;
			Point<3,double> p2;

			p1.get(0) = SpaceBox<3,double>(dec.getSubDomains().get(i)).getLow(0);
			p1.get(1) = SpaceBox<3,double>(dec.getSubDomains().get(i)).getLow(1);
			p1.get(2) = SpaceBox<3,double>(dec.getSubDomains().get(i)).getLow(2);

			p2 = p1;

			p2.get(j) = std::nextafter(SpaceBox<3,double>(dec.getSubDomains().get(i)).getLow(j),-1.0);

			size_t proc1 = dec.processorIDBC(p1);
			size_t proc2 = dec.processorIDBC(p2);

			BOOST_REQUIRE(proc1 < vcl.size());
			BOOST_REQUIRE(proc2 < vcl.size());

			const openfpm::vector<std::pair<size_t, size_t>> & vp_id1 = dec.template ghost_processorID_pair<typename CartDecomposition<3, double>::lc_processor_id, typename CartDecomposition<3, double>::shift_id>(p1, UNIQUE);
			const openfpm::vector<std::pair<size_t, size_t>> & vp_id2 = dec.template ghost_processorID_pair<typename CartDecomposition<3, double>::lc_processor_id, typename CartDecomposition<3, double>::shift_id>(p2, UNIQUE);

			if (proc1 != proc2)
			{
				if (vcl.rank() == proc2)
				{
					BOOST_REQUIRE(vp_id2.size() != 0);
					BOOST_REQUIRE(vp_id1.size() == 0);
				}

				if (vcl.rank() == proc1)
				{
					BOOST_REQUIRE(vp_id2.size() == 0 );
					BOOST_REQUIRE(vp_id1.size() != 0 );
				}
			}


			p1.get(0) = std::nextafter(SpaceBox<3,double>(dec.getSubDomains().get(i)).getHigh(0),SpaceBox<3,double>(dec.getSubDomains().get(i)).getLow(0));
			p1.get(1) = std::nextafter(SpaceBox<3,double>(dec.getSubDomains().get(i)).getHigh(1),SpaceBox<3,double>(dec.getSubDomains().get(i)).getLow(1));
			p1.get(2) = std::nextafter(SpaceBox<3,double>(dec.getSubDomains().get(i)).getHigh(2),SpaceBox<3,double>(dec.getSubDomains().get(i)).getLow(2));

			p2 = p1;

			p2.get(j) = std::nextafter(SpaceBox<3,double>(dec.getSubDomains().get(i)).getHigh(j),1.0);

			proc1 = dec.processorIDBC(p1);
			proc2 = dec.processorIDBC(p2);

			BOOST_REQUIRE(proc1 < vcl.size());
			BOOST_REQUIRE(proc2 < vcl.size());

			const openfpm::vector<std::pair<size_t, size_t>> & vp_id3 = dec.template ghost_processorID_pair<typename CartDecomposition<3, double>::lc_processor_id, typename CartDecomposition<3, double>::shift_id>(p1, UNIQUE);
			const openfpm::vector<std::pair<size_t, size_t>> & vp_id4 = dec.template ghost_processorID_pair<typename CartDecomposition<3, double>::lc_processor_id, typename CartDecomposition<3, double>::shift_id>(p2, UNIQUE);

			if (proc1 != proc2)
			{
				if (vcl.rank() == proc2)
				{
					BOOST_REQUIRE(vp_id4.size() != 0);
					BOOST_REQUIRE(vp_id3.size() == 0);
				}

				if (vcl.rank() == proc1)
				{
					BOOST_REQUIRE(vp_id4.size() == 0 );
					BOOST_REQUIRE(vp_id3.size() != 0 );
				}
			}

		}
	}
}
incardon's avatar
incardon committed
487

488
489
490
BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test_dist_grid)
{
	// Vcluster
491
	Vcluster<> & vcl = create_vcluster();
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

	CartDecomposition<3, float> dec(vcl);

	// Physical domain
	Box<3, float> box( { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 });
	size_t div[3];
	size_t div_sub[3];

	// Get the number of processor and calculate the number of sub-domain
	// for each processor (SUB_UNIT_FACTOR=64)
	size_t n_proc = vcl.getProcessingUnits();
	size_t n_sub = n_proc * SUB_UNIT_FACTOR*4*4*4;

	// Set the number of sub-domains on each dimension (in a scalable way)
	for (int i = 0; i < 3; i++)
	{div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}

	// create a sub_distribution grid
	for (int i = 0; i < 3; i++)
	{div_sub[i] = div[i] / 4;}

	grid_sm<3,void> gsub(div_sub);

	// Define ghost
	Ghost<3, float> g(0.01);

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

	// Decompose
	dec.setParameters(div,box,bc,g,gsub);
	dec.decompose();
	dec.write("Test_sub_dist2");

	// For each calculated ghost box
	for (size_t i = 0; i < dec.getNIGhostBox(); i++)
	{
		SpaceBox<3,float> b = dec.getIGhostBox(i);
		size_t proc = dec.getIGhostBoxProcessor(i);

		// sample one point inside the box
		Point<3,float> p = b.rnd();

		// Check that ghost_processorsID return that processor number
		const openfpm::vector<size_t> & pr = dec.ghost_processorID<CartDecomposition<3,float>::processor_id>(p);

		bool found = false;

		for (size_t j = 0; j < pr.size(); j++)
		{
			if (pr.get(j) == proc)
			{	found = true; break;}
		}

		if (found == false)
		{
			const openfpm::vector<size_t> pr2 = dec.ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
		}

		BOOST_REQUIRE_EQUAL(found,true);
	}

	// Check the consistency

	bool val = dec.check_consistency();
	BOOST_REQUIRE_EQUAL(val,true);
}

incardon's avatar
incardon committed
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
BOOST_AUTO_TEST_CASE( CartDecomposition_nsub_algo_functions_test)
{
	size_t n_sub = 64*2;
	size_t div[3];

	nsub_to_div2<3>(div,n_sub,3);

	BOOST_REQUIRE_EQUAL(div[0],8ul);
	BOOST_REQUIRE_EQUAL(div[1],8ul);
	BOOST_REQUIRE_EQUAL(div[2],8ul);

	nsub_to_div2<3>(div,n_sub,2);

	BOOST_REQUIRE_EQUAL(div[0],16ul);
	BOOST_REQUIRE_EQUAL(div[1],16ul);
	BOOST_REQUIRE_EQUAL(div[2],1ul);

	nsub_to_div2<3>(div,n_sub,1);

	BOOST_REQUIRE_EQUAL(div[0],128ul);
	BOOST_REQUIRE_EQUAL(div[1],1ul);
	BOOST_REQUIRE_EQUAL(div[2],1ul);

	n_sub = 64*3;
	nsub_to_div<3>(div,n_sub,3);

	BOOST_REQUIRE_EQUAL(div[0],5ul);
	BOOST_REQUIRE_EQUAL(div[1],5ul);
	BOOST_REQUIRE_EQUAL(div[2],5ul);

	nsub_to_div<3>(div,n_sub,2);

	BOOST_REQUIRE_EQUAL(div[0],13ul);
	BOOST_REQUIRE_EQUAL(div[1],13ul);
	BOOST_REQUIRE_EQUAL(div[2],1ul);

	nsub_to_div<3>(div,n_sub,1);

	BOOST_REQUIRE_EQUAL(div[0],192ul);
	BOOST_REQUIRE_EQUAL(div[1],1ul);
	BOOST_REQUIRE_EQUAL(div[2],1ul);

	// Test high dimension cart decomposition subdivision

	Box<50,double> domain;
	size_t bc[50];
	Ghost<50,double> ghost(0.01);

	for(size_t i = 0 ; i < 50 ; i++)
	{
		domain.setLow(i,0.0);
		domain.setHigh(i,1.0);
		bc[i] = NON_PERIODIC;
	}

	CartDecomposition<50,double> dec(create_vcluster());

	dec.setGoodParameters(domain,bc,ghost,64);

	size_t div2[50];
	dec.getParameters(div2);

	auto & v_cl = create_vcluster();
	if (v_cl.size() == 1)
	{
		for (size_t i = 0 ; i < 50 ; i++)
		{
			if (i < 6)
			{BOOST_REQUIRE_EQUAL(div2[i],2ul);}
			else
			{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
		}
	}

	if (v_cl.size() == 2)
	{
		for (size_t i = 0 ; i < 50 ; i++)
		{
			if (i < 7)
			{BOOST_REQUIRE_EQUAL(div2[i],2ul);}
			else
			{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
		}
	}

	if (v_cl.size() == 3)
	{
		for (size_t i = 0 ; i < 50 ; i++)
		{
			if (i < 2)
			{BOOST_REQUIRE_EQUAL(div2[i],13ul);}
			else
			{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
		}
	}

	if (v_cl.size() == 4)
	{
		for (size_t i = 0 ; i < 50 ; i++)
		{
			if (i < 8)
			{BOOST_REQUIRE_EQUAL(div2[i],2ul);}
			else
			{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
		}
	}

	if (v_cl.size() == 5)
	{
		for (size_t i = 0 ; i < 50 ; i++)
		{
			if (i < 8)
			{BOOST_REQUIRE_EQUAL(div2[i],2ul);}
			else
			{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
		}
	}

	if (v_cl.size() == 6)
	{
		for (size_t i = 0 ; i < 50 ; i++)
		{
			if (i < 3)
			{BOOST_REQUIRE_EQUAL(div2[i],7ul);}
			else
			{BOOST_REQUIRE_EQUAL(div2[i],1ul);}
		}
	}
}

incardon's avatar
incardon committed
690
691
BOOST_AUTO_TEST_SUITE_END()