OpenFPM_io  0.2.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Functions Variables Typedefs
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.hpp"
14 
27 template<typename ele_v, bool has_name>
29 {
30  // HDF5 file
31  hid_t file_id;
32 
33  // vector that we are processing
34  ele_v & vv;
35 
36  // Up to which element to write
37  size_t stop;
38 
44  H5_prop_out(hid_t file_id, ele_v & vv, size_t stop)
45  :file_id(file_id),vv(vv),stop(stop)
46  {};
47 
49  template<typename T>
50  void operator()(T& t) const
51  {
52  typedef typename boost::mpl::at<typename ele_v::value_type::value_type::type,boost::mpl::int_<T::value>>::type ptype;
53 
54  H5_write<ptype,T::value,ele_v>::write(file_id,std::string(ele_v::value_type::attributes::names[T::value]),vv,stop);
55  }
56 };
57 
58 
59 
71 template<typename ele_v>
72 struct H5_prop_out<ele_v,false>
73 {
74  // HDF5 file
75  hid_t file_id;
76 
77  // vector that we are processing
78  ele_v & vv;
79 
80  // Up to which element to write
81  size_t stop;
82 
88  H5_prop_out(hid_t file_id, ele_v & vv, size_t stop)
89  :file_id(file_id),vv(vv),stop(stop)
90  {};
91 
93  template<typename T>
94  void operator()(T& t) const
95  {
96  typedef typename boost::mpl::at<typename ele_v::value_type::type,boost::mpl::int_<T::value>>::type ptype;
97 
98  H5_write<ptype,T::value,ele_v>::write(file_id,std::string("attr") + std::to_string(T::value),vv,stop);
99  }
100 };
101 
102 template <>
103 class HDF5_XdmfWriter<H5_POINTSET>
104 {
105  // Time step
106  int t;
107 
109  hid_t file_id;
110 
111 public:
112 
119  :t(0)
120  {}
121 
122 
136  template<typename VPos, typename VPrp, int ... prp > bool write(const std::string & file, openfpm::vector<VPos> & v_pos, openfpm::vector<VPrp> & v_prp, size_t stop)
137  {
138  Vcluster & v_cl = *global_v_cluster;
139 
140  // Open and HDF5 file in parallel
141 
142  hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
143  H5Pset_fapl_mpio(plist_id, v_cl.getMPIComm(), MPI_INFO_NULL);
144  file_id = H5Fcreate(file.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
145  H5Pclose(plist_id);
146 
147  // Single coordinate positional vector
148  openfpm::vector<typename VPos::coord_type> x_n;
149  x_n.resize(stop);
150 
151  //for each component, fill x_n
152  for (size_t i = 0 ; i < VPos::dims ; i++)
153  {
154  //
155  for (size_t j = 0 ; j < stop ; j++)
156  x_n.get(j) = v_pos.template get<0>(j)[i];
157 
158  std::stringstream str;
159  str << "x" << i;
160 
161  HDF5CreateDataSet<typename VPos::coord_type>(file_id,str.str(),x_n.getPointer(),stop*sizeof(typename VPos::coord_type));
162  }
163 
164  // Now we write the properties
165 
166  typedef typename to_boost_vmpl<prp ... >::type v_prp_seq;
167  H5_prop_out<openfpm::vector<VPrp>,has_attributes<VPrp>::value> f(file_id,v_prp,stop);
168 
169  boost::mpl::for_each_ref<v_prp_seq>(f);
170 
171  H5Fclose(file_id);
172 
173  return true;
174  }
175 };
176 
177 
178 #endif /* OPENFPM_IO_SRC_HDF5_XDMFWRITER_HDF5_XDMFWRITER_POINT_SET_HPP_ */
H5_prop_out(hid_t file_id, ele_v &vv, size_t stop)
constructor
bool write(const std::string &file, openfpm::vector< VPos > &v_pos, openfpm::vector< VPrp > &v_prp, size_t stop)
Write a set of particle position and properties into HDF5.
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
void operator()(T &t) const
It produce an output for each property.
static void write(hid_t file_id, const std::string &str, V &v, size_t stop)
write