OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
shift_vect_converter_tests.cpp
1 /*
2  * shift_vect_converter_tests.cpp
3  *
4  * Created on: Feb 8, 2018
5  * Author: i-bird
6  */
7 
8 #define BOOST_TEST_DYN_LINK
9 #include <boost/test/unit_test.hpp>
10 #include "Space/Shape/Box.hpp"
11 
12 #include "Vector/map_vector.hpp"
13 #include "Decomposition/shift_vect_converter.hpp"
14 
15 BOOST_AUTO_TEST_SUITE( shift_vect_converter_tests_suite )
16 
17 BOOST_AUTO_TEST_CASE( shift_vect_converter_tests_use )
18 {
19  {
20  Box<3,double> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
22  size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
23 
25 
26  svc.generateShiftVectors(domain,bc,sv);
27 
28  BOOST_REQUIRE_EQUAL(sv.size(),27ul);
29 
30  // We test that the cominations generate the correct shift vectors
31  comb<3> cmb1({-1,-1,1});
32  comb<3> cmb2({-1,0,1});
33  comb<3> cmb3({0,0,1});
34 
35  size_t i = svc.linId(cmb1);
36 
37  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[0],-1.0);
38  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[1],1.0);
39  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[2],1.0);
40 
41  i = svc.linId(cmb2);
42 
43  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[0],-1.0);
44  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[1],0.0);
45  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[2],1.0);
46 
47  i = svc.linId(cmb3);
48 
49  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[0],-1.0);
50  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[1],0.0);
51  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[2],0.0);
52 
53  }
54 
55  {
57  Box<50,double> domain;
58  size_t bc[50];
59 
60  for (size_t i = 0 ; i < 50 ; i++)
61  {
62  domain.setLow(i,0.0);
63  domain.setHigh(i,1.0);
64  bc[i] = NON_PERIODIC;
65  }
66 
67  bc[5] = PERIODIC;
68  bc[17] = PERIODIC;
69  bc[23] = PERIODIC;
70 
72 
73  svc.generateShiftVectors(domain,bc,sv);
74 
75  BOOST_REQUIRE_EQUAL(sv.size(),27ul);
76 
77  // We test that the cominations generate the correct shift vectors
78  comb<50> cmb1;
79  comb<50> cmb2;
80  comb<50> cmb3;
81 
82  cmb1.c[5] = 1;
83  cmb1.c[17] = -1;
84  cmb1.c[23] = -1;
85 
86  cmb2.c[5] = 1;
87  cmb2.c[17] = 0;
88  cmb2.c[23] = -1;
89 
90  cmb3.c[5] = 1;
91  cmb3.c[17] = 0;
92  cmb3.c[23] = 0;
93 
94  size_t i = svc.linId(cmb1);
95 
96  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[5],-1.0);
97  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[6],0.0);
98  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[17],1.0);
99  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[23],1.0);
100  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[24],0.0);
101 
102  i = svc.linId(cmb2);
103 
104  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[5],-1.0);
105  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[6],0.0);
106  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[17],0.0);
107  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[23],1.0);
108  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[24],0.0);
109 
110  i = svc.linId(cmb3);
111 
112  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[5],-1.0);
113  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[6],0.0);
114  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[17],0.0);
115  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[23],0.0);
116  BOOST_REQUIRE_EQUAL(sv.get<0>(i)[24],0.0);
117 
118  }
119 }
120 
121 
122 BOOST_AUTO_TEST_SUITE_END()
123 
size_t linId(const comb< dim > &cmb)
linearize the combination in case of high dimensions
Position of the element of dimension d in the hyper-cube of dimension dim.
Definition: comb.hpp:34
void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:467
size_t size()
Stub size.
Definition: map_vector.hpp:70
void generateShiftVectors(const Box< dim, T > &domain, size_t(&bc)[dim], openfpm::vector< Point< dim, T >> &shifts)
Here we generare the shift vectors for the low dimension case.
void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:456
This class represent an N-dimensional box.
Definition: Box.hpp:56
in case of high dimensions shift vector converter
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
char c[dim]
Array that store the combination.
Definition: comb.hpp:37