OpenFPM_pdata  1.0.0
Project that contain the implementation of distributed structures
 All Data Structures Functions Variables Typedefs Enumerations Friends Pages
vector_dist_HDF5_chckpnt_restart_test.hpp
1 /*
2  * vector_dist_HDF5_save.hpp
3  *
4  * Created on: Jun 12, 2016
5  * Author: Yaroslav Zaluzhnyi
6  */
7 
8 #ifndef SRC_VECTOR_VECTOR_DIST_HDF5_CHCKPNT_RESTART_TEST_HPP_
9 #define SRC_VECTOR_VECTOR_DIST_HDF5_CHCKPNT_RESTART_TEST_HPP_
10 
11 #include "vector_dist.hpp"
12 #include "Packer_Unpacker/Pack_selector.hpp"
13 #include "Packer_Unpacker/Packer.hpp"
14 #include "Packer_Unpacker/Unpacker.hpp"
15 #include "Vector/performance/vector_dist_performance_util.hpp"
16 
17 
18 #include "hdf5.h"
19 
20 BOOST_AUTO_TEST_SUITE( vd_hdf5_chckpnt_rstrt_test )
21 
22 // Dimensionality
23 const size_t dim = 3;
24 
25 BOOST_AUTO_TEST_CASE( vector_dist_hdf5_save_test )
26 {
27  Box<dim,float> box;
28 
29  for (size_t i = 0; i < dim; i++)
30  {
31  box.setLow(i,0.0);
32  box.setHigh(i,1.0);
33  }
34 
35  // Boundary conditions
36  size_t bc[dim];
37 
38  const size_t Ng = 32;
39 
40  // we create a Grid iterator
41  size_t sz[dim] = {Ng,Ng,Ng};
42 
43  for (size_t i = 0; i < dim; i++)
44  bc[i] = NON_PERIODIC;
45 
46  // ghost
47  Ghost<dim,float> ghost(1.0/(Ng-2));
48 
50 
51  // Put particles
52 
53  auto it = vd.getGridIterator(sz);
54 
55  while (it.isNext())
56  {
57  vd.add();
58 
59  auto key = it.get();
60 
61  vd.getLastPos()[0] = key.get(0) * it.getSpacing(0);
62  vd.getLastPos()[1] = key.get(1) * it.getSpacing(1);
63  vd.getLastPos()[2] = key.get(2) * it.getSpacing(2);
64 
65  ++it;
66  }
67 
68  vd.map();
69 
70  // Put forces
71 
72  auto it2 = vd.getDomainIterator();
73 
74  while (it2.isNext())
75  {
76  auto key = it2.get();
77 
78  //Put the forces
79  for (size_t i = 0; i < dim; i++)
80  vd.template getProp<0>(key)[i] = 0.51234 + vd.getPos(key)[0] + vd.getPos(key)[1]+ vd.getPos(key)[2];
81 
82  ++it2;
83  }
84 
85  // Save the vector
86  vd.save("vector_dist.h5");
87 
89 
90  vd2.load("vector_dist.h5");
91 
92  // Check that vd and vd2 match
93 
94  auto it3 = vd.getDomainIterator();
95 
96  BOOST_REQUIRE_EQUAL(vd.size_local(),vd2.size_local());
97 
98  bool check = true;
99  while (it3.isNext())
100  {
101  auto p = it3.get();
102 
103  Point<3,float> p1 = vd.getPos(p);
104  Point<3,float> p2 = vd2.getPos(p);
105 
106  check &= (p1 == p2);
107 
108  check &= (vd.template getProp<0>(p)[0] == vd2.template getProp<0>(p)[0]);
109  check &= (vd.template getProp<0>(p)[1] == vd2.template getProp<0>(p)[1]);
110  check &= (vd.template getProp<0>(p)[2] == vd2.template getProp<0>(p)[2]);
111 
112  ++it3;
113  }
114 
115  BOOST_REQUIRE_EQUAL(check,true);
116 }
117 
118 
119 
120 BOOST_AUTO_TEST_CASE( vector_dist_hdf5_load_test )
121 {
122 #ifndef SE_CLASS3
123 
124  Vcluster & v_cl = create_vcluster();
125 
126  Box<dim,float> box;
127 
128  for (size_t i = 0; i < dim; i++)
129  {
130  box.setLow(i,0.0);
131  box.setHigh(i,1.0);
132  }
133 
134  // Boundary conditions
135  size_t bc[dim];
136 
137  for (size_t i = 0; i < dim; i++)
138  bc[i] = NON_PERIODIC;
139 
140 
141  const size_t Ng = 32;
142 
143  // ghost
144  Ghost<dim,float> ghost(1.0/(Ng-2));
145 
147 
148  // Load the vector
149  vd.load("test_data/vector_dist_24.h5");
150 
152 
153  // Check total number of particles
154  size_t n_part = vd.size_local();
155  v_cl.sum(n_part);
156  v_cl.execute();
157 
158  BOOST_REQUIRE_EQUAL(n_part,Ng*Ng*Ng);
159 
160  // Check properties
161 
162  auto it2 = vd.getDomainIterator();
163 
164  while (it2.isNext())
165  {
166  auto key = it2.get();
167 
168  // Check the properties
169  for (size_t i = 0; i < dim; i++)
170  BOOST_REQUIRE_EQUAL(vd.template getProp<0>(key)[i],(float)(0.51234 + vd.getPos(key)[0] + vd.getPos(key)[1]+ vd.getPos(key)[2]));
171 
172  ++it2;
173  }
174 
175 #endif
176 }
177 
178 BOOST_AUTO_TEST_SUITE_END()
179 
180 
181 #endif /* SRC_VECTOR_VECTOR_DIST_HDF5_CHCKPNT_RESTART_TEST_HPP_ */
void sum(T &num)
Sum the numbers across all processors and get the result.
void execute()
Execute all the requests.
void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:467
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
Definition: Ghost.hpp:37
Implementation of VCluster class.
Definition: VCluster.hpp:36
This class decompose a space into sub-sub-domains and distribute them across processors.
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
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
Distributed vector.