Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
hdf5.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2018 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_hdf5_h
17 #define dealii_hdf5_h
18 
19 #include <deal.II/base/config.h>
20 
21 #ifdef DEAL_II_WITH_HDF5
22 
23 # include <deal.II/lac/full_matrix.h>
24 
25 # include <hdf5.h>
26 
27 # include <vector>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 // It is necessary to turn clang-format off in order to maintain the Doxygen
32 // links because they are longer than 80 characters
33 // clang-format off
306 // clang-format on
307 namespace HDF5
308 {
315  {
316  protected:
321  HDF5Object(const std::string &name, const bool mpi);
322 
323  public:
336  template <typename T>
337  T
338  get_attribute(const std::string &attr_name) const;
339 
352  template <typename T>
353  void
354  set_attribute(const std::string &attr_name, const T value);
355 
361  std::string
362  get_name() const;
363 
364  protected:
370  const std::string name;
371 
379  std::shared_ptr<hid_t> hdf5_reference;
380 
384  const bool mpi;
385  };
386 
392  class DataSet : public HDF5Object
393  {
394  friend class Group;
395 
396  protected:
401  DataSet(const std::string &name, const hid_t &parent_group_id, bool mpi);
402 
407  DataSet(const std::string & name,
408  const hid_t & parent_group_id,
409  const std::vector<hsize_t> & dimensions,
410  const std::shared_ptr<hid_t> &t_type,
411  const bool mpi);
412 
413  public:
431  template <typename Container>
432  Container
433  read();
434 
468  template <typename Container>
469  Container
470  read_selection(const std::vector<hsize_t> &coordinates);
471 
472  // clang-format off
506  // clang-format on
507  template <typename Container>
508  Container
509  read_hyperslab(const std::vector<hsize_t> &offset,
510  const std::vector<hsize_t> &count);
511 
544  template <typename Container>
545  Container
546  read_hyperslab(const std::vector<hsize_t> &data_dimensions,
547  const std::vector<hsize_t> &offset,
548  const std::vector<hsize_t> &stride,
549  const std::vector<hsize_t> &count,
550  const std::vector<hsize_t> &block);
551 
563  template <typename number>
564  void
565  read_none();
566 
585  template <typename Container>
586  void
587  write(const Container &data);
588 
617  template <typename Container>
618  void
619  write_selection(const Container & data,
620  const std::vector<hsize_t> &coordinates);
621 
622  // clang-format off
648  // clang-format on
649  template <typename Container>
650  void
651  write_hyperslab(const Container & data,
652  const std::vector<hsize_t> &offset,
653  const std::vector<hsize_t> &count);
654 
687  template <typename Container>
688  void
689  write_hyperslab(const Container & data,
690  const std::vector<hsize_t> &data_dimensions,
691  const std::vector<hsize_t> &offset,
692  const std::vector<hsize_t> &stride,
693  const std::vector<hsize_t> &count,
694  const std::vector<hsize_t> &block);
695 
707  template <typename number>
708  void
709  write_none();
710 
727  bool
728  get_query_io_mode() const;
729 
733  void
734  set_query_io_mode(const bool new_query_io_mode);
735 
750  std::string
751  get_io_mode();
752 
769  H5D_mpio_actual_io_mode_t
771 
790  std::string
792 
813  uint32_t
815 
834  std::string
836 
857  uint32_t
859 
865  std::vector<hsize_t>
866  get_dimensions() const;
867 
871  unsigned int
872  get_size() const;
873 
877  unsigned int
878  get_rank() const;
879 
880  private:
884  unsigned int rank;
885 
890  std::vector<hsize_t> dimensions;
891 
895  std::shared_ptr<hid_t> dataspace;
896 
900  unsigned int size;
901 
912 
916  H5D_mpio_actual_io_mode_t io_mode;
917 
924 
931  };
932 
938  class Group : public HDF5Object
939  {
940  protected:
944  enum class GroupAccessMode
945  {
949  open,
953  create
954  };
963  Group(const std::string & name,
964  const Group & parent_group,
965  const bool mpi,
966  const GroupAccessMode mode);
967 
973  Group(const std::string &name, const bool mpi);
974 
975  public:
979  Group
980  open_group(const std::string &name) const;
981 
985  Group
986  create_group(const std::string &name) const;
987 
991  DataSet
992  open_dataset(const std::string &name) const;
993 
1004  template <typename number>
1005  DataSet
1006  create_dataset(const std::string & name,
1007  const std::vector<hsize_t> &dimensions) const;
1008 
1027  template <typename Container>
1028  void
1029  write_dataset(const std::string &name, const Container &data) const;
1030  };
1031 
1037  class File : public Group
1038  {
1039  public:
1043  enum class FileAccessMode
1044  {
1048  open,
1052  create
1053  };
1054 
1060  File(const std::string &name, const FileAccessMode mode);
1061 
1069  File(const std::string & name,
1070  const FileAccessMode mode,
1071  const MPI_Comm mpi_communicator);
1072 
1073  private:
1081  File(const std::string & name,
1082  const FileAccessMode mode,
1083  const bool mpi,
1084  const MPI_Comm mpi_communicator);
1085  };
1086 } // namespace HDF5
1087 
1088 DEAL_II_NAMESPACE_CLOSE
1089 
1090 
1091 #endif // DEAL_II_WITH_HDF5
1092 
1093 #endif // dealii_hdf5_h
void write_none()
Definition: hdf5.cc:1132
DataSet open_dataset(const std::string &name) const
Definition: hdf5.cc:1361
Container read_selection(const std::vector< hsize_t > &coordinates)
Definition: hdf5.cc:743
GroupAccessMode
Definition: hdf5.h:944
std::string get_name() const
Definition: hdf5.cc:599
H5D_mpio_actual_io_mode_t get_io_mode_as_hdf5_type()
Definition: hdf5.cc:1221
void read_none()
Definition: hdf5.cc:902
Group(const std::string &name, const Group &parent_group, const bool mpi, const GroupAccessMode mode)
Definition: hdf5.cc:1302
T get_attribute(const std::string &attr_name) const
Definition: hdf5.cc:405
Container read()
Definition: hdf5.cc:708
HDF5Object(const std::string &name, const bool mpi)
Definition: hdf5.cc:396
std::shared_ptr< hid_t > hdf5_reference
Definition: hdf5.h:379
FileAccessMode
Definition: hdf5.h:1043
unsigned int size
Definition: hdf5.h:900
DataSet(const std::string &name, const hid_t &parent_group_id, bool mpi)
Definition: hdf5.cc:606
void write_selection(const Container &data, const std::vector< hsize_t > &coordinates)
Definition: hdf5.cc:974
void write(const Container &data)
Definition: hdf5.cc:942
bool query_io_mode
Definition: hdf5.h:911
Group create_group(const std::string &name) const
Definition: hdf5.cc:1353
void set_query_io_mode(const bool new_query_io_mode)
Definition: hdf5.cc:1171
void set_attribute(const std::string &attr_name, const T value)
Definition: hdf5.cc:505
unsigned int get_rank() const
Definition: hdf5.cc:1295
DataSet create_dataset(const std::string &name, const std::vector< hsize_t > &dimensions) const
Definition: hdf5.cc:1370
const std::string name
Definition: hdf5.h:370
unsigned int get_size() const
Definition: hdf5.cc:1287
void write_hyperslab(const Container &data, const std::vector< hsize_t > &offset, const std::vector< hsize_t > &count)
Definition: hdf5.cc:1023
std::vector< hsize_t > dimensions
Definition: hdf5.h:890
uint32_t get_global_no_collective_cause_as_hdf5_type()
Definition: hdf5.cc:1268
unsigned int rank
Definition: hdf5.h:884
std::shared_ptr< hid_t > dataspace
Definition: hdf5.h:895
void write_dataset(const std::string &name, const Container &data) const
Definition: hdf5.cc:1381
Definition: hdf5.h:307
std::string get_local_no_collective_cause()
Definition: hdf5.cc:1232
uint32_t local_no_collective_cause
Definition: hdf5.h:923
std::vector< hsize_t > get_dimensions() const
Definition: hdf5.cc:1179
std::string get_global_no_collective_cause()
Definition: hdf5.cc:1256
uint32_t global_no_collective_cause
Definition: hdf5.h:930
std::string get_io_mode()
Definition: hdf5.cc:1187
const bool mpi
Definition: hdf5.h:384
H5D_mpio_actual_io_mode_t io_mode
Definition: hdf5.h:916
File(const std::string &name, const FileAccessMode mode)
Definition: hdf5.cc:1391
uint32_t get_local_no_collective_cause_as_hdf5_type()
Definition: hdf5.cc:1244
Container read_hyperslab(const std::vector< hsize_t > &offset, const std::vector< hsize_t > &count)
Definition: hdf5.cc:795
bool get_query_io_mode() const
Definition: hdf5.cc:1279
Group open_group(const std::string &name) const
Definition: hdf5.cc:1345