| 1 | /* | 
| 2 |  * vector_dist_HDF5_save.hpp | 
| 3 |  * | 
| 4 |  *  Created on: Jun 12, 2016 | 
| 5 |  *      Author: Yaroslav Zaluzhnyi | 
| 6 |  */ | 
| 7 | #define BOOST_TEST_DYN_LINK | 
| 8 | #include <boost/test/unit_test.hpp> | 
| 9 |  | 
| 10 | #include "Vector/vector_dist.hpp" | 
| 11 | #include "Packer_Unpacker/Pack_selector.hpp" | 
| 12 | #include "Packer_Unpacker/Packer.hpp" | 
| 13 | #include "Packer_Unpacker/Unpacker.hpp" | 
| 14 | #include "Vector/performance/vector_dist_performance_util.hpp" | 
| 15 | #include "NN/CellList/CellList_util.hpp" | 
| 16 |  | 
| 17 | #include "hdf5.h" | 
| 18 |  | 
| 19 | BOOST_AUTO_TEST_SUITE( vd_hdf5_chckpnt_rstrt_test ) | 
| 20 |  | 
| 21 | // Dimensionality | 
| 22 | const size_t dim = 3; | 
| 23 |  | 
| 24 | BOOST_AUTO_TEST_CASE( vector_dist_hdf5_save_test ) | 
| 25 | { | 
| 26 | 	Box<dim,float> box; | 
| 27 |  | 
| 28 | 	for (size_t i = 0; i < dim; i++) | 
| 29 | 	{ | 
| 30 | 		box.setLow(i,0.0); | 
| 31 | 		box.setHigh(i,1.0); | 
| 32 | 	} | 
| 33 |  | 
| 34 | 	// Boundary conditions | 
| 35 | 	size_t bc[dim]; | 
| 36 |  | 
| 37 | 	const size_t Ng = 32; | 
| 38 |  | 
| 39 | 	// we create a Grid iterator | 
| 40 | 	size_t sz[dim] = {Ng,Ng,Ng}; | 
| 41 |  | 
| 42 | 	for (size_t i = 0; i < dim; i++) | 
| 43 | 	{bc[i] = NON_PERIODIC;} | 
| 44 |  | 
| 45 | 	// ghost | 
| 46 | 	Ghost<dim,float> ghost(1.0/(Ng-2)); | 
| 47 |  | 
| 48 | 	vector_dist<dim,float, aggregate<float[dim]> > vd(0,box,bc,ghost); | 
| 49 |  | 
| 50 | 	// Put particles | 
| 51 |  | 
| 52 | 	auto it = vd.getGridIterator(sz); | 
| 53 |  | 
| 54 | 	while (it.isNext()) | 
| 55 | 	{ | 
| 56 | 		vd.add(); | 
| 57 |  | 
| 58 | 		auto key = it.get(); | 
| 59 |  | 
| 60 | 		vd.getLastPos()[0] = key.get(0) * it.getSpacing(0); | 
| 61 | 		vd.getLastPos()[1] = key.get(1) * it.getSpacing(1); | 
| 62 | 		vd.getLastPos()[2] = key.get(2) * it.getSpacing(2); | 
| 63 |  | 
| 64 | 		++it; | 
| 65 | 	} | 
| 66 |  | 
| 67 | 	vd.map(); | 
| 68 |  | 
| 69 | 	// Put forces | 
| 70 |  | 
| 71 | 	auto it2 = vd.getDomainIterator(); | 
| 72 |  | 
| 73 | 	while (it2.isNext()) | 
| 74 | 	{ | 
| 75 | 		auto key = it2.get(); | 
| 76 |  | 
| 77 | 		//Put the forces | 
| 78 | 		for (size_t i = 0; i < dim; i++) | 
| 79 | 			vd.template getProp<0>(key)[i] = 0.51234 + vd.getPos(key)[0] + vd.getPos(key)[1]+ vd.getPos(key)[2]; | 
| 80 |  | 
| 81 | 		++it2; | 
| 82 | 	} | 
| 83 |  | 
| 84 | 	// Save the vector | 
| 85 |     vd.save("vector_dist"  + std::to_string(create_vcluster().size()) + ".h5" ); | 
| 86 |  | 
| 87 |     vector_dist<dim,float, aggregate<float[dim]> > vd2(0,box,bc,ghost); | 
| 88 |  | 
| 89 |     vd2.load("vector_dist"  + std::to_string(create_vcluster().size())  + ".h5" ); | 
| 90 |  | 
| 91 |     // Check that vd and vd2 match | 
| 92 |  | 
| 93 |     auto it3 = vd.getDomainIterator(); | 
| 94 |  | 
| 95 |     BOOST_REQUIRE_EQUAL(vd.size_local(),vd2.size_local()); | 
| 96 |  | 
| 97 |     bool check = true; | 
| 98 | 	while (it3.isNext()) | 
| 99 | 	{ | 
| 100 | 		auto p = it3.get(); | 
| 101 |  | 
| 102 | 		Point<3,float> p1 = vd.getPos(p); | 
| 103 | 		Point<3,float> p2 = vd2.getPos(p); | 
| 104 |  | 
| 105 | 		check &= (p1 == p2); | 
| 106 |  | 
| 107 | 		check &= (vd.template getProp<0>(p)[0] == vd2.template getProp<0>(p)[0]); | 
| 108 | 		check &= (vd.template getProp<0>(p)[1] == vd2.template getProp<0>(p)[1]); | 
| 109 | 		check &= (vd.template getProp<0>(p)[2] == vd2.template getProp<0>(p)[2]); | 
| 110 |  | 
| 111 | 		++it3; | 
| 112 | 	} | 
| 113 |  | 
| 114 | 	BOOST_REQUIRE_EQUAL(check,true); | 
| 115 | } | 
| 116 |  | 
| 117 |  | 
| 118 |  | 
| 119 | BOOST_AUTO_TEST_CASE( vector_dist_hdf5_load_test ) | 
| 120 | { | 
| 121 | #ifndef SE_CLASS3 | 
| 122 |  | 
| 123 | 	Vcluster<> & v_cl = create_vcluster(); | 
| 124 |  | 
| 125 | 	Box<dim,float> box; | 
| 126 |  | 
| 127 | 	for (size_t i = 0; i < dim; i++) | 
| 128 | 	{ | 
| 129 | 		box.setLow(i,0.0); | 
| 130 | 		box.setHigh(i,1.0); | 
| 131 | 	} | 
| 132 |  | 
| 133 | 	// Boundary conditions | 
| 134 | 	size_t bc[dim]; | 
| 135 |  | 
| 136 | 	for (size_t i = 0; i < dim; i++) | 
| 137 | 		bc[i] = NON_PERIODIC; | 
| 138 |  | 
| 139 |  | 
| 140 | 	const size_t Ng = 32; | 
| 141 |  | 
| 142 | 	// ghost | 
| 143 | 	Ghost<dim,float> ghost(1.0/(Ng-2)); | 
| 144 |  | 
| 145 | 	vector_dist<dim,float, aggregate<float[dim]> > vd(0,box,bc,ghost); | 
| 146 |  | 
| 147 | 	// Load the vector | 
| 148 |     vd.load("test_data/vector_dist_24.h5" ); | 
| 149 |  | 
| 150 | 	/////////////////// Checking data /////////////////////// | 
| 151 |  | 
| 152 | 	// Check total number of particles | 
| 153 | 	size_t n_part = vd.size_local(); | 
| 154 | 	v_cl.sum(n_part); | 
| 155 | 	v_cl.execute(); | 
| 156 |  | 
| 157 | 	BOOST_REQUIRE_EQUAL(n_part,Ng*Ng*Ng); | 
| 158 |  | 
| 159 | 	// Check properties | 
| 160 |  | 
| 161 | 	auto it2 = vd.getDomainIterator(); | 
| 162 |  | 
| 163 | 	while (it2.isNext()) | 
| 164 | 	{ | 
| 165 | 		auto key = it2.get(); | 
| 166 |  | 
| 167 | 		// Check the properties | 
| 168 | 		for (size_t i = 0; i < dim; i++) | 
| 169 | 			BOOST_REQUIRE_EQUAL(vd.template getProp<0>(key)[i],(float)(0.51234 + vd.getPos(key)[0] + vd.getPos(key)[1]+ vd.getPos(key)[2])); | 
| 170 |  | 
| 171 | 		++it2; | 
| 172 | 	} | 
| 173 |  | 
| 174 | #endif | 
| 175 | } | 
| 176 |  | 
| 177 | BOOST_AUTO_TEST_SUITE_END() | 
| 178 |  | 
| 179 |  |