1/*
2 * HDF5_writer_unit_test.hpp
3 *
4 * Created on: May 1, 2017
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_IO_SRC_HDF5_WR_HDF5_WRITER_UNIT_TESTS_HPP_
9#define OPENFPM_IO_SRC_HDF5_WR_HDF5_WRITER_UNIT_TESTS_HPP_
10
11#include "HDF5_wr.hpp"
12
13#include "hdf5.h"
14
15BOOST_AUTO_TEST_SUITE( vd_hdf5_chckpnt_rstrt_test )
16
17// Dimensionality
18const size_t dim = 3;
19
20BOOST_AUTO_TEST_CASE( vector_dist_hdf5_save_test )
21{
22 openfpm::vector<Point<3,float>> vpos;
23 openfpm::vector<aggregate<float[dim]>> vprp;
24
25 // Put forces
26
27 for (size_t i = 0 ; i < 1024 ; i++)
28 {
29 Point<3,float> p;
30
31 p.get(0) = i;
32 p.get(1) = i+13;
33 p.get(2) = i+17;
34
35 vpos.add(p);
36
37 vprp.add();
38 vprp.template get<0>(vprp.size()-1)[0] = p.get(0) + 100.0;
39 vprp.template get<0>(vprp.size()-1)[1] = p.get(1) + 200.0;
40 vprp.template get<0>(vprp.size()-1)[2] = p.get(2) + 300.0;
41 }
42
43 HDF5_writer<VECTOR_DIST> h5;
44
45 // Save the vector
46 h5.save("vector_dist.h5",vpos,vprp);
47
48 HDF5_reader<VECTOR_DIST> h5r;
49
50 openfpm::vector<Point<3,float>> vpos2;
51 openfpm::vector<aggregate<float[dim]>> vprp2;
52
53 size_t g_m = 0;
54 h5r.load("vector_dist.h5",vpos2,vprp2,g_m);
55
56 BOOST_REQUIRE_EQUAL(1024ul,vpos2.size());
57 BOOST_REQUIRE_EQUAL(1024ul,vprp2.size());
58
59 BOOST_REQUIRE_EQUAL(1024ul,g_m);
60
61 // Check that vpos == vpos2 and vprp2 == vprp2
62
63 bool check = true;
64 for (size_t i = 0 ; i < vpos.size() ; i++)
65 {
66 check &= (vpos.get(i) == vpos2.get(i));
67 check &= (vprp.get_o(i) == vprp2.get_o(i));
68 }
69
70 BOOST_REQUIRE_EQUAL(check,true);
71}
72
73
74
75BOOST_AUTO_TEST_CASE( vector_dist_hdf5_load_test )
76{
77 Vcluster<> & v_cl = create_vcluster();
78
79 openfpm::vector<Point<3,float>> vpos;
80 openfpm::vector<aggregate<float[dim]>> vprp;
81
82 HDF5_reader<VECTOR_DIST> h5;
83
84 size_t g_m = 0;
85
86 // Load the vector
87 h5.load("test_data/vector_dist_24.h5",vpos,vprp,g_m);
88
89 /////////////////// Checking data ///////////////////////
90
91 // Check total number of particles
92 size_t n_part = vpos.size();
93 v_cl.sum(n_part);
94 v_cl.execute();
95
96 BOOST_REQUIRE_EQUAL(n_part,1024ul*24ul);
97
98 BOOST_REQUIRE_EQUAL(vpos.size(),vprp.size());
99
100 bool check = true;
101
102 for (size_t i = 0 ; i < vpos.size() ; i++)
103 {
104 check &= (vprp.template get<0>(i)[0] == vpos.template get<0>(i)[0] + 100.0);
105 check &= (vprp.template get<0>(i)[1] == vpos.template get<0>(i)[1] + 200.0);
106 check &= (vprp.template get<0>(i)[2] == vpos.template get<0>(i)[2] + 300.0);
107 }
108
109
110}
111
112BOOST_AUTO_TEST_SUITE_END()
113
114
115#endif /* OPENFPM_IO_SRC_HDF5_WR_HDF5_WRITER_UNIT_TESTS_HPP_ */
116