OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_dist_id_unit_test_ext_dom.hpp
1/*
2 * grid_dist_id_unit_test_ext_dom.hpp
3 *
4 * Created on: Feb 24, 2016
5 * Author: i-bird
6 */
7#include "Decomposition/CartDecomposition_ext.hpp"
8#include "Grid/grid_dist_id.hpp"
9
10extern void print_test_v(std::string test, size_t sz);
11
12// Test duplicated topology
13
14void Test3D_extended_grid(const Box<3,float> & domain, long int k)
15{
16 long int big_step = k / 30;
17 big_step = (big_step == 0)?1:big_step;
18 long int small_step = 21;
19
20 Vcluster<> & v_cl = create_vcluster();
21
22 if ( v_cl.getProcessingUnits() > 32 )
23 return;
24
25 print_test_v( "Testing 3D extended grid k<=",k);
26
27 // factor
28 float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
29
30 // This test in order to work must have at least one ghost
31 for ( ; (0.01 / factor) > ((domain.getHigh(0) - domain.getLow(0)) / k) ; k-= (k > 2*big_step)?big_step:small_step )
32 {
33 BOOST_TEST_CHECKPOINT( "Testing 3D extended grid k=" << k );
34
35 // grid size
36 size_t sz[3];
37 sz[0] = k;
38 sz[1] = k;
39 sz[2] = k;
40
41 // Ghost
42 Ghost<3,float> g(0.01 / factor);
43
45
46 // Distributed grid with id decomposition
48
49 // Extend the grid by 2 points
50 Box<3,size_t> ext({2,2,2},{2,2,2});
51
52 // Ghost size of 1 grid point
54
55 // another grid perfectly overlapping the previous, extended by 2 points
57
58 // Given an iterator of the grid 1
59 auto dom_g1 = g_dist1.getDomainIterator();
60 // And a sub-iterator of grid 2 overlapping grid 1
61 auto dom_g2 = g_dist2.getSubDomainIterator({0,0,0},{k-1,k-1,k-1});
62
63 // the 2 iterator must match
64
65 bool check = true;
66
67 while (dom_g2.isNext())
68 {
69 auto key1 = dom_g1.get();
70 auto key2 = dom_g2.get();
71
72 grid_key_dx<3> g1_k = g_dist1.getGKey(key1);
73 grid_key_dx<3> g2_k = g_dist2.getGKey(key2);
74
75 check &= (g1_k == g2_k)?true:false;
76
77 ++dom_g1;
78 ++dom_g2;
79 }
80
81 BOOST_REQUIRE_EQUAL(check,true);
82
84
85 bool ret = g_dist2.getDecomposition().check_consistency();
86 BOOST_REQUIRE_EQUAL(ret,true);
87
88 // Get domain iterator
89
90 grid_sm<3,void> info = g_dist2.getGridInfo();
91 auto dom_g3 = g_dist2.getDomainIterator();
92
93 check = false;
94
95 while (dom_g3.isNext())
96 {
97 auto key1 = dom_g3.get();
98
99 auto keyg = g_dist2.getGKey(key1);
100
101 g_dist2.template get<0>(key1)[0] = keyg.get(0);
102 g_dist2.template get<0>(key1)[1] = keyg.get(1);
103 g_dist2.template get<0>(key1)[2] = keyg.get(2);
104
105 g_dist2.template get<1>(key1) = info.LinId(keyg);
106
107 ++dom_g3;
108 }
109
110 g_dist2.ghost_get<0,1>();
111
112 auto dom_g4 = g_dist2.getSubDomainIterator({-1,-1,-1},{(long int) sz[0]+2-2, (long int) sz[1]+2-2, (long int) sz[2]+2-2});
113
114 check = true;
115
116 while (dom_g4.isNext())
117 {
118 auto key1 = dom_g4.get();
119
120 key1 = key1.move(0,1);
121 key1 = key1.move(1,1);
122 key1 = key1.move(2,1);
123
124 auto key2 = g_dist2.getGKey(key1);
125
126 check &= g_dist2.template get<0>(key1)[0] == (size_t)key2.get(0);
127 check &= g_dist2.template get<0>(key1)[1] == (size_t)key2.get(1);
128 check &= g_dist2.template get<0>(key1)[2] == (size_t)key2.get(2);
129
130 auto key3 = dom_g4.get();
131
132 key3 = key3.move(0,-1);
133 key3 = key3.move(1,-1);
134 key3 = key3.move(2,-1);
135
136 auto key4 = g_dist2.getGKey(key3);
137
138 check &= g_dist2.template get<0>(key3)[0] == (size_t)key4.get(0);
139 check &= g_dist2.template get<0>(key3)[1] == (size_t)key4.get(1);
140 check &= g_dist2.template get<0>(key3)[2] == (size_t)key4.get(2);
141
142 ++dom_g4;
143 }
144
145 BOOST_REQUIRE_EQUAL(check,true);
146 }
147}
148
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.
This class decompose a space into sub-sub-domains and distribute them across processors.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
Definition VCluster.hpp:59
This is a distributed grid.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
Declaration grid_sm.
Definition grid_sm.hpp:167
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition grid_sm.hpp:454
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data