8#ifndef OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_FDSCHEME_UNIT_TESTS_HPP_
9#define OPENFPM_NUMERICS_SRC_FINITEDIFFERENCE_FDSCHEME_UNIT_TESTS_HPP_
11#define BOOST_TEST_DYN_LINK
12#include <boost/test/unit_test.hpp>
14#include "FiniteDifference/Derivative.hpp"
15#include "FiniteDifference/Laplacian.hpp"
16#include "Decomposition/CartDecomposition.hpp"
17#include "util/grid_dist_testing.hpp"
18#include "FiniteDifference/Average.hpp"
19#include "FiniteDifference/sum.hpp"
22constexpr unsigned int x = 0;
23constexpr unsigned int y = 1;
24constexpr unsigned int z = 2;
25constexpr unsigned int V = 0;
30 static const unsigned int dims = 2;
32 static const unsigned int nvar = 1;
34 static const unsigned int ord = EQS_FIELD;
54 static const unsigned int dims = 2;
56 static const unsigned int nvar = 1;
57 static const unsigned int ord = EQS_FIELD;
79 static const unsigned int dims = 2;
81 static const unsigned int nvar = 1;
83 static const unsigned int ord = EQS_FIELD;
86 static const unsigned int grid_type = STAGGERED_GRID;
106 static const unsigned int dims = 2;
108 static const unsigned int nvar = 1;
109 static const unsigned int ord = EQS_FIELD;
129BOOST_AUTO_TEST_SUITE( fd_test )
134BOOST_AUTO_TEST_CASE( der_central_non_periodic)
139 size_t sz[2]={16,16};
148 float spacing[2] = {0.5,0.3};
157 std::unordered_map<long int,float> cols_x;
158 std::unordered_map<long int,float> cols_y;
163 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
164 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
166 BOOST_REQUIRE_EQUAL(cols_x[17+1],1/spacing[0]/2.0);
167 BOOST_REQUIRE_EQUAL(cols_x[17-1],-1/spacing[0]/2.0);
169 BOOST_REQUIRE_EQUAL(cols_y[17+16],1/spacing[1]/2.0);
170 BOOST_REQUIRE_EQUAL(cols_y[17-16],-1/spacing[1]/2.0);
176 std::unordered_map<long int,float> cols_xx;
177 std::unordered_map<long int,float> cols_xy;
178 std::unordered_map<long int,float> cols_yx;
179 std::unordered_map<long int,float> cols_yy;
183 D<x,D<x,Field<V,sys_nn>,
sys_nn>,
sys_nn>::value(g_map,key22,ginfo,spacing,cols_xx,1);
184 D<x,D<y,Field<V,sys_nn>,
sys_nn>,
sys_nn>::value(g_map,key22,ginfo,spacing,cols_xy,1);
185 D<y,D<x,Field<V,sys_nn>,
sys_nn>,
sys_nn>::value(g_map,key22,ginfo,spacing,cols_yx,1);
186 D<y,D<y,Field<V,sys_nn>,
sys_nn>,
sys_nn>::value(g_map,key22,ginfo,spacing,cols_yy,1);
188 BOOST_REQUIRE_EQUAL(cols_xx.size(),3ul);
189 BOOST_REQUIRE_EQUAL(cols_xy.size(),4ul);
190 BOOST_REQUIRE_EQUAL(cols_yx.size(),4ul);
191 BOOST_REQUIRE_EQUAL(cols_yy.size(),3ul);
193 BOOST_REQUIRE_EQUAL(cols_xx[32],1/spacing[0]/spacing[0]/2.0/2.0);
194 BOOST_REQUIRE_EQUAL(cols_xx[34],-2/spacing[0]/spacing[0]/2.0/2.0);
195 BOOST_REQUIRE_EQUAL(cols_xx[36],1/spacing[0]/spacing[0]/2.0/2.0);
197 BOOST_REQUIRE_EQUAL(cols_xy[17],1/spacing[0]/spacing[1]/2.0/2.0);
198 BOOST_REQUIRE_EQUAL(cols_xy[19],-1/spacing[0]/spacing[1]/2.0/2.0);
199 BOOST_REQUIRE_EQUAL(cols_xy[49],-1/spacing[0]/spacing[1]/2.0/2.0);
200 BOOST_REQUIRE_EQUAL(cols_xy[51],1/spacing[0]/spacing[1]/2.0/2.0);
202 BOOST_REQUIRE_EQUAL(cols_yx[17],1/spacing[0]/spacing[1]/2.0/2.0);
203 BOOST_REQUIRE_EQUAL(cols_yx[19],-1/spacing[0]/spacing[1]/2.0/2.0);
204 BOOST_REQUIRE_EQUAL(cols_yx[49],-1/spacing[0]/spacing[1]/2.0/2.0);
205 BOOST_REQUIRE_EQUAL(cols_xy[51],1/spacing[0]/spacing[1]/2.0/2.0);
207 BOOST_REQUIRE_EQUAL(cols_yy[2],1/spacing[1]/spacing[1]/2.0/2.0);
208 BOOST_REQUIRE_EQUAL(cols_yy[34],-2/spacing[1]/spacing[1]/2.0/2.0);
209 BOOST_REQUIRE_EQUAL(cols_yy[66],1/spacing[1]/spacing[1]/2.0/2.0);
219 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
220 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
222 BOOST_REQUIRE_EQUAL(cols_x[17+1],1/spacing[0]);
223 BOOST_REQUIRE_EQUAL(cols_x[17-1],-1/spacing[0]);
225 BOOST_REQUIRE_EQUAL(cols_y[17+16],1/spacing[1]);
226 BOOST_REQUIRE_EQUAL(cols_y[17-16],-1/spacing[1]);
236 BOOST_REQUIRE_EQUAL(cols_x.size(),3ul);
237 BOOST_REQUIRE_EQUAL(cols_y.size(),3ul);
239 BOOST_REQUIRE_EQUAL(cols_x[0],-1.5/spacing[0]);
240 BOOST_REQUIRE_EQUAL(cols_x[1],2/spacing[0]);
241 BOOST_REQUIRE_EQUAL(cols_x[2],-0.5/spacing[0]);
243 BOOST_REQUIRE_CLOSE(cols_y[0],-1.5/spacing[1],0.001);
244 BOOST_REQUIRE_CLOSE(cols_y[16],2/spacing[1],0.001);
245 BOOST_REQUIRE_CLOSE(cols_y[32],-0.5/spacing[1],0.001);
255 BOOST_REQUIRE_EQUAL(cols_x.size(),3ul);
256 BOOST_REQUIRE_EQUAL(cols_y.size(),3ul);
258 BOOST_REQUIRE_EQUAL(cols_x[15*16+15],1.5/spacing[0]);
259 BOOST_REQUIRE_EQUAL(cols_x[15*16+14],-2/spacing[0]);
260 BOOST_REQUIRE_EQUAL(cols_x[15*16+13],0.5/spacing[0]);
262 BOOST_REQUIRE_CLOSE(cols_y[15*16+15],1.5/spacing[1],0.001);
263 BOOST_REQUIRE_CLOSE(cols_y[14*16+15],-2/spacing[1],0.001);
264 BOOST_REQUIRE_CLOSE(cols_y[13*16+15],0.5/spacing[1],0.001);
269BOOST_AUTO_TEST_CASE( der_forward_backward_non_periodic )
272 size_t sz[2]={16,16};
275 float spacing[2] = {0.5,0.3};
290 std::unordered_map<long int,float> cols_x;
291 std::unordered_map<long int,float> cols_y;
296 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
297 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
299 BOOST_REQUIRE_EQUAL(cols_x[17+1],1/spacing[0]);
300 BOOST_REQUIRE_EQUAL(cols_x[17],-1/spacing[0]);
302 BOOST_REQUIRE_EQUAL(cols_y[17+16],1/spacing[1]);
303 BOOST_REQUIRE_EQUAL(cols_y[17],-1/spacing[1]);
311 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
312 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
314 BOOST_REQUIRE_EQUAL(cols_x[17],1/spacing[0]);
315 BOOST_REQUIRE_EQUAL(cols_x[17-1],-1/spacing[0]);
317 BOOST_REQUIRE_EQUAL(cols_y[17],1/spacing[1]);
318 BOOST_REQUIRE_EQUAL(cols_y[17-16],-1/spacing[1]);
323BOOST_AUTO_TEST_CASE( avg_central_non_periodic)
326 size_t sz[2]={16,16};
329 float spacing[2] = {0.5,0.3};
344 std::unordered_map<long int,float> cols_x;
345 std::unordered_map<long int,float> cols_y;
350 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
351 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
353 BOOST_REQUIRE_EQUAL(cols_x[17+1],0.5);
354 BOOST_REQUIRE_EQUAL(cols_x[17-1],0.5);
356 BOOST_REQUIRE_EQUAL(cols_y[17+16],0.5);
357 BOOST_REQUIRE_EQUAL(cols_y[17-16],0.5);
361 std::unordered_map<long int,float> cols_xx;
362 std::unordered_map<long int,float> cols_xy;
363 std::unordered_map<long int,float> cols_yx;
364 std::unordered_map<long int,float> cols_yy;
368 Avg<x,Avg<x,Field<V,sys_nn>,
sys_nn>,
sys_nn>::value(g_map,key22,ginfo,spacing,cols_xx,1);
369 Avg<x,Avg<y,Field<V,sys_nn>,
sys_nn>,
sys_nn>::value(g_map,key22,ginfo,spacing,cols_xy,1);
370 Avg<y,Avg<x,Field<V,sys_nn>,
sys_nn>,
sys_nn>::value(g_map,key22,ginfo,spacing,cols_yx,1);
371 Avg<y,Avg<y,Field<V,sys_nn>,
sys_nn>,
sys_nn>::value(g_map,key22,ginfo,spacing,cols_yy,1);
373 BOOST_REQUIRE_EQUAL(cols_xx.size(),3ul);
374 BOOST_REQUIRE_EQUAL(cols_xy.size(),4ul);
375 BOOST_REQUIRE_EQUAL(cols_yx.size(),4ul);
376 BOOST_REQUIRE_EQUAL(cols_yy.size(),3ul);
378 BOOST_REQUIRE_EQUAL(cols_xx[32],1/2.0/2.0);
379 BOOST_REQUIRE_EQUAL(cols_xx[34],2/2.0/2.0);
380 BOOST_REQUIRE_EQUAL(cols_xx[36],1/2.0/2.0);
382 BOOST_REQUIRE_EQUAL(cols_xy[17],1/2.0/2.0);
383 BOOST_REQUIRE_EQUAL(cols_xy[19],1/2.0/2.0);
384 BOOST_REQUIRE_EQUAL(cols_xy[49],1/2.0/2.0);
385 BOOST_REQUIRE_EQUAL(cols_xy[51],1/2.0/2.0);
387 BOOST_REQUIRE_EQUAL(cols_yx[17],1/2.0/2.0);
388 BOOST_REQUIRE_EQUAL(cols_yx[19],1/2.0/2.0);
389 BOOST_REQUIRE_EQUAL(cols_yx[49],1/2.0/2.0);
390 BOOST_REQUIRE_EQUAL(cols_xy[51],1/2.0/2.0);
392 BOOST_REQUIRE_EQUAL(cols_yy[2],1/2.0/2.0);
393 BOOST_REQUIRE_EQUAL(cols_yy[34],2/2.0/2.0);
394 BOOST_REQUIRE_EQUAL(cols_yy[66],1/2.0/2.0);
399BOOST_AUTO_TEST_CASE( der_central_staggered_non_periodic)
402 size_t sz[2]={16,16};
405 float spacing[2] = {0.5,0.3};
419 std::unordered_map<long int,float> cols_x;
420 std::unordered_map<long int,float> cols_y;
425 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
426 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
428 BOOST_REQUIRE_EQUAL(cols_x[17],1/spacing[0]);
429 BOOST_REQUIRE_EQUAL(cols_x[17-1],-1/spacing[0]);
431 BOOST_REQUIRE_EQUAL(cols_y[17],1/spacing[1]);
432 BOOST_REQUIRE_EQUAL(cols_y[17-16],-1/spacing[1]);
438BOOST_AUTO_TEST_CASE( avg_central_staggered_non_periodic)
441 size_t sz[2]={16,16};
444 float spacing[2] = {0.5,0.3};
458 std::unordered_map<long int,float> cols_x;
459 std::unordered_map<long int,float> cols_y;
464 BOOST_REQUIRE_EQUAL(cols_x.size(),2ul);
465 BOOST_REQUIRE_EQUAL(cols_y.size(),2ul);
467 BOOST_REQUIRE_EQUAL(cols_x[17],1/2.0);
468 BOOST_REQUIRE_EQUAL(cols_x[17-1],1/2.0);
470 BOOST_REQUIRE_EQUAL(cols_y[17],1/2.0);
471 BOOST_REQUIRE_EQUAL(cols_y[17-16],1/2.0);
479BOOST_AUTO_TEST_CASE( lap_periodic)
484 size_t sz[2]={16,16};
490 float spacing[2] = {0.5,0.3};
501 std::unordered_map<long int,float> cols;
505 BOOST_REQUIRE_EQUAL(cols.size(),5ul);
507 BOOST_REQUIRE_EQUAL(cols[1],1/spacing[1]/spacing[1]);
508 BOOST_REQUIRE_EQUAL(cols[17-1],1/spacing[0]/spacing[0]);
509 BOOST_REQUIRE_EQUAL(cols[17+1],1/spacing[0]/spacing[0]);
510 BOOST_REQUIRE_EQUAL(cols[17+16],1/spacing[1]/spacing[1]);
512 BOOST_REQUIRE_EQUAL(cols[17],-2/spacing[0]/spacing[0] - 2/spacing[1]/spacing[1]);
520 BOOST_REQUIRE_EQUAL(cols.size(),5ul);
522 BOOST_REQUIRE_EQUAL(cols[14*16+13],1.0/spacing[0]/spacing[0]);
523 BOOST_REQUIRE_EQUAL(cols[14*16+15],1.0/spacing[0]/spacing[0]);
524 BOOST_REQUIRE_CLOSE(cols[13*16+14],1.0/spacing[1]/spacing[1],0.001);
525 BOOST_REQUIRE_CLOSE(cols[15*16+14],1.0/spacing[1]/spacing[1],0.001);
527 BOOST_REQUIRE_EQUAL(cols[14*16+14],-2/spacing[0]/spacing[0] - 2/spacing[1]/spacing[1]);
533BOOST_AUTO_TEST_CASE( sum_periodic)
538 size_t sz[2]={16,16};
541 float spacing[2] = {0.5,0.3};
555 std::unordered_map<long int,float> cols;
559 BOOST_REQUIRE_EQUAL(cols.size(),1ul);
561 BOOST_REQUIRE_EQUAL(cols[17],2);
567 sum<Field<V,sys_pp>,
Field<V,sys_pp> ,
Field<V,sys_pp> ,
sys_pp>::value(g_map,key11,ginfo,spacing,cols,1);
569 BOOST_REQUIRE_EQUAL(cols.size(),1ul);
571 BOOST_REQUIRE_EQUAL(cols[17],3);
577 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);
579 BOOST_REQUIRE_EQUAL(cols.size(),1ul);
581 BOOST_REQUIRE_EQUAL(cols[17],1ul);
588BOOST_AUTO_TEST_CASE( fd_test_use_staggered_position)
591 size_t sz[2]={16,16};
602 comb<2> vx_c[] = {{(char)0,(
char)-1}};
603 comb<2> vy_c[] = {{(char)-1,(
char)0}};
610 BOOST_REQUIRE_EQUAL(key_ret_vx_x.
get(0),0);
611 BOOST_REQUIRE_EQUAL(key_ret_vx_x.
get(1),0);
612 BOOST_REQUIRE_EQUAL(key_ret_vx_y.
get(0),-1);
613 BOOST_REQUIRE_EQUAL(key_ret_vx_y.
get(1),-1);
614 BOOST_REQUIRE_EQUAL(key_ret_vy_y.
get(0),0);
615 BOOST_REQUIRE_EQUAL(key_ret_vy_y.
get(1),0);
616 BOOST_REQUIRE_EQUAL(key_ret_vy_x.
get(0),-1);
617 BOOST_REQUIRE_EQUAL(key_ret_vy_x.
get(1),-1);
626 BOOST_REQUIRE_EQUAL(key_ret_xx.
get(0),-1);
627 BOOST_REQUIRE_EQUAL(key_ret_xx.
get(1),0);
629 BOOST_REQUIRE_EQUAL(key_ret_xy.
get(0),0);
630 BOOST_REQUIRE_EQUAL(key_ret_xy.
get(1),-1);
632 BOOST_REQUIRE_EQUAL(key_ret_yx.
get(0),0);
633 BOOST_REQUIRE_EQUAL(key_ret_yx.
get(1),-1);
635 BOOST_REQUIRE_EQUAL(key_ret_yy.
get(0),-1);
636 BOOST_REQUIRE_EQUAL(key_ret_yy.
get(1),0);
645 BOOST_REQUIRE_EQUAL(key_ret_vx_x.
get(0),-1);
646 BOOST_REQUIRE_EQUAL(key_ret_vx_x.
get(1),0);
647 BOOST_REQUIRE_EQUAL(key_ret_vx_y.
get(0),-1);
648 BOOST_REQUIRE_EQUAL(key_ret_vx_y.
get(1),0);
649 BOOST_REQUIRE_EQUAL(key_ret_vy_y.
get(0),0);
650 BOOST_REQUIRE_EQUAL(key_ret_vy_y.
get(1),-1);
651 BOOST_REQUIRE_EQUAL(key_ret_vy_x.
get(0),0);
652 BOOST_REQUIRE_EQUAL(key_ret_vy_x.
get(1),-1);
657BOOST_AUTO_TEST_SUITE_END()
This class decompose a space into sub-sub-domains and distribute them across processors.
Derivative second order on h (spacing)
Laplacian second order on h (spacing)
This is a distributed grid.
Grid key for a distributed grid.
grid_key_dx is the key to access any element in the grid
__device__ __host__ index_type get(index_type i) const
Get the i index.
Position of the element of dimension d in the hyper-cube of dimension dim.
It ancapsulate the minus operation.
It model an expression expr1 + ... exprn.
static const unsigned int nvar
number of degree of freedoms
void testing
specify that we are on testing
static const unsigned int dims
dimensionaly of the equation (2D problem 3D problem ...)
grid_dist_id< dims, stype, aggregate< float >, CartDecomposition< 2, stype > > b_grid
Base grid.
static const bool boundary[]
boundary at X and Y
float stype
type of space float, double, ...
static const unsigned int nvar
number of degree of freedom in the system
grid_dist_id< dims, stype, aggregate< float >, CartDecomposition< 2, stype > > b_grid
Base grid.
static const bool boundary[]
boundary at X and Y
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 ...)
grid_dist_id< dims, stype, aggregate< float >, CartDecomposition< 2, stype > > b_grid
Base grid.
float stype
type of space float, double, ...
void testing
Indicate we are on testing.
static const unsigned int nvar
Degree of freedom in the system.
static const bool boundary[]
boundary at X and Y
static const unsigned int dims
dimensionaly of the equation (2D problem 3D problem ...)
grid_dist_id< dims, stype, aggregate< float >, CartDecomposition< 2, stype > > b_grid
Base grid.
static const unsigned int dims
dimensionaly of the equation (2D problem 3D problem ...)
static const unsigned int nvar
number of fields in the system
static const bool boundary[]
boundary at X and Y
float stype
type of space float, double, ...
void testing
Indicate we are on testing.