vector_dist_complex_prp_unit_test.hpp 7.68 KB
Newer Older
incardon's avatar
incardon 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_complex_prp_unit_test.hpp
 *
 *  Created on: Sep 18, 2016
 *      Author: i-bird
 */

#ifndef SRC_VECTOR_VECTOR_DIST_COMPLEX_PRP_UNIT_TEST_HPP_
#define SRC_VECTOR_VECTOR_DIST_COMPLEX_PRP_UNIT_TEST_HPP_


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

	if (v_cl.getProcessingUnits() > 48)
		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 = 24288 * v_cl.getProcessingUnits();
#else
incardon's avatar
incardon committed
28
    long int k = 124288 * v_cl.getProcessingUnits();
incardon's avatar
incardon committed
29
#endif
incardon's avatar
incardon 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

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

	print_test_v( "Testing 3D vector full complex prp vector k<=",k);

	// 3D test
	for ( ; k >= 2 ; k-= decrement(k,big_step) )
	{
		BOOST_TEST_CHECKPOINT( "Testing 3D full complex prp vector k=" << k );

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

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

		// factor
		float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);

		// ghost
		Ghost<3,float> ghost(0.05 / factor);

		// ghost2 (a little bigger because of round off error)
		Ghost<3,float> ghost2(0.05001 / factor);

		// Distributed vector
		vector_dist<3,float, aggregate<openfpm::vector<float>,grid_cpu<3,aggregate<double,double[3]>> > > 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);

			// initalize vector property and grid

incardon's avatar
incardon committed
70
71
72
			vd.getProp<0>(key).add(vd.getPos(key)[0]);
			vd.getProp<0>(key).add(vd.getPos(key)[1]);
			vd.getProp<0>(key).add(vd.getPos(key)[2]);
incardon's avatar
incardon committed
73

incardon's avatar
incardon committed
74
75
76
			vd.getProp<0>(key).add(vd.getPos(key)[0]+vd.getPos(key)[1]);
			vd.getProp<0>(key).add(vd.getPos(key)[1]+vd.getPos(key)[2]);
			vd.getProp<0>(key).add(vd.getPos(key)[0]+vd.getPos(key)[2]);
incardon's avatar
incardon committed
77
78
79

			// Grid
			size_t sz[] = {3,3,3};
incardon's avatar
incardon committed
80
			vd.getProp<1>(key).resize(sz);
incardon's avatar
incardon committed
81

incardon's avatar
incardon committed
82
83
84
			vd.getProp<1>(key).get<0>({0,0,0}) = vd.getPos(key)[0];
			vd.getProp<1>(key).get<0>({0,0,1}) = vd.getPos(key)[1];
			vd.getProp<1>(key).get<0>({0,0,2}) = vd.getPos(key)[2];
incardon's avatar
incardon committed
85

incardon's avatar
incardon committed
86
87
88
			vd.getProp<1>(key).get<0>({0,1,0}) = 2.0*vd.getPos(key)[0];
			vd.getProp<1>(key).get<0>({0,1,1}) = 2.0*vd.getPos(key)[1];
			vd.getProp<1>(key).get<0>({0,1,2}) = 2.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
89

incardon's avatar
incardon committed
90
91
92
			vd.getProp<1>(key).get<0>({0,2,0}) = 3.0*vd.getPos(key)[0];
			vd.getProp<1>(key).get<0>({0,2,1}) = 3.0*vd.getPos(key)[1];
			vd.getProp<1>(key).get<0>({0,2,2}) = 3.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
93

incardon's avatar
incardon committed
94
95
96
			vd.getProp<1>(key).get<0>({1,0,0}) = 4.0*vd.getPos(key)[0];
			vd.getProp<1>(key).get<0>({1,0,1}) = 4.0*vd.getPos(key)[1];
			vd.getProp<1>(key).get<0>({1,0,2}) = 4.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
97

incardon's avatar
incardon committed
98
99
100
			vd.getProp<1>(key).get<0>({1,1,0}) = 5.0*vd.getPos(key)[0];
			vd.getProp<1>(key).get<0>({1,1,1}) = 5.0*vd.getPos(key)[1];
			vd.getProp<1>(key).get<0>({1,1,2}) = 5.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
101

incardon's avatar
incardon committed
102
103
104
			vd.getProp<1>(key).get<0>({1,2,0}) = 6.0*vd.getPos(key)[0];
			vd.getProp<1>(key).get<0>({1,2,1}) = 6.0*vd.getPos(key)[1];
			vd.getProp<1>(key).get<0>({1,2,2}) = 6.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
105

incardon's avatar
incardon committed
106
107
108
			vd.getProp<1>(key).get<0>({2,0,0}) = 7.0*vd.getPos(key)[0];
			vd.getProp<1>(key).get<0>({2,0,1}) = 7.0*vd.getPos(key)[1];
			vd.getProp<1>(key).get<0>({2,0,2}) = 7.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
109

incardon's avatar
incardon committed
110
111
112
			vd.getProp<1>(key).get<0>({2,1,0}) = 8.0*vd.getPos(key)[0];
			vd.getProp<1>(key).get<0>({2,1,1}) = 8.0*vd.getPos(key)[1];
			vd.getProp<1>(key).get<0>({2,1,2}) = 8.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
113

incardon's avatar
incardon committed
114
115
116
			vd.getProp<1>(key).get<0>({2,2,0}) = 9.0*vd.getPos(key)[0];
			vd.getProp<1>(key).get<0>({2,2,1}) = 9.0*vd.getPos(key)[1];
			vd.getProp<1>(key).get<0>({2,2,2}) = 9.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
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

			++it;
		}

		vd.map();

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

		// Domain + ghost
		Box<3,float> dom_ext = box;
		dom_ext.enlarge(ghost2);

		// Iterate on all particles domain + ghost
		size_t l_cnt = 0;
		size_t nl_cnt = 0;
		size_t n_out = 0;

		auto it2 = vd.getIterator();
		count_local_n_local<3,vector_dist<3,float, aggregate<openfpm::vector<float>,grid_cpu<3,aggregate<double,double[3]>>>>  >(vd,it2,bc,box,dom_ext,l_cnt,nl_cnt,n_out);

		// No particles should be out of domain + ghost
		BOOST_REQUIRE_EQUAL(n_out,0ul);

		// Ghost must populated because we synchronized them
		if (k > 524288)
		{
			BOOST_REQUIRE(nl_cnt != 0);
			BOOST_REQUIRE(l_cnt > nl_cnt);
		}

		// Sum all the particles inside the domain
		v_cl.sum(l_cnt);
		v_cl.execute();
		BOOST_REQUIRE_EQUAL(l_cnt,(size_t)k);

		l_cnt = 0;
		nl_cnt = 0;

		// Iterate only on the ghost particles
		auto itg = vd.getGhostIterator();
		count_local_n_local<3, vector_dist<3,float, aggregate<openfpm::vector<float>,grid_cpu<3,aggregate<double,double[3]>>>> >(vd,itg,bc,box,dom_ext,l_cnt,nl_cnt,n_out);

		// No particle on the ghost must be inside the domain
		BOOST_REQUIRE_EQUAL(l_cnt,0ul);

		// Ghost must be populated
		if (k > 524288)
		{
			BOOST_REQUIRE(nl_cnt != 0);
		}

		// check that the particles contain the correct information

		bool ret = true;
		auto it3 = vd.getDomainAndGhostIterator();

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

incardon's avatar
incardon committed
178
			ret &= vd.getProp<0>(key).size() == 6;
incardon's avatar
incardon committed
179

incardon's avatar
incardon committed
180
181
182
			ret &= vd.getProp<0>(key).get(0) == vd.getPos(key)[0];
			ret &= vd.getProp<0>(key).get(1) == vd.getPos(key)[1];
			ret &= vd.getProp<0>(key).get(2) == vd.getPos(key)[2];
incardon's avatar
incardon committed
183

incardon's avatar
incardon committed
184
185
186
			ret &= vd.getProp<0>(key).get(3) == vd.getPos(key)[0]+vd.getPos(key)[1];
			ret &= vd.getProp<0>(key).get(4) == vd.getPos(key)[1]+vd.getPos(key)[2];
			ret &= vd.getProp<0>(key).get(5) == vd.getPos(key)[0]+vd.getPos(key)[2];
incardon's avatar
incardon committed
187

incardon's avatar
incardon committed
188
//			BOOST_REQUIRE_EQUAL(vd.getProp<0>(key).get(0),vd.getPos(key)[0]);
incardon's avatar
incardon committed
189

incardon's avatar
incardon committed
190
191
192
193
			ret &= vd.getProp<1>(key).size() == 3*3*3;
			ret &= vd.getProp<1>(key).get<0>({0,0,0}) == vd.getPos(key)[0];
			ret &= vd.getProp<1>(key).get<0>({0,0,1}) == vd.getPos(key)[1];
			ret &= vd.getProp<1>(key).get<0>({0,0,2}) == vd.getPos(key)[2];
incardon's avatar
incardon committed
194

incardon's avatar
incardon committed
195
196
197
			ret &= vd.getProp<1>(key).get<0>({0,1,0}) == 2.0*vd.getPos(key)[0];
			ret &= vd.getProp<1>(key).get<0>({0,1,1}) == 2.0*vd.getPos(key)[1];
			ret &= vd.getProp<1>(key).get<0>({0,1,2}) == 2.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
198

incardon's avatar
incardon committed
199
200
201
			ret &= vd.getProp<1>(key).get<0>({0,2,0}) == 3.0*vd.getPos(key)[0];
			ret &= vd.getProp<1>(key).get<0>({0,2,1}) == 3.0*vd.getPos(key)[1];
			ret &= vd.getProp<1>(key).get<0>({0,2,2}) == 3.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
202

incardon's avatar
incardon committed
203
204
205
			ret &= vd.getProp<1>(key).get<0>({1,0,0}) == 4.0*vd.getPos(key)[0];
			ret &= vd.getProp<1>(key).get<0>({1,0,1}) == 4.0*vd.getPos(key)[1];
			ret &= vd.getProp<1>(key).get<0>({1,0,2}) == 4.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
206

incardon's avatar
incardon committed
207
208
209
			ret &= vd.getProp<1>(key).get<0>({1,1,0}) == 5.0*vd.getPos(key)[0];
			ret &= vd.getProp<1>(key).get<0>({1,1,1}) == 5.0*vd.getPos(key)[1];
			ret &= vd.getProp<1>(key).get<0>({1,1,2}) == 5.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
210

incardon's avatar
incardon committed
211
212
213
			ret &= vd.getProp<1>(key).get<0>({1,2,0}) == 6.0*vd.getPos(key)[0];
			ret &= vd.getProp<1>(key).get<0>({1,2,1}) == 6.0*vd.getPos(key)[1];
			ret &= vd.getProp<1>(key).get<0>({1,2,2}) == 6.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
214

incardon's avatar
incardon committed
215
216
217
			ret &= vd.getProp<1>(key).get<0>({2,0,0}) == 7.0*vd.getPos(key)[0];
			ret &= vd.getProp<1>(key).get<0>({2,0,1}) == 7.0*vd.getPos(key)[1];
			ret &= vd.getProp<1>(key).get<0>({2,0,2}) == 7.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
218

incardon's avatar
incardon committed
219
220
221
			ret &= vd.getProp<1>(key).get<0>({2,1,0}) == 8.0*vd.getPos(key)[0];
			ret &= vd.getProp<1>(key).get<0>({2,1,1}) == 8.0*vd.getPos(key)[1];
			ret &= vd.getProp<1>(key).get<0>({2,1,2}) == 8.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
222

incardon's avatar
incardon committed
223
224
225
			ret &= vd.getProp<1>(key).get<0>({2,2,0}) == 9.0*vd.getPos(key)[0];
			ret &= vd.getProp<1>(key).get<0>({2,2,1}) == 9.0*vd.getPos(key)[1];
			ret &= vd.getProp<1>(key).get<0>({2,2,2}) == 9.0*vd.getPos(key)[2];
incardon's avatar
incardon committed
226
227
228
229
230
231
232
233
234
235

			++it3;
		}

		BOOST_REQUIRE_EQUAL(ret,true);
	}
}


#endif /* SRC_VECTOR_VECTOR_DIST_COMPLEX_PRP_UNIT_TEST_HPP_ */