8 #ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_FDSCHEME_UNIT_TESTS_HPP_
9 #define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_FDSCHEME_UNIT_TESTS_HPP_
11 #include "FiniteDifference/Derivative.hpp"
12 #include "FiniteDifference/Laplacian.hpp"
13 #include "Decomposition/CartDecomposition.hpp"
14 #include "util/grid_dist_testing.hpp"
15 #include "FiniteDifference/Average.hpp"
16 #include "FiniteDifference/sum.hpp"
19 constexpr
unsigned int x = 0;
20 constexpr
unsigned int y = 1;
21 constexpr
unsigned int z = 2;
22 constexpr
unsigned int V = 0;
27 static const unsigned int dims = 2;
29 static const unsigned int nvar = 1;
31 static const unsigned int ord = EQS_FIELD;
51 static const unsigned int dims = 2;
53 static const unsigned int nvar = 1;
54 static const unsigned int ord = EQS_FIELD;
76 static const unsigned int dims = 2;
78 static const unsigned int nvar = 1;
80 static const unsigned int ord = EQS_FIELD;
83 static const unsigned int grid_type = STAGGERED_GRID;
103 static const unsigned int dims = 2;
105 static const unsigned int nvar = 1;
106 static const unsigned int ord = EQS_FIELD;
126 BOOST_AUTO_TEST_SUITE( fd_test )
131 BOOST_AUTO_TEST_CASE( der_central_non_periodic)
136 size_t sz[2]={16,16};
145 float spacing[2] = {0.5,0.3};
154 std::unordered_map<long int,float> cols_x;
155 std::unordered_map<long int,float> cols_y;
160 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
161 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
163 BOOST_REQUIRE_EQUAL(cols_x[17+1],1/spacing[0]/2.0);
164 BOOST_REQUIRE_EQUAL(cols_x[17-1],-1/spacing[0]/2.0);
166 BOOST_REQUIRE_EQUAL(cols_y[17+16],1/spacing[1]/2.0);
167 BOOST_REQUIRE_EQUAL(cols_y[17-16],-1/spacing[1]/2.0);
173 std::unordered_map<long int,float> cols_xx;
174 std::unordered_map<long int,float> cols_xy;
175 std::unordered_map<long int,float> cols_yx;
176 std::unordered_map<long int,float> cols_yy;
180 D<x,D<x,Field<V,sys_nn>,
sys_nn>,sys_nn>::value(g_map,key22,ginfo,spacing,cols_xx,1);
181 D<x,D<y,Field<V,sys_nn>,sys_nn>,sys_nn>::value(g_map,key22,ginfo,spacing,cols_xy,1);
182 D<y,D<x,Field<V,sys_nn>,sys_nn>,sys_nn>::value(g_map,key22,ginfo,spacing,cols_yx,1);
183 D<y,D<y,Field<V,sys_nn>,sys_nn>,sys_nn>::value(g_map,key22,ginfo,spacing,cols_yy,1);
185 BOOST_REQUIRE_EQUAL(cols_xx.size(),3ul);
186 BOOST_REQUIRE_EQUAL(cols_xy.size(),4ul);
187 BOOST_REQUIRE_EQUAL(cols_yx.size(),4ul);
188 BOOST_REQUIRE_EQUAL(cols_yy.size(),3ul);
190 BOOST_REQUIRE_EQUAL(cols_xx[32],1/spacing[0]/spacing[0]/2.0/2.0);
191 BOOST_REQUIRE_EQUAL(cols_xx[34],-2/spacing[0]/spacing[0]/2.0/2.0);
192 BOOST_REQUIRE_EQUAL(cols_xx[36],1/spacing[0]/spacing[0]/2.0/2.0);
194 BOOST_REQUIRE_EQUAL(cols_xy[17],1/spacing[0]/spacing[1]/2.0/2.0);
195 BOOST_REQUIRE_EQUAL(cols_xy[19],-1/spacing[0]/spacing[1]/2.0/2.0);
196 BOOST_REQUIRE_EQUAL(cols_xy[49],-1/spacing[0]/spacing[1]/2.0/2.0);
197 BOOST_REQUIRE_EQUAL(cols_xy[51],1/spacing[0]/spacing[1]/2.0/2.0);
199 BOOST_REQUIRE_EQUAL(cols_yx[17],1/spacing[0]/spacing[1]/2.0/2.0);
200 BOOST_REQUIRE_EQUAL(cols_yx[19],-1/spacing[0]/spacing[1]/2.0/2.0);
201 BOOST_REQUIRE_EQUAL(cols_yx[49],-1/spacing[0]/spacing[1]/2.0/2.0);
202 BOOST_REQUIRE_EQUAL(cols_xy[51],1/spacing[0]/spacing[1]/2.0/2.0);
204 BOOST_REQUIRE_EQUAL(cols_yy[2],1/spacing[1]/spacing[1]/2.0/2.0);
205 BOOST_REQUIRE_EQUAL(cols_yy[34],-2/spacing[1]/spacing[1]/2.0/2.0);
206 BOOST_REQUIRE_EQUAL(cols_yy[66],1/spacing[1]/spacing[1]/2.0/2.0);
216 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
217 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
219 BOOST_REQUIRE_EQUAL(cols_x[17+1],1/spacing[0]);
220 BOOST_REQUIRE_EQUAL(cols_x[17-1],-1/spacing[0]);
222 BOOST_REQUIRE_EQUAL(cols_y[17+16],1/spacing[1]);
223 BOOST_REQUIRE_EQUAL(cols_y[17-16],-1/spacing[1]);
233 BOOST_REQUIRE_EQUAL(cols_x.size(),3ul);
234 BOOST_REQUIRE_EQUAL(cols_y.size(),3ul);
236 BOOST_REQUIRE_EQUAL(cols_x[0],-1.5/spacing[0]);
237 BOOST_REQUIRE_EQUAL(cols_x[1],2/spacing[0]);
238 BOOST_REQUIRE_EQUAL(cols_x[2],-0.5/spacing[0]);
240 BOOST_REQUIRE_CLOSE(cols_y[0],-1.5/spacing[1],0.001);
241 BOOST_REQUIRE_CLOSE(cols_y[16],2/spacing[1],0.001);
242 BOOST_REQUIRE_CLOSE(cols_y[32],-0.5/spacing[1],0.001);
249 D<x,Field<V,sys_nn>,sys_nn,CENTRAL_B_ONE_SIDE>::value(g_map,key1515,ginfo,spacing,cols_x,1);
250 D<y,Field<V,sys_nn>,sys_nn,CENTRAL_B_ONE_SIDE>::value(g_map,key1515,ginfo,spacing,cols_y,1);
252 BOOST_REQUIRE_EQUAL(cols_x.size(),3ul);
253 BOOST_REQUIRE_EQUAL(cols_y.size(),3ul);
255 BOOST_REQUIRE_EQUAL(cols_x[15*16+15],1.5/spacing[0]);
256 BOOST_REQUIRE_EQUAL(cols_x[15*16+14],-2/spacing[0]);
257 BOOST_REQUIRE_EQUAL(cols_x[15*16+13],0.5/spacing[0]);
259 BOOST_REQUIRE_CLOSE(cols_y[15*16+15],1.5/spacing[1],0.001);
260 BOOST_REQUIRE_CLOSE(cols_y[14*16+15],-2/spacing[1],0.001);
261 BOOST_REQUIRE_CLOSE(cols_y[13*16+15],0.5/spacing[1],0.001);
266 BOOST_AUTO_TEST_CASE( der_forward_backward_non_periodic )
269 size_t sz[2]={16,16};
272 float spacing[2] = {0.5,0.3};
287 std::unordered_map<long int,float> cols_x;
288 std::unordered_map<long int,float> cols_y;
293 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
294 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
296 BOOST_REQUIRE_EQUAL(cols_x[17+1],1/spacing[0]);
297 BOOST_REQUIRE_EQUAL(cols_x[17],-1/spacing[0]);
299 BOOST_REQUIRE_EQUAL(cols_y[17+16],1/spacing[1]);
300 BOOST_REQUIRE_EQUAL(cols_y[17],-1/spacing[1]);
308 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
309 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
311 BOOST_REQUIRE_EQUAL(cols_x[17],1/spacing[0]);
312 BOOST_REQUIRE_EQUAL(cols_x[17-1],-1/spacing[0]);
314 BOOST_REQUIRE_EQUAL(cols_y[17],1/spacing[1]);
315 BOOST_REQUIRE_EQUAL(cols_y[17-16],-1/spacing[1]);
320 BOOST_AUTO_TEST_CASE( avg_central_non_periodic)
323 size_t sz[2]={16,16};
326 float spacing[2] = {0.5,0.3};
341 std::unordered_map<long int,float> cols_x;
342 std::unordered_map<long int,float> cols_y;
347 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
348 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
350 BOOST_REQUIRE_EQUAL(cols_x[17+1],0.5);
351 BOOST_REQUIRE_EQUAL(cols_x[17-1],0.5);
353 BOOST_REQUIRE_EQUAL(cols_y[17+16],0.5);
354 BOOST_REQUIRE_EQUAL(cols_y[17-16],0.5);
358 std::unordered_map<long int,float> cols_xx;
359 std::unordered_map<long int,float> cols_xy;
360 std::unordered_map<long int,float> cols_yx;
361 std::unordered_map<long int,float> cols_yy;
365 Avg<x,Avg<x,Field<V,sys_nn>,sys_nn>,sys_nn>::value(g_map,key22,ginfo,spacing,cols_xx,1);
366 Avg<x,Avg<y,Field<V,sys_nn>,sys_nn>,sys_nn>::value(g_map,key22,ginfo,spacing,cols_xy,1);
367 Avg<y,Avg<x,Field<V,sys_nn>,sys_nn>,sys_nn>::value(g_map,key22,ginfo,spacing,cols_yx,1);
368 Avg<y,Avg<y,Field<V,sys_nn>,sys_nn>,sys_nn>::value(g_map,key22,ginfo,spacing,cols_yy,1);
370 BOOST_REQUIRE_EQUAL(cols_xx.size(),3ul);
371 BOOST_REQUIRE_EQUAL(cols_xy.size(),4ul);
372 BOOST_REQUIRE_EQUAL(cols_yx.size(),4ul);
373 BOOST_REQUIRE_EQUAL(cols_yy.size(),3ul);
375 BOOST_REQUIRE_EQUAL(cols_xx[32],1/2.0/2.0);
376 BOOST_REQUIRE_EQUAL(cols_xx[34],2/2.0/2.0);
377 BOOST_REQUIRE_EQUAL(cols_xx[36],1/2.0/2.0);
379 BOOST_REQUIRE_EQUAL(cols_xy[17],1/2.0/2.0);
380 BOOST_REQUIRE_EQUAL(cols_xy[19],1/2.0/2.0);
381 BOOST_REQUIRE_EQUAL(cols_xy[49],1/2.0/2.0);
382 BOOST_REQUIRE_EQUAL(cols_xy[51],1/2.0/2.0);
384 BOOST_REQUIRE_EQUAL(cols_yx[17],1/2.0/2.0);
385 BOOST_REQUIRE_EQUAL(cols_yx[19],1/2.0/2.0);
386 BOOST_REQUIRE_EQUAL(cols_yx[49],1/2.0/2.0);
387 BOOST_REQUIRE_EQUAL(cols_xy[51],1/2.0/2.0);
389 BOOST_REQUIRE_EQUAL(cols_yy[2],1/2.0/2.0);
390 BOOST_REQUIRE_EQUAL(cols_yy[34],2/2.0/2.0);
391 BOOST_REQUIRE_EQUAL(cols_yy[66],1/2.0/2.0);
396 BOOST_AUTO_TEST_CASE( der_central_staggered_non_periodic)
399 size_t sz[2]={16,16};
402 float spacing[2] = {0.5,0.3};
416 std::unordered_map<long int,float> cols_x;
417 std::unordered_map<long int,float> cols_y;
422 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
423 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
425 BOOST_REQUIRE_EQUAL(cols_x[17],1/spacing[0]);
426 BOOST_REQUIRE_EQUAL(cols_x[17-1],-1/spacing[0]);
428 BOOST_REQUIRE_EQUAL(cols_y[17],1/spacing[1]);
429 BOOST_REQUIRE_EQUAL(cols_y[17-16],-1/spacing[1]);
435 BOOST_AUTO_TEST_CASE( avg_central_staggered_non_periodic)
438 size_t sz[2]={16,16};
441 float spacing[2] = {0.5,0.3};
455 std::unordered_map<long int,float> cols_x;
456 std::unordered_map<long int,float> cols_y;
461 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
462 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
464 BOOST_REQUIRE_EQUAL(cols_x[17],1/2.0);
465 BOOST_REQUIRE_EQUAL(cols_x[17-1],1/2.0);
467 BOOST_REQUIRE_EQUAL(cols_y[17],1/2.0);
468 BOOST_REQUIRE_EQUAL(cols_y[17-16],1/2.0);
476 BOOST_AUTO_TEST_CASE( lap_periodic)
481 size_t sz[2]={16,16};
487 float spacing[2] = {0.5,0.3};
498 std::unordered_map<long int,float> cols;
502 BOOST_REQUIRE_EQUAL(cols.size(),5ul);
504 BOOST_REQUIRE_EQUAL(cols[1],1/spacing[1]/spacing[1]);
505 BOOST_REQUIRE_EQUAL(cols[17-1],1/spacing[0]/spacing[0]);
506 BOOST_REQUIRE_EQUAL(cols[17+1],1/spacing[0]/spacing[0]);
507 BOOST_REQUIRE_EQUAL(cols[17+16],1/spacing[1]/spacing[1]);
509 BOOST_REQUIRE_EQUAL(cols[17],-2/spacing[0]/spacing[0] - 2/spacing[1]/spacing[1]);
517 BOOST_REQUIRE_EQUAL(cols.size(),5ul);
519 BOOST_REQUIRE_EQUAL(cols[14*16+13],1.0/spacing[0]/spacing[0]);
520 BOOST_REQUIRE_EQUAL(cols[14*16+15],1.0/spacing[0]/spacing[0]);
521 BOOST_REQUIRE_CLOSE(cols[13*16+14],1.0/spacing[1]/spacing[1],0.001);
522 BOOST_REQUIRE_CLOSE(cols[15*16+14],1.0/spacing[1]/spacing[1],0.001);
524 BOOST_REQUIRE_EQUAL(cols[14*16+14],-2/spacing[0]/spacing[0] - 2/spacing[1]/spacing[1]);
530 BOOST_AUTO_TEST_CASE( sum_periodic)
535 size_t sz[2]={16,16};
538 float spacing[2] = {0.5,0.3};
552 std::unordered_map<long int,float> cols;
556 BOOST_REQUIRE_EQUAL(cols.size(),1ul);
558 BOOST_REQUIRE_EQUAL(cols[17],2);
564 sum<Field<V,sys_pp>, Field<V,sys_pp> , Field<V,sys_pp> ,
sys_pp>::value(g_map,key11,ginfo,spacing,cols,1);
566 BOOST_REQUIRE_EQUAL(cols.size(),1ul);
568 BOOST_REQUIRE_EQUAL(cols[17],3);
574 sum<Field<V,sys_pp>, Field<V,sys_pp> ,
minus<Field<V,sys_pp>,
sys_pp> ,sys_pp>::value(g_map,key11,ginfo,spacing,cols,1);
576 BOOST_REQUIRE_EQUAL(cols.size(),1ul);
578 BOOST_REQUIRE_EQUAL(cols[17],1ul);
585 BOOST_AUTO_TEST_CASE( fd_test_use_staggered_position)
588 size_t sz[2]={16,16};
607 BOOST_REQUIRE_EQUAL(key_ret_vx_x.
get(0),0);
608 BOOST_REQUIRE_EQUAL(key_ret_vx_x.
get(1),0);
609 BOOST_REQUIRE_EQUAL(key_ret_vx_y.
get(0),-1);
610 BOOST_REQUIRE_EQUAL(key_ret_vx_y.
get(1),-1);
611 BOOST_REQUIRE_EQUAL(key_ret_vy_y.
get(0),0);
612 BOOST_REQUIRE_EQUAL(key_ret_vy_y.
get(1),0);
613 BOOST_REQUIRE_EQUAL(key_ret_vy_x.
get(0),-1);
614 BOOST_REQUIRE_EQUAL(key_ret_vy_x.
get(1),-1);
623 BOOST_REQUIRE_EQUAL(key_ret_xx.get(0),-1);
624 BOOST_REQUIRE_EQUAL(key_ret_xx.get(1),0);
626 BOOST_REQUIRE_EQUAL(key_ret_xy.
get(0),0);
627 BOOST_REQUIRE_EQUAL(key_ret_xy.
get(1),-1);
629 BOOST_REQUIRE_EQUAL(key_ret_yx.
get(0),0);
630 BOOST_REQUIRE_EQUAL(key_ret_yx.
get(1),-1);
632 BOOST_REQUIRE_EQUAL(key_ret_yy.
get(0),-1);
633 BOOST_REQUIRE_EQUAL(key_ret_yy.
get(1),0);
642 BOOST_REQUIRE_EQUAL(key_ret_vx_x.get(0),-1);
643 BOOST_REQUIRE_EQUAL(key_ret_vx_x.get(1),0);
644 BOOST_REQUIRE_EQUAL(key_ret_vx_y.
get(0),-1);
645 BOOST_REQUIRE_EQUAL(key_ret_vx_y.
get(1),0);
646 BOOST_REQUIRE_EQUAL(key_ret_vy_y.
get(0),0);
647 BOOST_REQUIRE_EQUAL(key_ret_vy_y.
get(1),-1);
648 BOOST_REQUIRE_EQUAL(key_ret_vy_x.
get(0),0);
649 BOOST_REQUIRE_EQUAL(key_ret_vy_x.
get(1),-1);
654 BOOST_AUTO_TEST_SUITE_END()
static const bool boundary[]
boundary at X and Y
Derivative second order on h (spacing)
static const bool boundary[]
boundary at X and Y
grid_dist_id< dims, stype, aggregate< float >, CartDecomposition< 2, stype > > b_grid
Base grid.
It ancapsulate the minus operation.
grid_key_dx is the key to access any element in the grid
Position of the element of dimension d in the hyper-cube of dimension dim.
static const unsigned int dims
dimensionaly of the equation (2D problem 3D problem ...)
static const unsigned int dims
dimensionaly of the equation (2D problem 3D problem ...)
static const bool boundary[]
boundary at X and Y
grid_dist_id< dims, stype, aggregate< float >, CartDecomposition< 2, stype > > b_grid
Base grid.
Grid key for a distributed grid.
static const unsigned int dims
dimensionaly of the equation (2D problem 3D problem ...)
float stype
type of space float, double, ...
mem_id get(size_t i) const
Get the i index.
float stype
type of space float, double, ...
static const unsigned int nvar
number of fields in the system
This class decompose a space into sub-sub-domains and distribute them across processors.
This is a distributed grid.
grid_dist_id< dims, stype, aggregate< float >, CartDecomposition< 2, stype > > b_grid
Base grid.
void testing
Indicate we are on testing.
float stype
type of space float, double, ...
static const unsigned int dims
dimensionaly of the equation (2D problem 3D problem ...)
static const unsigned int nvar
Degree of freedom in the system.
void testing
specify that we are on testing
void testing
Indicate we are on testing.
Laplacian second order on h (spacing)
static const unsigned int nvar
number of degree of freedoms
grid_dist_id< dims, stype, aggregate< float >, CartDecomposition< 2, stype > > b_grid
Base grid.
float stype
type of space float, double, ...
static const bool boundary[]
boundary at X and Y
It model an expression expr1 + ... exprn.
void testing
Indicate we are on testing.
static const unsigned int nvar
number of degree of freedom in the system