OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
HDF5_XdmfWriter_point_set.hpp
1/*
2 * H5PartWriter_point_set.hpp
3 *
4 * Created on: Feb 7, 2016
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_IO_SRC_HDF5_XDMFWRITER_HDF5_XDMFWRITER_POINT_SET_HPP_
9#define OPENFPM_IO_SRC_HDF5_XDMFWRITER_HDF5_XDMFWRITER_POINT_SET_HPP_
10
11#include "HDF5_XdmfWriter_util.hpp"
12#include "Vector/map_vector.hpp"
13#include "VCluster/VCluster.hpp"
14
27template<typename ele_v, bool has_name>
29{
31 hid_t file_id;
32
34 ele_v & vv;
35
37 size_t stop;
38
44 H5_prop_out(hid_t file_id, ele_v & vv, size_t stop)
46 {};
47
53 template<typename T>
54 void operator()(T& t) const
55 {
56 typedef typename boost::mpl::at<typename ele_v::value_type::value_type::type,boost::mpl::int_<T::value>>::type ptype;
57
58 H5_write<ptype,T::value,ele_v>::write(file_id,std::string(ele_v::value_type::attributes::names[T::value]),vv,stop);
59 }
60};
61
62
63
75template<typename ele_v>
76struct H5_prop_out<ele_v,false>
77{
79 hid_t file_id;
80
82 ele_v & vv;
83
85 size_t stop;
86
94 H5_prop_out(hid_t file_id, ele_v & vv, size_t stop)
96 {};
97
103 template<typename T>
104 void operator()(T& t) const
105 {
106 typedef typename boost::mpl::at<typename ele_v::value_type::type,boost::mpl::int_<T::value>>::type ptype;
107
108 H5_write<ptype,T::value,ele_v>::write(file_id,std::string("attr") + std::to_string(T::value),vv,stop);
109 }
110};
111
116template <>
117class HDF5_XdmfWriter<H5_POINTSET>
118{
120 hid_t file_id;
121
122public:
123
130 {}
131
132
147 template<typename VPos, typename VPrp, int ... prp >
148 bool write(const std::string & file,
149 openfpm::vector<VPos> & v_pos,
150 openfpm::vector<VPrp> & v_prp,
151 size_t stop)
152 {
153 Vcluster & v_cl = create_vcluster();
154
155 // Open and HDF5 file in parallel
156
157 hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
158 H5Pset_fapl_mpio(plist_id, v_cl.getMPIComm(), MPI_INFO_NULL);
159 file_id = H5Fcreate(file.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
160 H5Pclose(plist_id);
161
162 // Single coordinate positional vector
164 x_n.resize(stop);
165
166 //for each component, fill x_n
167 for (size_t i = 0 ; i < VPos::dims ; i++)
168 {
169 //
170 for (size_t j = 0 ; j < stop ; j++)
171 x_n.get(j) = v_pos.template get<0>(j)[i];
172
173 std::stringstream str;
174 str << "x" << i;
175
176 HDF5CreateDataSet<typename VPos::coord_type>(file_id,str.str(),x_n.getPointer(),stop*sizeof(typename VPos::coord_type));
177 }
178
179 // Now we write the properties
180
181 typedef typename to_boost_vmpl<prp ... >::type v_prp_seq;
183
184 boost::mpl::for_each_ref<v_prp_seq>(f);
185
186 H5Fclose(file_id);
187
188 return true;
189 }
190};
191
192
193#endif /* OPENFPM_IO_SRC_HDF5_XDMFWRITER_HDF5_XDMFWRITER_POINT_SET_HPP_ */
bool write(const std::string &file, openfpm::vector< VPos > &v_pos, openfpm::vector< VPrp > &v_prp, size_t stop)
Write a set of particle positions and properties into HDF5.
MPI_Comm getMPIComm()
Get the MPI_Communicator (or processor group) this VCluster is using.
Implementation of VCluster class.
Definition VCluster.hpp:59
Implementation of 1-D std::vector like structure.
ele_v & vv
vector that we are processing
size_t stop
Up to which element to write.
void operator()(T &t) const
It produce an output for each property.
H5_prop_out(hid_t file_id, ele_v &vv, size_t stop)
constructor
this class is a functor for "for_each" algorithm
H5_prop_out(hid_t file_id, ele_v &vv, size_t stop)
constructor
size_t stop
Up to which element to write.
void operator()(T &t) const
It produce an output for each property.
ele_v & vv
vector that we are processing
static void write(hid_t file_id, const std::string &str, V &v, size_t stop)
write