OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_dist_id_unit_test_unb_ghost.hpp
1/*
2 * grid_dist_id_unit_test_unb_ghost.hpp
3 *
4 * Created on: Jul 11, 2016
5 * Author: i-bird
6 */
7
8void Test3D_unb_ghost(const Box<3,float> & domain, long int k)
9{
10 long int big_step = k / 30;
11 big_step = (big_step == 0)?1:big_step;
12 long int small_step = 21;
13
14 if (create_vcluster().getProcessingUnits() > 48)
15 return;
16
17 print_test_v( "Testing 3D grid unbound ghost k<=",k);
18
19 // 3D test
20 for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
21 {
22 BOOST_TEST_CHECKPOINT( "Testing 3D grid k=" << k );
23
24 // grid size
25 size_t sz[3];
26 sz[0] = k;
27 sz[1] = k;
28 sz[2] = k;
29
30 // Ghost
31 Ghost<3,float> g(0.49);
32
33 // Distributed grid with id decomposition
35
36 // check the consistency of the decomposition
37 bool val = g_dist.getDecomposition().check_consistency();
38 BOOST_REQUIRE_EQUAL(val,true);
39
40 // Grid sm
41 grid_sm<3,void> info(sz);
42
43 // get the domain iterator
44 size_t count = 0;
45
46 auto dom = g_dist.getDomainIterator();
47
48 while (dom.isNext())
49 {
50 auto key = dom.get();
51 auto key_g = g_dist.getGKey(key);
52
53 g_dist.template get<0>(key) = info.LinId(key_g);
54
55 // Count the point
56 count++;
57
58 ++dom;
59 }
60
61 // Get the virtual cluster machine
62 Vcluster<> & vcl = g_dist.getVC();
63
64 // reduce
65 vcl.sum(count);
66 vcl.execute();
67
68 // Check
69 BOOST_REQUIRE_EQUAL(count,(size_t)k*k*k);
70
71 bool match = true;
72
73 auto dom2 = g_dist.getDomainIterator();
74
75 // check that the grid store the correct information
76 while (dom2.isNext())
77 {
78 auto key = dom2.get();
79 auto key_g = g_dist.getGKey(key);
80
81 match &= (g_dist.template get<0>(key) == info.LinId(key_g))?true:false;
82
83 ++dom2;
84 }
85
86 BOOST_REQUIRE_EQUAL(match,true);
87
89
90 g_dist.template ghost_get<0>();
91
92 // check that the communication is correctly completed
93
94 auto domg = g_dist.getDomainGhostIterator();
95
96 // check that the grid with the ghost past store the correct information
97 while (domg.isNext())
98 {
99 auto key = domg.get();
100 auto key_g = g_dist.getGKey(key);
101
102 // In this case the boundary condition are non periodic
103 if (g_dist.isInside(key_g))
104 {
105 match &= (g_dist.template get<0>(key) == info.LinId(key_g))?true:false;
106 }
107
108 ++domg;
109 }
110
111 BOOST_REQUIRE_EQUAL(match,true);
112
114 }
115}
116
117
118// Test grid periodic
119void Test3D_unb_ghost_periodic(const Box<3,float> & domain, long int k)
120{
121 Vcluster<> & v_cl = create_vcluster();
122
123 if ( v_cl.getProcessingUnits() > 24 )
124 return;
125
126 long int big_step = k / 30;
127 big_step = (big_step == 0)?1:big_step;
128 long int small_step = 21;
129
130 print_test_v( "Testing grid periodic unbound ghost k<=",k);
131
132 // 3D test
133 for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
134 {
135 BOOST_TEST_CHECKPOINT( "Testing grid unbound ghost periodic k<=" << k );
136
137 // grid size
138 size_t sz[3];
139 sz[0] = k;
140 sz[1] = k;
141 sz[2] = k;
142
143 // Ghost
144 Ghost<3,float> g(0.491);
145
146 // periodicity
147 periodicity<3> pr = {{PERIODIC,PERIODIC,PERIODIC}};
148
149 // Distributed grid with id decomposition
151
152 // check the consistency of the decomposition
153 bool val = g_dist.getDecomposition().check_consistency();
154 BOOST_REQUIRE_EQUAL(val,true);
155
156 // Grid sm
157 grid_sm<3,void> info(sz);
158
159 size_t count = 0;
160
161 // Set to zero the full grid
162
163 auto dom1 = g_dist.getDomainGhostIterator();
164
165 while (dom1.isNext())
166 {
167 auto key = dom1.get();
168
169 g_dist.template get<0>(key) = -1;
170
171 ++dom1;
172 }
173
174 auto dom = g_dist.getDomainIterator();
175
176 while (dom.isNext())
177 {
178 auto key = dom.get();
179 auto key_g = g_dist.getGKey(key);
180
181 g_dist.template get<0>(key) = info.LinId(key_g);
182
183 // Count the points
184 count++;
185
186 ++dom;
187 }
188
189 // Get the virtual cluster machine
190 Vcluster<> & vcl = g_dist.getVC();
191
192 // reduce
193 vcl.sum(count);
194 vcl.execute();
195
196 // Check
197 BOOST_REQUIRE_EQUAL(count,(size_t)k*k*k);
198
199 // sync the ghosts
200 g_dist.ghost_get<0>();
201
202 bool match = true;
203
204 // Domain + Ghost iterator
205 auto dom_gi = g_dist.getDomainGhostIterator();
206
207 size_t out_cnt = 0;
208
209 while (dom_gi.isNext())
210 {
211 bool out_p = false;
212
213 auto key = dom_gi.get();
214 auto key_g = g_dist.getGKey(key);
215
216 // Return the boxes containing the grids
217 auto & gb = dom_gi.getGBoxes();
218
219 // transform the key to be periodic
220 for (size_t i = 0 ; i < 3 ; i++)
221 {
222 if (key_g.get(i) < 0)
223 {key_g.set_d(i,key_g.get(i) + k);out_p = true;}
224 else if (key_g.get(i) >= k)
225 {key_g.set_d(i,key_g.get(i) - k);out_p = true;}
226 }
227
228 if (g_dist.template get<0>(key) != -1 && out_p == true)
229 out_cnt++;
230
231 // The last points can be invalid because of rounding off problems
232 bool can_invalid = false;
233 if (key.getKey().get(0) == 0 || key.getKey().get(1) == 0 || key.getKey().get(2) == 0)
234 can_invalid = true;
235 else if (key.getKey().get(0) == gb.get(key.getSub()).GDbox.getHigh(0) ||
236 key.getKey().get(1) == gb.get(key.getSub()).GDbox.getHigh(1) ||
237 key.getKey().get(2) == gb.get(key.getSub()).GDbox.getHigh(2))
238 can_invalid = true;
239
240 if (can_invalid == true)
241 {
242 if ( g_dist.template get<0>(key) != -1 && info.LinId(key_g) != g_dist.template get<0>(key) )
243 match &= false;
244 }
245 else
246 {
247 if (info.LinId(key_g) != g_dist.template get<0>(key) )
248 match &= false;
249 }
250
251 ++dom_gi;
252 }
253
254 BOOST_REQUIRE_EQUAL(match, true);
255 if (k > 83)
256 {
257 vcl.sum(out_cnt);
258 vcl.execute();
259 BOOST_REQUIRE(out_cnt != 0ul);
260 }
261 }
262}
263
264
This class represent an N-dimensional box.
Definition Box.hpp:61
This class decompose a space into sub-sub-domains and distribute them across processors.
void execute()
Execute all the requests.
void sum(T &num)
Sum the numbers across all processors and get the result.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
Definition VCluster.hpp:59
This is a distributed grid.
Declaration grid_sm.
Definition grid_sm.hpp:167
Boundary conditions.
Definition common.hpp:22