OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_smb_tests.cpp
1//
2// Created by tommaso on 18/06/19.
3//
4
5#define BOOST_TEST_DYN_LINK
6
7#include <boost/test/unit_test.hpp>
8#include "Grid/Geometry/grid_smb.hpp"
9#include "Grid/Geometry/grid_zmb.hpp"
10
11template <unsigned int dim, typename BGT>
12void testStandardLinearizations(BGT geometry)
13{
14 grid_key_dx<dim, int> origin({0,0});
15 BOOST_REQUIRE_EQUAL(geometry.LinId(origin), 0);
16
17 grid_key_dx<dim, int> block0a({7,0});
18 BOOST_REQUIRE_EQUAL(geometry.LinId(block0a), 7);
19 grid_key_dx<dim, int> block0b({0,1});
20 BOOST_REQUIRE_EQUAL(geometry.LinId(block0b), 8);
21 grid_key_dx<dim, int> block0c({7,7});
22 BOOST_REQUIRE_EQUAL(geometry.LinId(block0c), 63);
23
24 grid_key_dx<dim, int> block1a({8+7,0});
25 BOOST_REQUIRE_EQUAL(geometry.LinId(block1a), 64+7);
26 grid_key_dx<dim, int> block1b({8+0,1});
27 BOOST_REQUIRE_EQUAL(geometry.LinId(block1b), 64+8);
28 grid_key_dx<dim, int> block1c({8+7,7});
29 BOOST_REQUIRE_EQUAL(geometry.LinId(block1c), 64+63);
30
31 grid_key_dx<dim, int> block3a({7,8+0});
32 BOOST_REQUIRE_EQUAL(geometry.LinId(block3a), (64*3)+7);
33 grid_key_dx<dim, int> block3b({0,8+1});
34 BOOST_REQUIRE_EQUAL(geometry.LinId(block3b), (64*3)+8);
35 grid_key_dx<dim, int> block3c({7,8+7});
36 BOOST_REQUIRE_EQUAL(geometry.LinId(block3c), (64*3)+63);
37}
38
39BOOST_AUTO_TEST_SUITE(BlockGeometry_tests)
40
41BOOST_AUTO_TEST_CASE(testLinId)
42{
43 constexpr unsigned int dim = 2;
44 const size_t sz[dim] = {3*8,7*8};
45 grid_smb<dim, 8> geometry(sz);
46
47 testStandardLinearizations<dim>(geometry);
48}
49
50BOOST_AUTO_TEST_CASE(testCopyConstructor)
51{
52 constexpr unsigned int dim = 2;
53 const size_t sz[dim] = {3*8,7*8};
54 grid_smb<dim, 8> geometry0(sz);
55
56 // Here copy-construct
57 grid_smb<dim, 8> geometry(geometry0);
58
59 // Then test...
60 testStandardLinearizations<dim>(geometry);
61}
62
63BOOST_AUTO_TEST_CASE(testCopyAssignOp)
64{
65 constexpr unsigned int dim = 2;
66 const size_t sz[dim] = {3*8,7*8};
67 grid_smb<dim, 8> geometry0(sz);
68
69 // Here copy-assign
70 grid_smb<dim, 8> geometry(sz);
71 geometry = geometry0;
72
73 // Then test...
74 testStandardLinearizations<dim>(geometry);
75}
76
77template<typename gsmb_type>
78void test_swap()
79{
80 const size_t sz[2] = {3*8,7*8};
81 gsmb_type geometry0(sz);
82
83 const size_t sz2[2] = {3*8+50,7*8+50};
84 gsmb_type geometry1(sz2);
85
86 geometry1.swap(geometry0);
87
88
89 BOOST_REQUIRE_EQUAL(geometry1.size(0),3*8);
90 BOOST_REQUIRE_EQUAL(geometry1.size(1),7*8);
91
92 BOOST_REQUIRE_EQUAL(geometry0.size(0),3*8+50);
93 BOOST_REQUIRE_EQUAL(geometry0.size(1),7*8+50);
94}
95
96BOOST_AUTO_TEST_CASE(testSwap)
97{
98 constexpr unsigned int dim = 2;
99
100 test_swap<grid_smb<dim, 8>>();
101 test_swap<grid_zmb<dim, 8, long int>>();
102}
103
104BOOST_AUTO_TEST_SUITE_END()
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19