Proto  3.2
Proto_HDF5.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef PROTO_HDF5_H
3 #define PROTO_HDF5_H
4 #include "Proto_BoxData.H"
5 #ifdef PR_HDF5
6 #include "hdf5.h"
7 #ifdef PR_MMB
8 #include "../mmb/Proto_MBGraph.H"
9 #include "../mmb/Proto_MBProblemDomain.H"
10 #include "../mmb/Proto_MBDisjointBoxLayout.H"
11 #endif
12 #endif
13 
14 namespace Proto
15 {
16  template<typename T, unsigned int C, MemType MEM, Centering CTR>
17  class LevelBoxData;
18 
19 #ifdef PR_AMR
20  template<typename T, unsigned int C, MemType MEM, Centering CTR>
21  class AMRData;
22  template<typename T, unsigned int C, MemType MEM>
23  class LevelFluxRegister;
24 #endif
25 #ifdef PR_MMB
26  class MBGraph;
27  class MBProblemDomain;
28  template<typename MAP, MemType MEM>
29  class MBLevelMap;
30  template<typename T, unsigned int C, MemType MEM, Centering CTR>
31  class MBLevelBoxData;
32 #ifdef PR_AMR
33  template<typename MAP, MemType MEM>
34  class MBAMRMap;
35  template<typename T, unsigned int C, MemType MEM, Centering CTR>
36  class MBAMRData;
37 #endif
38 #endif
39 
40 #ifdef PR_HDF5
41  class HDF5Handler
42  {
43  public:
44 
45  /// Default Constructor
46  inline HDF5Handler();
47 
48  /// Read Level Box Data
49  /**
50  Read a LevelBoxData from an appropriately constructed HDF5 file. This function
51  should be compatible with files created using Chombo's HDF5 I/O system.
52 
53  The input LevelBoxData is REDEFINED when calling this function, and a new
54  DisjointBoxLayout is built. Because of this, knowledge of the way in which
55  the input data was constructed is not needed.
56 
57  The filename and following variadic arguments are used in the same way as
58  printf-style functions. For example:
59 
60  readLevel(data, "filename_%i.hdf5", 42) -> read from "filename_42.hdf5"
61 
62  Compatible with MPI if PR_MPI=TRUE.
63  */
64  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
65  inline void readLevel(LevelBoxData<T, C, MEM, CTR>& a_data,
66  std::string a_filename,
67  Args... a_params);
68 
69  /// Write Header
70  template<unsigned int C, Centering CTR>
71  void writeHeader(
72  hid_t* a_file,
73  int a_numLevels,
74  std::vector<std::string> a_varNames);
75 
76  /// Write Box Data
77  /**
78  Writes a single BoxData to an HDF5 file compatible with Chombo's HDF5 I/O and VisIt.
79 
80  The filename and following variadic arguments are used in the same way as
81  printf-style functions. For example:
82 
83  writePatch(data, {"rho", "vx", "vy"}, dx, "Euler_T%i.hdf5", 0) -> writes to "Euler_T0.hdf5"
84 
85  Ghost cells ARE printed, but appear with the rest of the data (they are not hidden by
86  default in VisIt).
87  */
88  template<typename T, unsigned int C, typename... Args>
89  inline void writePatch(
90  std::vector<std::string> a_varnames,
91  Array<double, DIM> a_dx,
92  const BoxData<T, C, HOST>& a_data,
93  std::string a_filename,
94  Args... a_params);
95 
96  template<typename T, unsigned int C, typename... Args>
97  inline void writePatch(
98  std::vector<std::string> a_varnames,
99  Array<double, DIM> a_dx,
100  const BoxData<T, C, DEVICE>& a_data,
101  std::string a_filename,
102  Args... a_params);
103 
104  /// Write Box Data (Scalar DX)
105  template<typename T, unsigned int C, MemType MEM, typename... Args>
106  inline void writePatch(
107  std::vector<std::string> a_varnames,
108  double a_dx,
109  const BoxData<T, C, MEM>& a_data,
110  std::string a_filename,
111  Args... a_params);
112 
113  template<typename T, unsigned int C, MemType MEM, typename... Args>
114  inline void writePatch(
115  Array<double, DIM> a_dx,
116  const BoxData<T, C, MEM>& a_data,
117  std::string a_filename,
118  Args... a_params);
119 
120  /// Write Box Data (Scalar DX)
121  template<typename T, unsigned int C, MemType MEM, typename... Args>
122  inline void writePatch(
123  double a_dx,
124  const BoxData<T, C, MEM>& a_data,
125  std::string a_filename,
126  Args... a_params);
127  /// Write Box Data (No DX)
128  /**
129  A convenient overload. Grid spacing defaults to 1.
130  */
131  template<typename T, unsigned int C, MemType MEM, typename... Args>
132  inline void writePatch(
133  std::vector<std::string> a_varnames,
134  const BoxData<T, C, MEM>& a_data,
135  std::string a_filename,
136  Args... a_params);
137 
138  /// Write Box Data (No DX, Varnames)
139  /**
140  A convenient overload. Grid spacing defaults to 1 and variable names are generated
141  automatically.
142  */
143  template<typename T, unsigned int C, MemType MEM, typename... Args>
144  inline void writePatch(const BoxData<T, C, MEM>& a_data,
145  std::string a_filename,
146  Args... a_params);
147 
148  /// Write Level Box Data
149  /**
150  Write's a LevelBoxData to an HDF5 file which is compatible with Chombo's HDF5 I/O
151  as well as VisIt.
152 
153  The filename and following variadic arguments are used in the same way as
154  printf-style functions. For example:
155 
156  writeLevel(data, {"rho", "vx", "vy"}, dx, "Euler_T%i.hdf5", 0) -> writes to "Euler_T0.hdf5"
157 
158  Compatible with MPI if PR_MPI=TRUE.
159  */
160  template<typename T, unsigned int C, Centering CTR, typename... Args>
161  inline void writeLevel(
162  std::vector<std::string> a_varnames,
163  Array<double, DIM> a_dx,
164  const LevelBoxData<T, C, HOST, CTR>& a_data,
165  std::string a_filename,
166  Args... a_params);
167 
168  template<typename T, unsigned int C, Centering CTR, typename... Args>
169  inline void writeLevel(
170  std::vector<std::string> a_varnames,
171  Array<double, DIM> a_dx,
172  const LevelBoxData<T, C, DEVICE, CTR>& a_data,
173  std::string a_filename,
174  Args... a_params);
175 
176  /// Write Level Box Data (scalar DX)
177  /**
178  A convenient overload. Grid spacing is isotropic.
179  */
180  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
181  inline void writeLevel(
182  std::vector<std::string> a_varnames,
183  double a_dx,
184  const LevelBoxData<T, C, MEM, CTR>& a_data,
185  std::string a_filename,
186  Args... a_params);
187 
188  /// Write Level Box Data (No Varnames)
189  /**
190  A convenient overload.
191  */
192  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
193  inline void writeLevel(
194  Array<double, DIM> a_dx,
195  const LevelBoxData<T, C, MEM, CTR>& a_data,
196  std::string a_filename,
197  Args... a_params);
198 
199  /// Write Level Box Data (No Varnames, scalar DX)
200  /**
201  A convenient overload. Grid spacing is isotropic.
202  */
203  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
204  inline void writeLevel(
205  double a_dx,
206  const LevelBoxData<T, C, MEM, CTR>& a_data,
207  std::string a_filename,
208  Args... a_params);
209 
210  /// Write Level Box Data (No DX)
211  /**
212  A convenient overload. Grid spacing defaults to 1.
213  */
214  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
215  inline void writeLevel(
216  std::vector<std::string> a_varnames,
217  const LevelBoxData<T, C, MEM, CTR>& a_data,
218  std::string a_filename,
219  Args... a_params);
220 
221  /// Write Level Box Data (No DX, Varnames)
222  /**
223  A convenient overload. Grid spacing defaults to 1 and variable names are generated
224  automatically.
225  */
226  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
227  inline void writeLevel(
228  const LevelBoxData<T, C, MEM, CTR>& a_data,
229  std::string a_filename,
230  Args... a_params);
231 #ifdef PR_AMR
232  /// Write AMR Hierarchy
233  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
234  inline void writeAMRData(
235  std::vector<std::string> a_varnames,
236  Array<double, DIM> a_dx,
237  const AMRData<T, C, MEM, CTR>& a_data,
238  std::string a_filename,
239  Args... a_params);
240 
241  /// Write AMR Hierarchy
242  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
243  inline void writeAMRData(
244  std::vector<std::string> a_varnames,
245  double a_dx,
246  const AMRData<T, C, MEM, CTR>& a_data,
247  std::string a_filename,
248  Args... a_params);
249 
250  /// Write AMR Hierarchy
251  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
252  inline void writeAMRData(
253  Array<double, DIM> a_dx,
254  const AMRData<T, C, MEM, CTR>& a_data,
255  std::string a_filename,
256  Args... a_params);
257 
258  /// Write AMR Hierarchy
259  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
260  inline void writeAMRData(
261  double a_dx,
262  const AMRData<T, C, MEM, CTR>& a_data,
263  std::string a_filename,
264  Args... a_params);
265 
266  /// Write Flux Register
267  template<typename T, unsigned int C, MemType MEM, typename... Args>
268  inline void writeFluxRegister(
269  std::vector<std::string> a_varnames,
270  Array<double, DIM> a_dx,
271  LevelFluxRegister<T, C, MEM>& a_register,
272  std::string a_filename,
273  Args... a_params);
274 
275  /// Write Flux Register
276  template<typename T, unsigned int C, MemType MEM, typename... Args>
277  inline void writeFluxRegister(
278  Array<double, DIM> a_dx,
279  LevelFluxRegister<T, C, MEM>& a_register,
280  std::string a_filename,
281  Args... a_params);
282 
283  /// Write Flux Register
284  template<typename T, unsigned int C, MemType MEM, typename... Args>
285  inline void writeFluxRegister(
286  LevelFluxRegister<T, C, MEM>& a_register,
287  std::string a_filename,
288  Args... a_params);
289 #endif
290 #ifdef PR_MMB
291  template<typename MAP, typename T, unsigned int C,
292  MemType MEM, Centering CTR, typename... Args>
293  inline void writeMBLevel(
294  std::vector<std::string> a_varNames,
295  const MBLevelMap<MAP, MEM>& a_map,
296  const MBLevelBoxData<T, C, MEM, CTR>& a_data,
297  std::string a_filename,
298  Args... a_params);
299 
300  template<typename MAP, typename T, unsigned int C,
301  MemType MEM, Centering CTR, typename... Args>
302  inline void writeMBLevel(
303  const MBLevelMap<MAP, MEM>& a_map,
304  const MBLevelBoxData<T, C, MEM, CTR>& a_data,
305  std::string a_filename,
306  Args... a_params);
307 
308  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
309  inline void writeMBLevel(
310  std::vector<std::string> a_varNames,
311  const MBLevelBoxData<T, C, MEM, CTR>& a_data,
312  std::string a_filename,
313  Args... a_params);
314 
315  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
316  inline void writeMBLevel(
317  const MBLevelBoxData<T, C, MEM, CTR>& a_data,
318  std::string a_filename,
319  Args... a_params);
320 
321  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
322  inline void writeMBLevelBoundsUnified(
323  std::vector<std::string> a_varNames,
324  const MBLevelBoxData<T, C, MEM, CTR>& a_data,
325  std::string a_filename,
326  Args... a_params);
327 
328  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
329  inline void writeMBLevelBounds(
330  std::vector<std::string> a_varNames,
331  const MBLevelBoxData<T, C, MEM, CTR>& a_data,
332  std::string a_filename,
333  Args... a_params);
334 
335  template<typename T, unsigned int C, MemType MEM, Centering CTR>
336  inline void addMBLevel(
337  hid_t* a_file,
338  const MBLevelBoxData<T, C, MEM, CTR>& a_data,
339  Array<double, DIM> a_dx,
340  Point a_refRatio,
341  int a_level);
342 
343  template<typename... Args>
344  inline void readMBLayout(
345  MBDisjointBoxLayout& a_layout,
346  std::shared_ptr<MBGraph> a_graph,
347  std::string a_filename,
348  Args... a_params);
349 
350  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
351  inline void readMBLevel(MBLevelBoxData<T, C, MEM, CTR>& a_data,
352  std::string a_filename,
353  Args... a_params);
354 
355 #ifdef PR_AMR
356  template<typename MAP, typename T, unsigned int C,
357  MemType MEM, Centering CTR, typename... Args>
358  inline void writeMBAMRData(
359  std::vector<std::string> a_varNames,
360  const MBAMRMap<MAP, MEM>& a_map,
361  const MBAMRData<T, C, MEM, CTR>& a_data,
362  std::string a_filename,
363  Args... a_params);
364 
365  template<typename T, unsigned int C, MemType MEM, Centering CTR, typename... Args>
366  inline void writeMBAMRData(
367  std::vector<std::string> a_varNames,
368  const MBAMRData<T, C, MEM, CTR>& a_data,
369  std::string a_filename,
370  Args... a_params);
371 
372 #endif
373 #endif
374  inline void setTime(double a_time) { m_time = a_time; }
375  inline void setTimestep(double a_dt) { m_dt = a_dt; }
376  inline double& time() { return m_time; }
377  inline double& dt() { return m_dt; }
378 
379  template<typename T>
380  inline static void getH5DataType(hid_t* a_type) {}
381 
382  private:
383 
384  static inline hid_t H5T_PROTO_POINT();
385  static inline hid_t H5T_PROTO_BOX();
386  static inline hid_t H5T_PROTO_STRING();
387 
388  double m_time = 0.0;
389  double m_dt = 1.0;
390 
391  template<typename T, unsigned int C, Centering CTR>
392  inline void addLevel(hid_t* a_file,
393  const LevelBoxData<T, C, DEVICE, CTR>& a_data,
394  Array<double, DIM>& a_dx0,
395  Point a_refRatio,
396  int a_level);
397 
398  template<typename T, unsigned int C, Centering CTR>
399  inline void addLevel(hid_t* a_file,
400  const LevelBoxData<T, C, HOST, CTR>& a_data,
401  Array<double, DIM>& a_dx0,
402  Point a_refRatio,
403  int a_level);
404 
405  template<typename T, unsigned int C, MemType MEM>
406  inline void addPatch(hid_t* a_file,
407  const BoxData<T, C, MEM>& a_data,
408  Array<double, DIM>& a_dx0,
409  Point a_ghost);
410 
411  }; // end class HDF5Handler
412 #include "implem/Proto_HDF5Implem.H"
413 #endif
414 } // end namespace Proto
415 #endif //end of include guard
Flux Register.
Definition: Proto_LevelFluxRegister.H:13
Multiblock AMR Data.
Definition: Proto_MBAMRData.H:12
Graph of a mapped multiblock domain. Nodes represent blocks and arcs represent boundaries between blo...
Definition: Proto_MBGraph.H:105
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:314
Single Level Mapped Multiblock Map.
Definition: Proto_MBLevelBoxData.H:19
MemType
Definition: Proto_MemType.H:7
Level Box Data.
Definition: Proto_HDF5.H:17
Multiblock Level Box Data.
Definition: Proto_MBLevelBoxData.H:17
AMR Data Hierarchy.
Definition: Proto_AMRData.H:23
Mapped Multi-Block Problem Domain.
Definition: Proto_MBProblemDomain.H:76
Definition: Proto_Array.H:17
Integer Valued Vector.
Definition: Proto_Point.H:24
Definition: Proto_MBDisjointBoxLayout.H:14
Definition: Proto_MBAMRMap.H:11
Centering
Definition: Proto_Centering.H:7