OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
grid_sm_unit_tests.hpp
1 /*
2  * grid_sm_test.hpp
3  *
4  * Created on: Dec 14, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_GRID_GRID_SM_UNIT_TESTS_HPP_
9 #define OPENFPM_DATA_SRC_GRID_GRID_SM_UNIT_TESTS_HPP_
10 
11 #include "iterators/grid_key_dx_iterator_sub_bc.hpp"
12 
13 BOOST_AUTO_TEST_SUITE( grid_sm_test )
14 
15 
16 BOOST_AUTO_TEST_CASE( grid_sm_linearization )
17 {
18  const grid_key_dx<3> key1(1,2,3);
19  const grid_key_dx<3> zero(0,0,0);
20  const grid_key_dx<3> seven(7,7,7);
21  const comb<3> c({1,0,-1});
22  size_t sz[3] = {8,8,8};
23 
24  grid_sm<3,int> gs(sz);
25  size_t bc[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
26 
27  long int lin = gs.LinId<CheckExistence>(key1,c.getComb(),bc);
28  BOOST_REQUIRE_EQUAL(lin,146);
29  lin = gs.LinId<CheckExistence>(zero,c.getComb(),bc);
30  BOOST_REQUIRE_EQUAL(lin,-1);
31  lin = gs.LinId<CheckExistence>(seven,c.getComb(),bc);
32  BOOST_REQUIRE_EQUAL(lin,-1);
33 
34  for (size_t i = 0 ; i < 3 ; i++)
35  bc[i] = PERIODIC;
36 
37  lin = gs.LinId<CheckExistence>(key1,c.getComb(),bc);
38  BOOST_REQUIRE_EQUAL(lin,146);
39  lin = gs.LinId<CheckExistence>(zero,c.getComb(),bc);
40  BOOST_REQUIRE_EQUAL(lin,71);
41  lin = gs.LinId<CheckExistence>(seven,c.getComb(),bc);
42  BOOST_REQUIRE_EQUAL(lin,62);
43 }
44 
45 
46 BOOST_AUTO_TEST_CASE( grid_iterator_sub_p )
47 {
48  const grid_key_dx<3> key1(4,4,4);
49  const grid_key_dx<3> key2(-1,-1,-1);
50  const grid_key_dx<3> key3(9,9,9);
51  size_t sz[3] = {8,8,8};
52 
53  grid_sm<3,int> gs(sz);
54 
55  grid_key_dx_iterator_sub_bc<3> it(gs,key2,key1,{PERIODIC,PERIODIC,PERIODIC});
56 
57  size_t cnt = 0;
58 
59  while (it.isNext())
60  {
61  auto key = it.get();
62 
63  for (size_t i = 0 ; i < 3 ; i++)
64  {
65  BOOST_REQUIRE_EQUAL(key.get(i) >= (long int)0,true);
66  BOOST_REQUIRE_EQUAL(key.get(i) < (long int)sz[i],true);
67  }
68 
69  cnt++;
70 
71  ++it;
72  }
73 
74  BOOST_REQUIRE_EQUAL(cnt,216ul);
75 
76  grid_key_dx_iterator_sub_bc<3> it2(gs,key2,key3,{PERIODIC,PERIODIC,PERIODIC});
77 
78  cnt = 0;
79 
80  while (it2.isNext())
81  {
82  auto key = it2.get();
83 
84  for (size_t i = 0 ; i < 3 ; i++)
85  {
86  BOOST_REQUIRE_EQUAL(key.get(i) >= (long int)0,true);
87  BOOST_REQUIRE_EQUAL(key.get(i) < (long int)sz[i],true);
88  }
89 
90  cnt++;
91 
92  ++it2;
93  }
94 
95  BOOST_REQUIRE_EQUAL(cnt,1331ul);
96 
97  cnt = 0;
98 
99  const grid_key_dx<3> key4(0,-1,0);
100  const grid_key_dx<3> key5(2,2,2);
101 
102  grid_key_dx_iterator_sub_bc<3> it3(gs,key4,key5,{NON_PERIODIC,PERIODIC,NON_PERIODIC});
103 
104  while (it3.isNext())
105  {
106  auto key = it3.get();
107 
108  for (size_t i = 0 ; i < 3 ; i++)
109  {
110  BOOST_REQUIRE_EQUAL(key.get(i) >= (long int)0,true);
111  BOOST_REQUIRE_EQUAL(key.get(i) < (long int)sz[i],true);
112  }
113 
114  cnt++;
115 
116  ++it3;
117  }
118 
119  BOOST_REQUIRE_EQUAL(cnt,36ul);
120 
121  // bc non periodic with out-of-bound
122 
123  grid_key_dx_iterator_sub_bc<3,do_not_print_warning_on_adjustment<3>> it4(gs,key4,key5,{NON_PERIODIC,NON_PERIODIC,NON_PERIODIC});
124 
125  cnt = 0;
126 
127  while (it4.isNext())
128  {
129  auto key = it4.get();
130 
131  for (size_t i = 0 ; i < 3 ; i++)
132  {
133  BOOST_REQUIRE_EQUAL(key.get(i) >= (long int)0,true);
134  BOOST_REQUIRE_EQUAL(key.get(i) < (long int)sz[i],true);
135  }
136 
137  cnt++;
138 
139  ++it4;
140  }
141 
142  BOOST_REQUIRE_EQUAL(cnt,27ul);
143 
144  // case with no key
145 
146  const grid_key_dx<3> key6(-1,-1,-1);
147  const grid_key_dx<3> key7(-1,-1,8);
148 
149  grid_key_dx_iterator_sub_bc<3,do_not_print_warning_on_adjustment<3>> it5(gs,key6,key7,{NON_PERIODIC,NON_PERIODIC,NON_PERIODIC});
150 
151  cnt = 0;
152 
153  while (it5.isNext())
154  {
155  auto key = it5.get();
156 
157  for (size_t i = 0 ; i < 3 ; i++)
158  {
159  BOOST_REQUIRE_EQUAL(key.get(i) >= 0,true);
160  BOOST_REQUIRE_EQUAL(key.get(i) < (long int)sz[i],true);
161  }
162 
163  cnt++;
164 
165  ++it5;
166  }
167 
168  BOOST_REQUIRE_EQUAL(cnt,0ul);
169 }
170 
171 BOOST_AUTO_TEST_SUITE_END()
172 
173 
174 #endif /* OPENFPM_DATA_SRC_GRID_GRID_SM_UNIT_TESTS_HPP_ */
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
Position of the element of dimension d in the hyper-cube of dimension dim.
Definition: comb.hpp:34
The same as grid_key_dx_iterator_sub_p but with periodic boundary.
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:202
class that store the information of the grid like number of point on each direction and define the in...
Definition: grid_sm.hpp:69
Class to check if the edge can be created or not.
Definition: grid_sm.hpp:50