Chombo + EB  3.0
CH_HDF5.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _CH_HDF5_H_
12 #define _CH_HDF5_H_
13 
14 #define CHOFFSET(object, member) (int)((char*)&(object.member) - (char*)&object)
15 
16 #ifdef CH_USE_HDF5 // if you don't have CH_USE_HDF5, then this file is useless
17 
18 #include <iostream>
19 using std::cout;
20 using std::endl;
21 
22 #ifdef CH_MPI
23 #include <mpi.h>
24 #endif
25 
26 #include "LevelData.H"
27 #include "HDF5Portable.H"
28 // hdf5 #defines inline.... duh!
29 #undef inline
30 #include <string>
31 #include <map>
32 #include "RealVect.H"
33 #include "CH_Timer.H"
34 #include "LoadBalance.H"
35 #include "LayoutIterator.H"
36 #include "Vector.H"
37 #include "memtrack.H"
38 #include "FluxBox.H"
39 
40 #ifdef CH_MULTIDIM
41 #include "BoxTools_ExternC_Mangler.H" // Generated by lib/utils/multidim/mangle_externs.sh
42 #endif
43 #include "NamespaceHeader.H"
44 
45 
46 template <class T>
47 void read(T& item, Vector<Vector<char> >& a_allocatedBuffers, const Box& box,
48  const Interval& comps)
49 {
50  Vector<void*> b(a_allocatedBuffers.size());
51  for (int i=0; i<b.size(); ++i) b[i]= &(a_allocatedBuffers[i][0]);
52  read(item, b, box, comps);
53 }
54 
55 using std::map;
56 
57 class HDF5Handle;
58 
59 // CH_HDF5.H
60 // ============
61 
62 /// user-friendly function to write out data on a AMR level
63 /**
64  all data is IN data.
65  a_handle: handle open and ready.
66  a_data: data, what else do you want to know ?
67  a_dx: the grid spacing at this level
68  a_dt: the timestep size that was last completed
69  a_time: the time of this level (might not be the same as other levels)
70  a_domain: the problem domain, represented at this level of refinement
71  a_refRatio:the refinement of a_level+1 wrt a_level. for vis systems it
72  would probably help if you use 1 for a_level==max_level.
73 */
74 template <class T>
75 int writeLevel(HDF5Handle& a_handle,
76  const int& a_level,
77  const T& a_data,
78  const Real& a_dx,
79  const Real& a_dt,
80  const Real& a_time,
81  const Box& a_domain,
82  const int& a_refRatio,
83  const IntVect& outputGhost = IntVect::Zero,
84  const Interval& comps = Interval());
85 
86 template <class T>
87 int readLevel(HDF5Handle& a_handle,
88  const int& a_level,
89  LevelData<T>& a_data,
90  Real& a_dx,
91  Real& a_dt,
92  Real& a_time,
93  Box& a_domain,
94  int& a_refRatio,
95  const Interval& a_comps = Interval(),
96  bool setGhost = false);
97 
98 // More basic HDF5 functions. These can be used at a persons own
99 // discretion. Refer to the User's Guide for a description of how these
100 // functions interact with the convenience functions writeLevel, etc.
101 
102 /// writes BoxLayout to HDF5 file.
103 /**
104  Writes BoxLayout to HDF5 file. Only one BoxLayout per group is permitted, this operation overwrites
105  previous entries.
106  This operation assumes boxes are cell-centered.\\
107  returns: success: 0\\
108  HDF5 error: negative error code.\\
109 */
110 int write(HDF5Handle& a_handle,
111  const BoxLayout& a_layout,
112  const std::string& name = "boxes");
113 
114 /// writes a BoxLayoutData<T> to an HDF5 file.
115 /**
116  writes a BoxLayoutData<T> to an HDF5 file.\\
117  returns: success: 0\\
118  HDF5 error: negative error code.\\
119 */
120 template <class T>
121 int write(HDF5Handle& a_handle,
122  const BoxLayoutData<T>& a_data,
123  const std::string& a_name,
124  IntVect outputGhost = IntVect::Zero,
125  const Interval& comps = Interval(),
126  bool newForm = false);
127 
128 /// writes a LevelData<T> to an HDF5 file.
129 /**
130  Writes a LevelData<T> to an HDF5 file.
131  the DisjointBoxLayout is not written out with the data, the user is required to
132  handle that object seperately. (see the "read" interface below).\\
133  returns: success: 0\\
134  HDF5 error: negative error code.\\
135 */
136 template <class T>
137 int write(HDF5Handle& a_handle,
138  const LevelData<T>& a_data,
139  const std::string& a_name,
140  const IntVect& outputGhost = IntVect::Zero,
141  const Interval& comps = Interval());
142 
143 /// reads Vector<Box> from location specified by a_handle.
144 /**
145  Reads BoxLayout from the group specified by a_handle.
146  Only one BoxLayout per group is permitted, this operation overwrites.
147  This operation assumes boxes are cell-centered.\\
148  returns: success: 0\\
149  HDF5 error: negative error code.\\
150 
151  Arg name refers to the name of an HDF5 dataset in which the boxes you want
152  are stored in a particular format, which is the one used to output DataLayouts
153  to HDF5. Here is an example of that format (as shown by h5dump):
154 
155  DATASET "datalayout" {
156  DATATYPE H5T_COMPOUND {
157  H5T_STD_I32LE "lo_i";
158  H5T_STD_I32LE "lo_j";
159  H5T_STD_I32LE "hi_i";
160  H5T_STD_I32LE "hi_j";
161  }
162  DATASPACE SIMPLE { ( 2 ) / ( 2 ) }
163  DATA {
164  (0): {
165  0,
166  0,
167  1,
168  0
169  },
170  (1): {
171  2,
172  0,
173  2,
174  1
175  }
176  }
177  }
178 
179 */
180 int read(HDF5Handle& a_handle,
181  Vector<Box>& boxes,
182  const std::string& name = "boxes");
183 
184 /// reads the set of Boxes out from the level_* groups of a Chombo HDF5 AMR file
185 /**
186  goes to all groups named level_n for level n = 0 to numLevel and fills the
187  vector of boxes. CH_HDF5.Handle must be set to the root group (the default location when the
188  file is just opened.
189 
190  A handy *get everything* version of int read(HDF5Handle& a_handle, Vector<Box>& boxes)
191 */
192 int readBoxes(HDF5Handle& a_handle,
193  Vector<Vector<Box> >& boxes);
194 
195 /// FArrayBox-at-a-time read function. FArrayBox gets redefined in the function. Reads data field named by a_dataName.
196 /** FArrayBox gets redefined in the function.
197  it will be sized to the box at the [level,boxNumber] position and have components
198  the go from [0,a_components.size()-1]
199 
200  some meta-data has to be read again and again internally to do this function, but
201  it should make some out-of-core tools possible.
202 */
203 
204 int readFArrayBox(HDF5Handle& a_handle,
205  FArrayBox& a_fab,
206  int a_level,
207  int a_boxNumber,
208  const Interval& a_components,
209  const std::string& a_dataName = "data" );
210 
211 /// read BoxLayoutData named a_name from location specified by a_handle.
212 /**
213  Read BoxLayoutData named a_name from location specified by a_handle. User must supply the correct BoxLayout for this function if redefineData == true. \\
214  returns: success: 0\\
215  bad location: 1\\
216  HDF5 error: negative error code.\\
217 */
218 template <class T>
219 int read(HDF5Handle& a_handle,
220  BoxLayoutData<T>& a_data,
221  const std::string& a_name,
222  const BoxLayout& a_layout,
223  const Interval& a_comps = Interval(),
224  bool redefineData = true);
225 
226 /// read LevelData named a_name from location specified by a_handle.
227 /**
228 
229  Read LevelData named a_name from location specified by a_handle.
230  User must supply the correct BoxLayout for this function.
231 
232  Arg a_name is significant: the HDF5 group to which a_handle is set is
233  is assumed to contain a dataset called <a_name>:datatype=<some integer>,
234  a dataset called <a_name>:offsets=<some integer>, and a subgroup named
235  <a_name>_attributes. You will have all these items if you dumped your
236  LevelData out using the corresponding write() function defined here.
237 
238  If arg redefineData==false, then the user must pass in a valid LevelData.
239  Otherwise, this function figures out how many components and ghost cells there
240  are, and allocates the correct amount of space. The actual FArray data held
241  by the LevelData gets filled in here, regardless of redefineData; "redefine"
242  alludes to the family of define() functions.
243 
244  returns: success: 0\\
245  bad location: 1\\
246  HDF5 error: negative error code.\\
247 */
248 template <class T>
249 int read(HDF5Handle& a_handle,
250  LevelData<T>& a_data,
251  const std::string& a_name,
252  const DisjointBoxLayout& a_layout,
253  const Interval& a_comps = Interval(),
254  bool redefineData = true);
255 
256 /// Handle to a particular group in an HDF file.
257 /**
258  HDF5Handle is a handle to a particular group in an HDF file. Upon
259  construction, group is defined to be the root. All data is
260  written and read assuming the native representations for data on
261  the architecture it is running on. When a file is opened, these
262  settings are checked and an error is flagged when things don't
263  match up. It is the USER'S responsibility to close() this object
264  when it is no longer needed.
265 
266 */
268 {
269 public:
270  ///
271  /**
272  Enumeration of opening modes for HDF5 files. \\
273 
274  CREATE: file is created if it didn't exist, or an existing file of
275  the same name is clobbered.\\
276 
277  CREATE_SERIAL: in serial execution this is equivalent to CREATE. In parallel this opens
278  a file just on this particular calling processor. Working with LevelData and this kind of
279  file is difficult to get right and most users will not use this mode. \\
280 
281  OPEN_RDONLY: existing file is opened in read-only mode. If the
282  file doesn't already exist then open fails and isOpen() returns
283  false.\\
284 
285  OPEN_RDWR: existing file is opened in read-write mode. If the file
286  doesn't already exist then open fails and isOpen() returns false.\\
287 
288  */
289  enum mode
290  {
295  };
296 
297  /// {\bf constructor}
298 
299  ///
300  /**
301  Default constructor. User must call open() prior to using
302  constructed object.
303  */
304  HDF5Handle();
305 
306  ///
307  /** Opens file and sets the current group to the root "/" group. \\
308 
309  if mode == CREATE, then file is created if it didn't exist, or an
310  existing file of the same name is clobbered.\\
311 
312  if mode == OPEN_*, then existing file is opened, if the file doesn't
313  already exist then open fails and isOpen() returns false.\\
314 
315  Writes basic information such as SpaceDim and testReal to a global
316  group. The global group is named Chombo_global in the call signature
317  where no globalGroupName is passed.\\
318  */
319  HDF5Handle(
320  const std::string& a_filename,
321  mode a_mode,
322  const char *a_globalGroupName="Chombo_global");
323 
324  // HDF5Handle(const std::string& a_filename, mode a_mode);
325 
326  ~HDF5Handle();
327 
328  /// {\bf File functions}
329 
330  ///
331  /**
332  Opens file and sets the current group of this HDF5Handle to the
333  root "/" group. File that this HDF5Handle previously pointed at is
334  NOT closed, that is the users responsibility.\\
335 
336  if mode == CREATE, then file is created if it didn't exist, or an
337  existing file of the same name is clobbered.\\
338 
339  if mode == OPEN_*, then existing file is opened, if the file doesn't
340  already exist then open fails and isOpen() returns false.\\
341 
342  Writes basic information such as SpaceDim and testReal to a global
343  group. The global group is named Chombo_global in the call signature
344  where no globalGroupName is passed.\\
345 
346  returns:\\
347  0 on success\\
348  negative number if file open failed (return code from HDF5)\\
349  1 file does not appear to contain datacheck info, probably not a Chombo file\\
350  2 on data bit size differences between code and file.\\
351 
352  aborts on SpaceDim not matching between code and file\\
353 
354  */
355  int open(
356  const std::string& a_filename,
357  mode a_mode,
358  const char *a_globalGroupName="Chombo_global");
359 
360  // int open(const std::string& a_filename, mode a_mode);
361 
362  ///
363  /**
364  A NULL or failed constructed HDF5Handle will return false.
365  */
366  bool isOpen() const;
367 
368  ///
369  /**
370  Closes the file. Must be called to close file. Files are not
371  automatically closed.
372 
373  */
374  void close();
375 
376  /// {\bf Group functions}
377 
378  ///
379  /**
380  Sets the current group to be "/level_x" where x=a_level.
381  */
382  void setGroupToLevel(int a_level);
383 
384  ///
385  /**
386  Set group to users choice, referenced from file root.
387  groupAbsPath will look like a Unix file path:
388  "/mySpecialData/group1/" "/" is the root group of the
389  file. returns a negative value on failure
390 
391  */
392  int setGroup(const std::string& groupAbsPath);
393 
394  ///
395  /**
396  Add the indicated string to the group path. For example, if
397  getGroup() returns "/foo" then after pushGroup("bar"), getGroup()
398  will return "/foo/bar".
399  Return value is whatever the internal setGroup returns.
400  */
401  int pushGroup( const std::string& grp );
402 
403  ///
404  /**
405  Pop off the last element of the group path. For example, "/foo/bar"
406  becomes "/foo". It's an error to call this function if the group,
407  going in, is "/".
408  Return value is whatever the internal setGroup returns, when we call
409  it to reset the group's path.
410  */
411  int popGroup();
412 
413  ///
414  /**
415  Returns name of current group. groupAbsPath will look like a Unix
416  file path: "/mySpecialData/group1/" "/" is the root group of the
417  file.
418 
419  */
420  const std::string& getGroup() const;
421 
422  const hid_t& fileID() const;
423  const hid_t& groupID() const;
424  static hid_t box_id;
425  static hid_t intvect_id;
426  static hid_t realvect_id;
427  static map<std::string, std::string> groups;
428 
429 private:
430 
431  HDF5Handle(const HDF5Handle&);
433 
434  hid_t m_fileID;
436  bool m_isOpen;
437  std::string m_filename; // keep around for debugging
438  std::string m_group;
439  int m_level;
440 
441  // static hid_t file_access;
442  static bool initialized;
443  static void initialize();
444 
445 };
446 
447 /// data to be added to HDF5 files.
448 /**
449  HDF5HeaderData is a wrapper for some data maps to be added to HDF5
450  files. instead of an overdose of access functions, the maps are
451  made public and they can be manipulated by the user at will. They
452  maintain type safety.
453 
454  to add a Real data entry, a user can simply program as follows:
455 
456  <PRE>
457  Real dx;
458  .
459  .
460  HDF5HeaderData metaData;
461  metaData.m_real["dx"] = dx;
462  </PRE>
463 
464  If "dx" already existed, then it is overwritten, otherwise an entry is
465  created and added with the new value;
466 
467  To search for entries, the user does the following:
468  <PRE>
469 
470  HDF5HeaderData metaData;
471  HDF5Handle currentStep(filename);
472  currentStep.setGroupToLevel(0);
473  metaData.readFromFile(currentStep);
474  if (metaData.m_intvect.find("ghost") != metaData.m_intvect.end())
475  ghost = metaData.m_intvect["ghost"];
476  else
477  ghost = defaultGhostIntVect;
478 
479  </PRE>
480 
481  A user can skip the check for existence if they have reason to "know" the
482  data will be there. It is just good coding practice.
483 
484  To erase an entry, you can use:
485  <PRE>
486  metaData.m_real.erase("dx");
487  </PRE>
488 
489 */
491 {
492 public:
493 
494  ///
495  /**
496  Writes this HDF5HeaderData's current attribute list to the
497  current group in 'file.' Returns 0 on success, returns the
498  error code from HDF5 on failure.
499 
500  */
501  int writeToFile(HDF5Handle& file) const;
502 
503  ///
504  /**
505  Reads into this HDF5HeaderData's attribute list from file. Read
506  process is add/change, does not remove key-value pairs. Reads
507  from current group. Returns 0 on success, positive number if a
508  particular member of group caused an error, negative on general
509  error.
510 
511  */
512  int readFromFile(HDF5Handle& file);
513 
514  ///
515  void clear();
516 
517  ///
518  map<std::string, Real> m_real;
519 
520  ///
521  map<std::string, int> m_int;
522 
523  ///
524  map<std::string, std::string> m_string;
525 
526  ///
527  map<std::string, IntVect> m_intvect;
528 
529  ///
530  map<std::string, Box> m_box;
531 
532  ///
533  map<std::string, RealVect> m_realvect;
534 
535  //users should not need these functions in general
536 
537  int writeToLocation(hid_t loc_id) const;
538  int readFromLocation(hid_t loc_id);
539 
540  /// useful for debugging. dumps contents to std::cout
541  void dump() const;
542 
543 private:
544  static herr_t attributeScan(hid_t loc_id, const char *name, void *opdata);
545 };
546 
547 extern "C"
548 {
549  herr_t HDF5HeaderDataattributeScan(hid_t loc_id, const char *name, void *opdata);
550 }
551 
552 std::ostream& operator<<(std::ostream& os, const HDF5HeaderData& data);
553 
554 //=============================================================================
555 //
556 // end of declarations.
557 //
558 //=============================================================================
559 
560 #if ( H5_VERS_MAJOR == 1 && H5_VERS_MINOR > 6 )
561 typedef hsize_t ch_offset_t;
562 #else
563 #if ( H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 6 && H5_VERS_RELEASE >= 4 )
564 typedef hsize_t ch_offset_t;
565 #else
566 typedef hssize_t ch_offset_t;
567 #endif
568 #endif
569 
570 
571 template<class T>
572 hid_t H5Type(const T* dummy);
573 
574 template< >
575 hid_t H5Type(const int* dummy);
576 
577 template< >
578 hid_t H5Type(const long long* dummy);
579 
580 template< >
581 hid_t H5Type(const float* dummy);
582 
583 template< >
584 hid_t H5Type(const double* dummy);
585 
586 template< >
587 hid_t H5Type(const Box* dummy);
588 
589 template< >
590 hid_t H5Type(const RealVect* dummy);
591 
592 template< >
593 hid_t H5Type(const IntVect* dummy);
594 
595 template<class T>
596 hid_t H5Type(const T* dummy)
597 {
598  // no such definition;
599  MayDay::Error(" H5Type(const T* dummy)");
600  return -4;
601 }
602 
603 
604 void createData(hid_t& a_dataset,
605  hid_t& a_dataspace,
606  HDF5Handle& handle,
607  const std::string& name,
608  hid_t type,
609  hsize_t size);
610 
611 template <class T>
612 void createDataset(hid_t& a_dataset,
613  hid_t& a_dataspace,
614  HDF5Handle& handle,
615  const std::string& name,
616  const T* dummy,
617  hsize_t size)
618 {
619  createData(a_dataset, a_dataspace, handle, name, H5Type(dummy), size);
620 
621 }
622 
623 void writeDataset(hid_t a_dataset,
624  hid_t a_dataspace,
625  const void* start,
626  ch_offset_t off,
627  hsize_t count);
628 
629 void readDataset(hid_t a_dataset,
630  hid_t a_dataspace,
631  void* start,
632  ch_offset_t off,
633  hsize_t count);
634 
635 // non-user code used in implementation of communication
636 
638 {
641  void operator=(const OffsetBuffer& rhs);
642 };
643 
644 ostream& operator<<(ostream& os, const OffsetBuffer& ob);
645 
646 
647 #include "NamespaceFooter.H"
648 
649 #include "BaseNamespaceHeader.H"
650 
651 #include "NamespaceVar.H"
652 
653 //OffsetBuffer specialization of linearSize
654 template < >
655 int linearSize(const CH_XDIR::OffsetBuffer& a_input);
656 
657 //OffsetBuffer specialization of linearIn
658 template < >
659 void linearIn(CH_XDIR::OffsetBuffer& a_outputT, const void* const a_inBuf);
660 
661 //OffsetBuffer specialization of linearOut
662 template < >
663 void linearOut(void* const a_outBuf, const CH_XDIR::OffsetBuffer& a_inputT);
664 
665 template < > int linearSize(const Vector<CH_XDIR::OffsetBuffer>& a_input);
666 template < > void linearIn(Vector<CH_XDIR::OffsetBuffer>& a_outputT, const void* const inBuf);
667 template < > void linearOut(void* const a_outBuf, const Vector<CH_XDIR::OffsetBuffer>& a_inputT);
668 
669 
670 #include "BaseNamespaceFooter.H"
671 #include "NamespaceHeader.H"
672 
673 // First, template specializations for read/write for FArrayBox.
674 
675 template <>
676 inline void dataTypes(Vector<hid_t>& a_types, const BaseFab<int>& dummy)
677 {
678  a_types.resize(1);
679  a_types[0] = H5T_NATIVE_INT;
680 }
681 
682 template <>
683 inline void dataTypes(Vector<hid_t>& a_types, const BaseFab<char>& dummy)
684 {
685  a_types.resize(1);
686  a_types[0] = H5T_NATIVE_CHAR;
687 }
688 
689 /* since many compilers choke on the proper template specialization syntax
690  I am forced to pass in a dummy specialization argument
691 */
692 template <>
693 inline void dataTypes(Vector<hid_t>& a_types, const FArrayBox& dummy)
694 {
695  a_types.resize(1);
696  a_types[0] = H5T_NATIVE_REAL;
697 }
698 
699 template <>
700 inline void dataTypes(Vector<hid_t>& a_types, const FluxBox& dummy)
701 {
702  a_types.resize(1);
703  a_types[0] = H5T_NATIVE_REAL;
704 }
705 
706 template <>
707 inline void dataSize(const BaseFab<int>& item, Vector<int>& a_sizes,
708  const Box& box, const Interval& comps)
709 {
710  a_sizes[0] = box.numPts() * comps.size();
711 }
712 
713 template <>
714 inline void dataSize(const BaseFab<char>& item, Vector<int>& a_sizes,
715  const Box& box, const Interval& comps)
716 {
717  a_sizes[0] = box.numPts() * comps.size();
718 }
719 
720 template <>
721 inline void dataSize(const FArrayBox& item, Vector<int>& a_sizes,
722  const Box& box, const Interval& comps)
723 {
724  a_sizes[0] = box.numPts() * comps.size();
725 }
726 
727 template <>
728 inline void dataSize(const FluxBox& item, Vector<int>& a_sizes,
729  const Box& box, const Interval& comps)
730 {
731  int& t = a_sizes[0];
732  t = 0;
733  for (int dir =0; dir<CH_SPACEDIM; dir++)
734  {
735  Box edgeBox(surroundingNodes(box,dir));
736  t += edgeBox.numPts()*comps.size();
737  }
738 }
739 
740 template <>
741 inline const char* name(const FArrayBox& a_dummySpecializationArg)
742 {
743  // Attempt to get rid of warnings on IBM...
744  //static const char* name = "FArrayBox";
745  const char* name = "FArrayBox";
746  return name;
747 }
748 
749 template <>
750 inline const char* name(const BaseFab<int>& a_dummySpecializationArg)
751 {
752  // Attempt to get rid of warnings on IBM...
753  //static const char* name = "BaseFab<int>";
754  const char* name = "BaseFab<int>";
755  return name;
756 }
757 
758 template <>
759 inline const char* name(const BaseFab<char>& a_dummySpecializationArg)
760 {
761  // Attempt to get rid of warnings on IBM...
762  //static const char* name = "BaseFab<int>";
763  const char* name = "BaseFab<char>";
764  return name;
765 }
766 //
767 // now, generic, non-binary portable version of template functions
768 // for people who just want ot rely on linearIn/linearOut
769 
770 template <class T>
771 inline void dataTypes(Vector<hid_t>& a_types, const T& dummy)
772 {
773  a_types.resize(1);
774  a_types[0] = H5T_NATIVE_CHAR;
775 }
776 
777 template <class T>
778 inline void dataSize(const T& item, Vector<int>& a_sizes,
779  const Box& box, const Interval& comps)
780 {
781  a_sizes[0] = item.size(box, comps);
782 }
783 
784 template <class T>
785 inline void write(const T& item, Vector<void*>& a_allocatedBuffers,
786  const Box& box, const Interval& comps)
787 {
788  item.linearOut(a_allocatedBuffers[0], box, comps);
789 }
790 
791 template <class T>
792 inline void read(T& item, Vector<void*>& a_allocatedBuffers,
793  const Box& box, const Interval& comps)
794 {
795  item.linearIn(a_allocatedBuffers[0], box, comps);
796 }
797 
798 template <class T>
799 inline const char* name(const T& a_dummySpecializationArg)
800 {
801  static const char* name = "unknown";
802  return name;
803 }
804 
805 template <class T>
806 void getOffsets(Vector<Vector<long long> >& offsets, const BoxLayoutData<T>& a_data,
807  int types, const Interval& comps, const IntVect& outputGhost)
808 {
809  const BoxLayout& layout = a_data.boxLayout();
810  offsets.resize(types, Vector<long long>(layout.size()+1));
811  // offsets.resize(layout.size() + 1, Vector<long long>(types));
812  for (int t=0; t<types; t++) offsets[t][0] = 0;
813  Vector<int> thisSize(types);
814  if (T::preAllocatable()==0)
815  { // static preAllocatable
816  T dummy;
817  unsigned int index = 1;
818  for (LayoutIterator it(layout.layoutIterator()); it.ok(); ++it)
819  {
820  Box region = layout[it()];
821  region.grow(outputGhost);
822  dataSize(dummy, thisSize, region, comps);
823  for (unsigned int i=0; i<thisSize.size(); ++i)
824  {
825  //offsets[index][i] = offsets[index-1][i] + thisSize[i];
826  offsets[i][index] = offsets[i][index-1] + thisSize[i];
827  }
828  ++index;
829  }
830  }
831  else
832  { // symmetric and dynamic preallocatable need two pass I/O
833  OffsetBuffer buff;
834  //int index = 0;
835  for (DataIterator dit(a_data.dataIterator()); dit.ok(); ++dit)
836  {
837  int index = a_data.boxLayout().index(dit());
838  //int index = dit().intCode();
839  buff.index.push_back(index);
840  Box region = layout[dit()];
841  region.grow(outputGhost);
842  dataSize(a_data[dit()], thisSize, region, comps);
843  buff.offsets.push_back(thisSize);
844  }
845  Vector<OffsetBuffer> gathering(numProc());
846  gather(gathering, buff, uniqueProc(SerialTask::compute));
848  // pout() << gathering<<endl;
849  for (int i=0; i<numProc(); ++i)
850  {
851  OffsetBuffer& offbuf = gathering[i];
852  for (int num=0; num<offbuf.index.size(); num++)
853  {
854  int index = offbuf.index[num];
855  for (unsigned int j=0; j<types; ++j)
856  {
857  //offsets[index+1][j] = offbuf.offsets[num][j];
858  offsets[j][index+1] = offbuf.offsets[num][j];
859  }
860  }
861  }
862  for (int i=0; i<layout.size(); i++)
863  {
864  for (unsigned int j=0; j<types; ++j)
865  {
866  //offsets[i+1][j] += offsets[i][j];
867  offsets[j][i+1] += offsets[j][i];
868  }
869  }
870  }
871 
872  // pout() << offsets<<endl;
873 }
874 
875 //==================================================================
876 //
877 // Now, linear IO routines for a BoxLayoutData of T
878 //
879 template <class T>
880 int write(HDF5Handle& a_handle, const BoxLayoutData<T>& a_data,
881  const std::string& a_name, IntVect outputGhost,
882  const Interval& in_comps, bool newForm)
883 {
884  CH_TIME("write Level");
885  int ret = 0;
886 
887  Interval comps(in_comps);
888  if ( comps.size() == 0) comps = a_data.interval();
889  T dummy; // used for preallocatable methods for dumb compilers.
890  Vector<hid_t> types;
891  dataTypes(types, dummy);
892 
893  Vector<Vector<long long> > offsets;
894  Vector<long long> bufferCapacity(types.size(), 1); // noel (was 0)
895  Vector<void*> buffers(types.size(), NULL);
896 
897  getOffsets(offsets, a_data, types.size(), comps, outputGhost);
898 
899  // create datasets collectively.
900  hsize_t flatdims[1];
901  char dataname[100];
902  Vector<hid_t> dataspace(types.size());
903  Vector<hid_t> dataset(types.size());
904 
905  herr_t err;
906  hsize_t count[1];
907  ch_offset_t offset[1];
908  CH_assert(!(newForm && types.size() != 1));
909 
910  for (unsigned int i=0; i<types.size(); ++i)
911  {
912  flatdims[0] = offsets[i][offsets[i].size()-1];
913  if (newForm)
914  {
915  if (a_name == "M")
916  {
917  strcpy(dataname, "Mask");
918  }
919  else
920  {
921  sprintf(dataname, "%sRegular", a_name.c_str());
922  }
923  }
924  else
925  {
926  sprintf(dataname, "%s:datatype=%i",a_name.c_str(), i);
927  }
928  dataspace[i] = H5Screate_simple(1, flatdims, NULL);
929  CH_assert(dataspace[i] >=0);
930  dataset[i] = H5Dcreate(a_handle.groupID(), dataname,
931  types[i],
932  dataspace[i], H5P_DEFAULT);
933  CH_assert(dataset[i] >= 0);
934  }
935 
936  hid_t offsetspace, offsetData;
937  for (unsigned int i=0; i<types.size(); ++i)
938  {
939  flatdims[0] = offsets[i].size();
940  if (newForm)
941  {
942  if (a_name == "M")
943  {
944  strcpy(dataname, "MaskOffsets");
945  }
946  else
947  {
948  sprintf(dataname, "%sOffsets",a_name.c_str());
949  }
950  }
951  else
952  {
953  sprintf(dataname, "%s:offsets=%i",a_name.c_str(), i);
954  }
955  offsetspace = H5Screate_simple(1, flatdims, NULL);
956  CH_assert(offsetspace >= 0);
957  offsetData = H5Dcreate(a_handle.groupID(), dataname,
958  H5T_NATIVE_LLONG, offsetspace, H5P_DEFAULT);
959  CH_assert(offsetData >= 0);
960  if (procID() == 0)
961  {
962  hid_t memdataspace = H5Screate_simple(1, flatdims, NULL);
963  CH_assert(memdataspace >= 0);
964  err = H5Dwrite(offsetData, H5T_NATIVE_LLONG, memdataspace, offsetspace,
965  H5P_DEFAULT, &(offsets[i][0]));
966  CH_assert(err >= 0);
967  H5Sclose(memdataspace);
968  }
969  H5Sclose(offsetspace);
970  H5Dclose(offsetData);
971  }
972 
973  // write BoxLayoutData attributes into Dataset[0]
974  if (!newForm)
975  {
976  HDF5HeaderData info;
977  info.m_int["comps"] = comps.size();
978  info.m_string["objectType"] = name(dummy);
979  std::string group = a_handle.getGroup();
980  a_handle.setGroup(group+"/"+a_name+"_attributes");
981  info.writeToFile(a_handle);
982  a_handle.setGroup(group);
983  }
984 
985  // collective operations finished, now perform parallel writes
986  // to specified hyperslabs.
987 
988  Vector<size_t> type_size(types.size());
989  for (unsigned int i=0; i<types.size(); ++i)
990  {
991  type_size[i] = H5Tget_size(types[i]);
992  }
993 
994  Vector<int> thisSize(types.size());
995 
996  // step 1, create buffer big enough to hold the biggest linearized T
997  // that I will have to output.
998 
999  // pout()<<"offsets ";
1000  for (int i=0; i<offsets[0].size(); i++)
1001  {
1002  // pout()<<" "<<offsets[0][i];
1003  }
1004  // pout()<<"\n";
1005  for (DataIterator it = a_data.dataIterator(); it.ok(); ++it)
1006  {
1007  unsigned int index = a_data.boxLayout().index(it());
1008  for (unsigned int i=0; i<types.size(); ++i)
1009  {
1010  long long size = (offsets[i][index+1] - offsets[i][index])
1011  * type_size[i];
1012  // pout()<<"index:size "<<index<<" "<<size<<"\n";
1013  CH_assert(size >= 0);
1014  if (size > bufferCapacity[i]) // grow buffer if necessary.....
1015  {
1016  bufferCapacity[i] = size;
1017  }
1018  }
1019  }
1020  // CH_assert(bufferCapacity[0] > 1);
1021  for (unsigned int i=0; i<types.size(); ++i)
1022  {
1023  buffers[i] = mallocMT(bufferCapacity[i]);
1024  if (buffers[i] == NULL)
1025  {
1026  pout() << " i=" << i
1027  << " types.size() = " << types.size()
1028  << " bufferCapacity[i] = " << (int)bufferCapacity[i]
1029  << endl;
1030  MayDay::Error("memory error in buffer allocation write");
1031  }
1032  }
1033 
1034  // Step 2. actually a) write each of my T objects into the
1035  // buffer, then b) write that buffered data out to the
1036  // write position in the data file using hdf5 hyperslab functions.
1037 #ifdef TRY_MPI_COLLECTIVES_
1038  hid_t DXPL = H5Pcreate(H5P_DATASET_XFER);
1039  H5Pset_dxpl_mpio(DXPL, H5FD_MPIO_COLLECTIVE);
1040 #endif
1041  for (DataIterator it = a_data.dataIterator(); it.ok(); ++it)
1042  {
1043  const T& data = a_data[it()];
1044  unsigned int index = a_data.boxLayout().index(it());
1045  Box box = a_data.box(it());
1046  box.grow(outputGhost);
1047  write(data, buffers, box, comps); //write T to buffer
1048  for (unsigned int i=0; i<types.size(); ++i)
1049  {
1050  offset[0] = offsets[i][index];
1051  count[0] = offsets[i][index+1] - offset[0];
1052  if (count[0] > 0)
1053  {
1054  err = H5Sselect_hyperslab(dataspace[i], H5S_SELECT_SET,
1055  offset, NULL,
1056  count, NULL);
1057  CH_assert(err >= 0);
1058  hid_t memdataspace = H5Screate_simple(1, count, NULL);
1059  CH_assert(memdataspace >= 0);
1060 #ifdef TRY_MPI_COLLECTIVES_
1061  err = H5Dwrite(dataset[i], types[i], memdataspace, dataspace[i],
1062  DXPL, buffers[i]);
1063 #else
1064  err = H5Dwrite(dataset[i], types[i], memdataspace, dataspace[i],
1065  H5P_DEFAULT, buffers[i]);
1066 #endif
1067  CH_assert(err >= 0);
1068  H5Sclose(memdataspace);
1069  if (err < 0)
1070  {
1071  ret = err;
1072  goto cleanup;
1073  }
1074  }
1075  }
1076  }
1077 #ifdef TRY_MPI_COLLECTIVES_
1078  H5Pclose(DXPL);
1079 #endif
1080 
1081  // OK, clean up data structures
1082 
1083  cleanup:
1084  for (unsigned int i=0; i<types.size(); ++i)
1085  {
1086  freeMT(buffers[i]);
1087  H5Sclose(dataspace[i]);
1088  H5Dclose(dataset[i]);
1089  }
1090  return ret;
1091 
1092 }
1093 
1094 template <class T>
1095 int write(HDF5Handle& a_handle, const LevelData<T>& a_data,
1096  const std::string& a_name, const IntVect& outputGhost, const Interval& in_comps)
1097 {
1098  HDF5HeaderData info;
1099  info.m_intvect["ghost"] = a_data.ghostVect();
1100  IntVect og(outputGhost);
1101  og.min(a_data.ghostVect());
1102  info.m_intvect["outputGhost"] = og;
1103  std::string group = a_handle.getGroup();
1104  a_handle.setGroup(group+"/"+a_name+"_attributes");
1105  info.writeToFile(a_handle);
1106  a_handle.setGroup(group);
1107  return write(a_handle, (const BoxLayoutData<T>&)a_data, a_name, og, in_comps);
1108 }
1109 
1110 template <class T>
1111 int read(HDF5Handle& a_handle, LevelData<T>& a_data, const std::string& a_name,
1112  const DisjointBoxLayout& a_layout, const Interval& a_comps, bool a_redefineData)
1113 {
1114  if (a_redefineData)
1115  {
1116  HDF5HeaderData info;
1117  std::string group = a_handle.getGroup();
1118  if (a_handle.setGroup(group+"/"+a_name+"_attributes"))
1119  {
1120  std::string message = "error opening "
1121  +a_handle.getGroup()+"/"+a_name+"_attributes" ;
1122  MayDay::Warning(message.c_str());
1123  return 1;
1124  }
1125  info.readFromFile(a_handle);
1126  a_handle.setGroup(group);
1127  int ncomp = info.m_int["comps"];
1128  IntVect ghost = info.m_intvect["ghost"];
1129  if (a_comps.end() > 0 && ncomp < a_comps.end())
1130  {
1131  MayDay::Error("attempt to read component interval that is not available");
1132  }
1133  if (a_comps.size() == 0)
1134  a_data.define(a_layout, ncomp, ghost);
1135  else
1136  a_data.define(a_layout, a_comps.size(), ghost);
1137  }
1138  return read(a_handle, (BoxLayoutData<T>&)a_data, a_name, a_layout, a_comps, false);
1139 
1140 }
1141 
1142 template <class T>
1143 int read(HDF5Handle& a_handle, BoxLayoutData<T>& a_data, const std::string& a_name,
1144  const BoxLayout& a_layout, const Interval& a_comps, bool a_redefineData)
1145 {
1146  int ret = 0; // return value;
1147 
1148  herr_t err;
1149 
1150  char dataname[100];
1151  hsize_t count[1];
1152  ch_offset_t offset[1];
1153  Vector<Vector<long long> > offsets;
1154 
1155  T dummy;
1156  Vector<hid_t> types;
1157  dataTypes(types, dummy);
1158  Vector<hid_t> dataspace(types.size());
1159  Vector<hid_t> dataset(types.size());
1160  offsets.resize(types.size(), Vector<long long>(a_layout.size() +1));
1161 
1162  //Vector<int> bufferCapacity(types.size(), 500);
1163  //Vector<void*> buffers(types.size(), NULL);
1164  Vector<Vector<char> > buffers(types.size(), 500);
1165 
1166  for (unsigned int i=0; i<types.size(); ++i)
1167  {
1168  sprintf(dataname, "%s:datatype=%i",a_name.c_str(), i);
1169  dataset[i] = H5Dopen(a_handle.groupID(), dataname);
1170  if (dataset[i] < 0)
1171  {
1172  MayDay::Warning("dataset open failure"); return dataset[i];
1173  }
1174  dataspace[i] = H5Dget_space(dataset[i]);
1175  if (dataspace[i] < 0)
1176  {
1177  MayDay::Warning("dataspace open failure"); return dataspace[i];
1178  }
1179  }
1180 
1181  hid_t offsetspace, offsetData;
1182  hsize_t flatdims[1];
1183  for (unsigned int i=0; i<types.size(); ++i)
1184  {
1185  flatdims[0] = offsets[i].size();
1186  sprintf(dataname, "%s:offsets=%i",a_name.c_str(), i);
1187  offsetspace = H5Screate_simple(1, flatdims, NULL);
1188  CH_assert(offsetspace >= 0);
1189  offsetData = H5Dopen(a_handle.groupID(), dataname);
1190  CH_assert(offsetData >= 0);
1191  hid_t memdataspace = H5Screate_simple(1, flatdims, NULL);
1192  CH_assert(memdataspace >= 0);
1193  err = H5Dread(offsetData, H5T_NATIVE_LLONG, memdataspace, offsetspace,
1194  H5P_DEFAULT, &(offsets[i][0]));
1195  CH_assert(err >=0);
1196  H5Sclose(memdataspace);
1197  H5Sclose(offsetspace);
1198  H5Dclose(offsetData);
1199  }
1200 
1201  HDF5HeaderData info;
1202  std::string group = a_handle.getGroup();
1203  if (a_handle.setGroup(a_handle.getGroup()+"/"+a_name+"_attributes"))
1204  {
1205  std::string message = "error opening "+a_handle.getGroup()+"/"+a_name ;
1206  MayDay::Warning(message.c_str());
1207  return 1;
1208  }
1209 
1210  info.readFromFile(a_handle);
1211  a_handle.setGroup(group);
1212  int ncomps = info.m_int["comps"];
1213  IntVect outputGhost(IntVect::Zero); // backwards file compatible mode.
1214  if (info.m_intvect.find("outputGhost") != info.m_intvect.end())
1215  {
1216  outputGhost = info.m_intvect["outputGhost"];
1217  }
1218  if (ncomps <= 0)
1219  {
1220  MayDay::Warning("ncomps <= 0 in read");
1221  return ncomps;
1222  }
1223 
1224  if (a_redefineData)
1225  {
1226  if (a_comps.size() != 0)
1227  {
1228  a_data.define(a_layout, a_comps.size());
1229  }
1230  else
1231  {
1232  a_data.define(a_layout, ncomps);
1233  }
1234  }
1235 
1236  Interval comps(0, ncomps-1);
1237  //huh?
1238  // if (a_comps.size() != 0) comps = Interval(0, a_comps.size());
1239 
1240  // getOffsets(offsets, a_data, types.size(), comps);
1241 
1242  Vector<size_t> type_size(types.size());
1243  for (unsigned int i=0; i<types.size(); ++i)
1244  {
1245  type_size[i] = H5Tget_size(types[i]);
1246 
1247  }
1248 
1249  Vector<int> thisSize(types.size());
1250  for (DataIterator it = a_data.dataIterator(); it.ok(); ++it)
1251  {
1252  T& data = a_data[it()];
1253  unsigned int index = a_data.boxLayout().index(it());
1254  Box box = a_data.box(it());
1255 
1256  for (unsigned int i=0; i<types.size(); ++i)
1257  {
1258 // Quick fix for Ted's tempest problem. Brian will think about this.
1259 // if (a_comps.size() == 0)
1260 // {
1261  offset[0] = offsets[i][index];
1262  count[0] = offsets[i][index+1] - offset[0];
1263 // } else {
1264 // offset[0] = offsets[i][index] + box.numPts()*a_comps.begin();
1265 // count[0] = a_comps.size() * box.numPts();
1266 // }
1267  if (count[0] > 0)
1268  {
1269  int size = count[0] * type_size[i];
1270  while (size > buffers[i].size())
1271  {
1272  buffers[i].resize(2*buffers[i].size());
1273  }
1274 
1275  err = H5Sselect_hyperslab(dataspace[i], H5S_SELECT_SET,
1276  offset, NULL,
1277  count, NULL);
1278  CH_assert(err >= 0);
1279  hid_t memdataspace = H5Screate_simple(1, count, NULL);
1280  CH_assert(memdataspace >= 0);
1281  err = H5Dread(dataset[i], types[i], memdataspace, dataspace[i],
1282  H5P_DEFAULT, &(buffers[i][0]));
1283  CH_assert(err >= 0);
1284  H5Sclose(memdataspace);
1285  if (err < 0)
1286  {
1287  ret = err;
1288  goto cleanup;
1289  }
1290  }
1291  }
1292  box.grow(outputGhost);
1293  read(data, buffers, box, comps);
1294  }
1295 
1296  cleanup:
1297  for (unsigned int i=0; i<types.size(); ++i)
1298  {
1299  // freeMT(buffers[i]);
1300  H5Sclose(dataspace[i]);
1301  H5Dclose(dataset[i]);
1302  }
1303  return ret;
1304 }
1305 
1306 template <class T>
1307 int writeLevel(HDF5Handle& a_handle,
1308  const int& a_level,
1309  const T& a_data,
1310  const Real& a_dx,
1311  const Real& a_dt,
1312  const Real& a_time,
1313  const Box& a_domain,
1314  const int& a_refRatio,
1315  const IntVect& outputGhost,
1316  const Interval& comps)
1317 {
1318  int error;
1319  char levelName[10];
1320  std::string currentGroup = a_handle.getGroup();
1321  sprintf(levelName, "/level_%i",a_level);
1322  error = a_handle.setGroup(currentGroup + levelName);
1323  if (error != 0) return 1;
1324 
1325  HDF5HeaderData meta;
1326  meta.m_real["dx"] = a_dx;
1327  meta.m_real["dt"] = a_dt;
1328  meta.m_real["time"] = a_time;
1329  meta.m_box["prob_domain"] = a_domain;
1330  meta.m_int["ref_ratio"] = a_refRatio;
1331 
1332  error = meta.writeToFile(a_handle);
1333  if (error != 0) return 2;
1334 
1335  error = write(a_handle, a_data.boxLayout());
1336  if (error != 0) return 3;
1337 
1338  error = write(a_handle, a_data, "data", outputGhost, comps);
1339  if (error != 0) return 4;
1340 
1341  a_handle.setGroup(currentGroup);
1342 
1343  return 0;
1344 }
1345 
1346 template <class T>
1347 int readLevel(HDF5Handle& a_handle,
1348  const int& a_level,
1349  LevelData<T>& a_data,
1350  Real& a_dx,
1351  Real& a_dt,
1352  Real& a_time,
1353  Box& a_domain,
1354  int& a_refRatio,
1355  const Interval& a_comps,
1356  bool setGhost)
1357 {
1358  HDF5HeaderData header;
1359  header.readFromFile(a_handle);
1360  //unused
1361  // int nComp = header.m_int["num_components"];
1362 
1363  int error;
1364  char levelName[10];
1365  std::string currentGroup = a_handle.getGroup();
1366  sprintf(levelName, "/level_%i",a_level);
1367  error = a_handle.setGroup(currentGroup + levelName);
1368  if (error != 0) return 1;
1369 
1370  HDF5HeaderData meta;
1371  error = meta.readFromFile(a_handle);
1372  if (error != 0) return 2;
1373  a_dx = meta.m_real["dx"];
1374  a_dt = meta.m_real["dt"];
1375  a_time = meta.m_real["time"];
1376  a_domain = meta.m_box["prob_domain"];
1377  a_refRatio = meta.m_int["ref_ratio"];
1378  Vector<Box> boxes;
1379  error = read(a_handle, boxes);
1380  Vector<int> procIDs;
1381  LoadBalance(procIDs, boxes);
1382 
1383  DisjointBoxLayout layout(boxes, procIDs, a_domain);
1384 
1385  layout.close();
1386  if (error != 0) return 3;
1387 
1388  error = read(a_handle, a_data, "data", layout, a_comps, true);
1389 
1390  if (error != 0) return 4;
1391 
1392  a_handle.setGroup(currentGroup);
1393 
1394  return 0;
1395 }
1396 
1397 #include "NamespaceFooter.H"
1398 
1399 #else // CH_USE_HDF5
1400 
1401 // this is the only thing needed when HDF is not used
1402 #define HOFFSET(S,M) (offsetof(S,M))
1403 
1404 #endif // CH_USE_HDF5 not defined
1405 #endif // CH_HDF5_H
std::ostream & pout()
Use this in place of std::cout for program output.
int open(const std::string &a_filename, mode a_mode, const char *a_globalGroupName="Chombo_global")
{ File functions}
map< std::string, int > m_int
Definition: CH_HDF5.H:521
virtual void define(const BoxLayout &boxes, int comps, const DataFactory< T > &factory=DefaultDataFactory< T >())
Definition: BoxLayoutDataI.H:83
static herr_t attributeScan(hid_t loc_id, const char *name, void *opdata)
IntVect & min(const IntVect &p)
Definition: IntVect.H:1041
#define freeMT(a_a)
Definition: memtrack.H:159
#define CH_SPACEDIM
Definition: SPACE.H:52
#define CH_assert(cond)
Definition: CHArray.H:37
int popGroup()
data to be added to HDF5 files.
Definition: CH_HDF5.H:490
const hid_t & fileID() const
int readBoxes(HDF5Handle &a_handle, Vector< Vector< Box > > &boxes)
reads the set of Boxes out from the level_* groups of a Chombo HDF5 AMR file
mode
Definition: CH_HDF5.H:289
void writeDataset(hid_t a_dataset, hid_t a_dataspace, const void *start, ch_offset_t off, hsize_t count)
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:146
one dimensional dynamic array
Definition: Vector.H:52
map< std::string, Real > m_real
Definition: CH_HDF5.H:518
int readFArrayBox(HDF5Handle &a_handle, FArrayBox &a_fab, int a_level, int a_boxNumber, const Interval &a_components, const std::string &a_dataName="data")
FArrayBox-at-a-time read function. FArrayBox gets redefined in the function. Reads data field named b...
int writeToLocation(hid_t loc_id) const
std::string m_group
Definition: CH_HDF5.H:438
#define mallocMT(a_a)
Definition: memtrack.H:158
LayoutIterator layoutIterator() const
Iterator that processes through ALL the boxes in a BoxLayout.
void getOffsets(Vector< Vector< long long > > &offsets, const BoxLayoutData< T > &a_data, int types, const Interval &comps, const IntVect &outputGhost)
Definition: CH_HDF5.H:806
void readDataset(hid_t a_dataset, hid_t a_dataspace, void *start, ch_offset_t off, hsize_t count)
void close()
void setGroupToLevel(int a_level)
{ Group functions}
Definition: DataIterator.H:140
void linearOut(void *const a_outBuf, const CH_XDIR::OffsetBuffer &a_inputT)
int readLevel(HDF5Handle &a_handle, const int &a_level, LevelData< T > &a_data, Real &a_dx, Real &a_dt, Real &a_time, Box &a_domain, int &a_refRatio, const Interval &a_comps=Interval(), bool setGhost=false)
Definition: CH_HDF5.H:1347
Definition: CH_HDF5.H:294
unsigned int size() const
Returns the total number of boxes in the BoxLayout.
std::ostream & operator<<(std::ostream &os, const HDF5HeaderData &data)
int LoadBalance(Vector< Vector< int > > &a_procAssignments, Real &a_effRatio, const Vector< Vector< Box > > &a_Grids, const Vector< Vector< long > > &a_ComputeLoads, const Vector< int > &a_RefRatios, int a_nProc=numProc())
unsigned int numProc()
number of parallel processes
int uniqueProc(const SerialTask::task &a_task)
An Iterator based on a BoxLayout object.
Definition: LayoutIterator.H:38
void createDataset(hid_t &a_dataset, hid_t &a_dataspace, HDF5Handle &handle, const std::string &name, const T *dummy, hsize_t size)
Definition: CH_HDF5.H:612
int size() const
Definition: Interval.H:64
void dataTypes(Vector< hid_t > &a_types, const BaseFab< int > &dummy)
Definition: CH_HDF5.H:676
void dataSize(const BaseFab< int > &item, Vector< int > &a_sizes, const Box &box, const Interval &comps)
Definition: CH_HDF5.H:707
Definition: CH_HDF5.H:291
map< std::string, RealVect > m_realvect
Definition: CH_HDF5.H:533
Definition: EBInterface.H:45
static hid_t realvect_id
Definition: CH_HDF5.H:426
void resize(unsigned int isize)
Definition: Vector.H:323
static void initialize()
Definition: CH_HDF5.H:293
virtual void close()
map< std::string, IntVect > m_intvect
Definition: CH_HDF5.H:527
A FArrayBox-like container for face-centered fluxes.
Definition: FluxBox.H:22
void gather(Vector< T > &a_outVec, const T &a_input, int a_dest)
Definition: SPMDI.H:194
void linearIn(CH_XDIR::OffsetBuffer &a_outputT, const void *const a_inBuf)
void push_back(const T &in)
Definition: Vector.H:283
static bool initialized
Definition: CH_HDF5.H:442
#define CH_TIME(name)
Definition: CH_Timer.H:59
Structure for passing component ranges in code.
Definition: Interval.H:23
const char * name(const FArrayBox &a_dummySpecializationArg)
Definition: CH_HDF5.H:741
int linearSize(const CH_XDIR::OffsetBuffer &a_input)
Definition: BoxLayoutData.H:136
std::string m_filename
Definition: CH_HDF5.H:437
Interval interval() const
Definition: BoxLayoutData.H:264
Data on a BoxLayout.
Definition: BoxLayoutData.H:91
double Real
Definition: REAL.H:33
Box surroundingNodes(const Box &b, int dir)
Definition: Box.H:2166
herr_t HDF5HeaderDataattributeScan(hid_t loc_id, const char *name, void *opdata)
unsigned int index(const LayoutIndex &index) const
Definition: BoxLayout.H:690
Definition: SPMD.H:279
Definition: CH_HDF5.H:637
long numPts() const
virtual void define(const DisjointBoxLayout &dp, int comps, const IntVect &ghost=IntVect::Zero, const DataFactory< T > &a_factory=DefaultDataFactory< T >())
Definition: LevelDataI.H:70
void operator=(const OffsetBuffer &rhs)
int pushGroup(const std::string &grp)
bool isOpen() const
Vector< int > index
Definition: CH_HDF5.H:639
Definition: CH_HDF5.H:292
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
void createData(hid_t &a_dataset, hid_t &a_dataspace, HDF5Handle &handle, const std::string &name, hid_t type, hsize_t size)
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
int write(HDF5Handle &a_handle, const BoxLayout &a_layout, const std::string &name="boxes")
writes BoxLayout to HDF5 file.
const BoxLayout & boxLayout() const
Definition: LayoutData.H:108
static const IntVect Zero
Definition: IntVect.H:627
static hid_t box_id
Definition: CH_HDF5.H:424
const hid_t & groupID() const
Vector< Vector< int > > offsets
Definition: CH_HDF5.H:640
hssize_t ch_offset_t
Definition: CH_HDF5.H:566
static void Warning(const char *const a_msg=m_nullString)
Print out message to cerr and continue.
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
hid_t m_fileID
Definition: CH_HDF5.H:434
int writeToFile(HDF5Handle &file) const
hid_t H5Type(const T *dummy)
Definition: CH_HDF5.H:596
map< std::string, Box > m_box
Definition: CH_HDF5.H:530
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:267
void dump() const
useful for debugging. dumps contents to std::cout
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Definition: FArrayBox.H:44
const std::string & getGroup() const
DataIterator dataIterator() const
Definition: LayoutDataI.H:79
size_t size() const
Definition: Vector.H:177
HDF5Handle()
{ constructor}
Box & grow(int i)
grow functions
Definition: Box.H:2268
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:110
int setGroup(const std::string &groupAbsPath)
void broadcast(T &a_inAndOut, int a_src)
broadcast to every process
Definition: SPMDI.H:204
int writeLevel(HDF5Handle &a_handle, const int &a_level, const T &a_data, const Real &a_dx, const Real &a_dt, const Real &a_time, const Box &a_domain, const int &a_refRatio, const IntVect &outputGhost=IntVect::Zero, const Interval &comps=Interval())
user-friendly function to write out data on a AMR level
Definition: CH_HDF5.H:1307
int readFromLocation(hid_t loc_id)
int end() const
Definition: Interval.H:91
map< std::string, std::string > m_string
Definition: CH_HDF5.H:524
static hid_t intvect_id
Definition: CH_HDF5.H:425
int procID()
local process ID
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:67
int readFromFile(HDF5Handle &file)
HDF5Handle & operator=(const HDF5Handle &)
bool m_isOpen
Definition: CH_HDF5.H:436
static map< std::string, std::string > groups
Definition: CH_HDF5.H:427
void read(T &item, Vector< Vector< char > > &a_allocatedBuffers, const Box &box, const Interval &comps)
Definition: CH_HDF5.H:47
hid_t m_currentGroupID
Definition: CH_HDF5.H:435
#define H5T_NATIVE_REAL
Definition: REAL.H:35
int m_level
Definition: CH_HDF5.H:439
const IntVect & ghostVect() const
Definition: LevelData.H:157