OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_dist_id_dlb_unit_test.cpp
1/*
2 * grid_dist_id_dlb_unit_test.cpp
3 *
4 * Created on: May 4, 2018
5 * Author: i-bird
6 */
7
8
9#define BOOST_TEST_DYN_LINK
10#include <boost/test/unit_test.hpp>
11
12#include "Point_test.hpp"
13#include "Grid/grid_dist_id.hpp"
14#include "data_type/aggregate.hpp"
15#include "grid_dist_id_util_tests.hpp"
16#include "Vector/vector_dist.hpp"
17
18BOOST_AUTO_TEST_SUITE( grid_dist_id_dlb_test )
19
20template<typename grid, typename vector>
21void test_vector_grid_dlb()
22{
23 // Domain
24 Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
25
27
28 size_t sz[3] = {37,37,37};
29
30 grid gdist(sz,domain3,g,DEC_GRAN(128));
31
32
34 bck.template get<0>() = -57;
35 bck.template get<1>() = -90;
36 bck.template get<2>() = -123;
37
38 gdist.setBackgroundValue(bck);
39
40 vector vd(gdist.getDecomposition(),0);
41
42 // we fill the grid with a gaussian
43
44 auto it = gdist.getGridIterator();
45
46 while (it.isNext())
47 {
48 auto p = it.get_dist();
49 auto gkey = it.get();
50
51 gdist.template insert<0>(p) = gkey.get(0);
52 gdist.template insert<1>(p) = gkey.get(1);
53 gdist.template insert<2>(p) = gkey.get(2);
54
55 ++it;
56 }
57
58 // fill a sphere of particles
59
60 auto it2 = vd.getGridIterator(sz);
61
62 while (it2.isNext())
63 {
64 auto gkey = it2.get();
65
66 vd.add();
67
68 float x = 0.2*gkey.get(0)*it2.getSpacing(0) + 0.05;
69 float y = 0.2*gkey.get(1)*it2.getSpacing(1) + 0.05;
70 float z = 0.2*gkey.get(2)*it2.getSpacing(2) + 0.05;
71
72 vd.getLastPos()[0] = x;
73 vd.getLastPos()[1] = y;
74 vd.getLastPos()[2] = z;
75
76 ++it2;
77 }
78
79 size_t n_step = 50;
80 for (size_t i = 0; i < n_step ; i++)
81 {
82 vd.map();
83 vd.addComputationCosts();
84 vd.getDecomposition().decompose();
85 vd.map();
86
87 gdist.getDecomposition() = vd.getDecomposition();
88 gdist.map();
89
90 // Check
91
92 bool check = true;
93 auto it = gdist.getDomainIterator();
94
95
96 while (it.isNext())
97 {
98 auto p = it.get();
99 auto gkey = it.getGKey(p);
100
101 check &= gdist.template get<0>(p) == gkey.get(0);
102 check &= gdist.template get<1>(p) == gkey.get(1);
103 check &= gdist.template get<2>(p) == gkey.get(2);
104
105 if (check == false)
106 {
107 std::cout << "Error " << gdist.template get<0>(p) << " != " << gkey.get(0) << " " << gdist.template get<1>(p) << " != " << gkey.get(1) << " " << gdist.template get<2>(p) << " != " << gkey.get(2) << std::endl;
108 break;
109 }
110
111 ++it;
112 }
113
114 BOOST_REQUIRE_EQUAL(check,true);
115
116 // Calculate shift vector
117
118 double t2 = 6.28*(double)(i+1)/n_step;
119 double t = 6.28*(double)i/n_step;
120 double v[3];
121 v[0] = 0.7*fabs(sin(t2)) - 0.7*fabs(sin(t));
122 v[1] = 0.7*fabs(sin(1.7*t2)) - 0.7*fabs(sin(1.7*t));
123 v[2] = 0.7*fabs(sin(2.5*t2)) - 0.7*fabs(sin(2.5*t));
124
125 auto it2 = vd.getDomainIterator();
126
127 while (it2.isNext())
128 {
129 auto p = it2.get();
130
131 vd.getPos(p)[0] += v[0];
132 vd.getPos(p)[1] += v[1];
133 vd.getPos(p)[2] += v[2];
134
135 ++it2;
136 }
137 vd.map();
138 }
139}
140
142{
143 double t = 0.0;
144
145 size_t resolution(const Point<3,float> & p)
146 {
147 float x0 = fabs(sin(t));
148 float y0 = fabs(cos(t));
149 float z0 = fabs(sin(3.0*t));
150
151 return 100 * exp( - ((p.get(0) - x0)*(p.get(0) - x0) + (p.get(1) - y0)*(p.get(1) - y0) + (p.get(2) - z0)*(p.get(2) - z0)) / 0.3);
152 }
153
154 double distributionTol()
155 {
156 return 1.01;
157 }
158};
159
160template<typename grid, typename vector>
161void test_vector_grid_dlb_resolution()
162{
163 // Domain
164 Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0});
165
167
168 size_t sz[3] = {37,37,37};
169
170 grid gdist(sz,domain3,g,DEC_GRAN(128));
171
172
174 bck.template get<0>() = -57;
175 bck.template get<1>() = -90;
176 bck.template get<2>() = -123;
177
178 gdist.setBackgroundValue(bck);
179
180 // we fill the grid with a gaussian
181
182 auto it = gdist.getGridIterator();
183
184 while (it.isNext())
185 {
186 auto p = it.get_dist();
187 auto gkey = it.get();
188
189 gdist.template insert<0>(p) = gkey.get(0);
190 gdist.template insert<1>(p) = gkey.get(1);
191 gdist.template insert<2>(p) = gkey.get(2);
192
193 ++it;
194 }
195
196 GaussianDLB gdlb;
197 gdlb.t = 0.0;
198
199 size_t n_step = 50;
200 for (size_t i = 0; i < n_step ; i++)
201 {
202 gdlb.t = (float)i/n_step;
203 gdist.addComputationCosts(gdlb);
204 gdist.getDecomposition().decompose();
205 gdist.map();
206
207 gdist.write_frame("sgrid",i);
208
209 // Check
210
211 bool check = true;
212 auto it = gdist.getDomainIterator();
213
214
215 while (it.isNext())
216 {
217 auto p = it.get();
218 auto gkey = it.getGKey(p);
219
220 check &= gdist.template get<0>(p) == gkey.get(0);
221 check &= gdist.template get<1>(p) == gkey.get(1);
222 check &= gdist.template get<2>(p) == gkey.get(2);
223
224 ++it;
225 }
226
227 BOOST_REQUIRE_EQUAL(check,true);
228 }
229}
230
231BOOST_AUTO_TEST_CASE( grid_dist_dlb_test )
232{
235
236 test_vector_grid_dlb<grid_sparse,particles>();
237}
238
239BOOST_AUTO_TEST_CASE( grid_dist_dlb_test_resolution )
240{
243
244 test_vector_grid_dlb_resolution<grid_sparse,particles>();
245}
246
247BOOST_AUTO_TEST_SUITE_END()
248
This class represent an N-dimensional box.
Definition Box.hpp:61
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition Point.hpp:172
This is a distributed grid.
Distributed vector.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
__device__ __host__ boost::mpl::at< type, boost::mpl::int_< i > >::type & get()
get the properties i
It model an expression expr1 * expr2.
Definition mul.hpp:120