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
HDF5::HDF5Object::get_attribute
T get_attribute(const std::string &attr_name) const
Definition: hdf5.cc:405
HDF5::File::FileAccessMode::open
HDF5::File::FileAccessMode::create
HDF5::DataSet::DataSet
DataSet(const std::string &name, const hid_t &parent_group_id, bool mpi)
Definition: hdf5.cc:606
HDF5::DataSet::read
Container read()
Definition: hdf5.cc:708
HDF5::File
Definition: hdf5.h:1037
HDF5::HDF5Object::name
const std::string name
Definition: hdf5.h:370
HDF5::HDF5Object::set_attribute
void set_attribute(const std::string &attr_name, const T value)
Definition: hdf5.cc:505
HDF5::Group::open_group
Group open_group(const std::string &name) const
Definition: hdf5.cc:1345
HDF5::Group::create_dataset
DataSet create_dataset(const std::string &name, const std::vector< hsize_t > &dimensions) const
Definition: hdf5.cc:1370
HDF5::DataSet::read_selection
Container read_selection(const std::vector< hsize_t > &coordinates)
Definition: hdf5.cc:743
HDF5
Definition: hdf5.h:307
HDF5::DataSet
Definition: hdf5.h:392
HDF5::DataSet::set_query_io_mode
void set_query_io_mode(const bool new_query_io_mode)
Definition: hdf5.cc:1171
HDF5::HDF5Object
Definition: hdf5.h:314
HDF5::HDF5Object::mpi
const bool mpi
Definition: hdf5.h:384
HDF5::DataSet::local_no_collective_cause
uint32_t local_no_collective_cause
Definition: hdf5.h:923
HDF5::DataSet::get_dimensions
std::vector< hsize_t > get_dimensions() const
Definition: hdf5.cc:1179
HDF5::DataSet::get_global_no_collective_cause
std::string get_global_no_collective_cause()
Definition: hdf5.cc:1256
HDF5::Group::GroupAccessMode
GroupAccessMode
Definition: hdf5.h:944
HDF5::DataSet::read_hyperslab
Container read_hyperslab(const std::vector< hsize_t > &offset, const std::vector< hsize_t > &count)
Definition: hdf5.cc:795
HDF5::DataSet::get_rank
unsigned int get_rank() const
Definition: hdf5.cc:1295
HDF5::DataSet::write
void write(const Container &data)
Definition: hdf5.cc:942
HDF5::DataSet::get_size
unsigned int get_size() const
Definition: hdf5.cc:1287
HDF5::DataSet::write_hyperslab
void write_hyperslab(const Container &data, const std::vector< hsize_t > &offset, const std::vector< hsize_t > &count)
Definition: hdf5.cc:1023
HDF5::DataSet::get_local_no_collective_cause
std::string get_local_no_collective_cause()
Definition: hdf5.cc:1232
HDF5::DataSet::get_query_io_mode
bool get_query_io_mode() const
Definition: hdf5.cc:1279
HDF5::Group::open_dataset
DataSet open_dataset(const std::string &name) const
Definition: hdf5.cc:1361
HDF5::Group::GroupAccessMode::create
HDF5::DataSet::get_global_no_collective_cause_as_hdf5_type
uint32_t get_global_no_collective_cause_as_hdf5_type()
Definition: hdf5.cc:1268
HDF5::DataSet::read_none
void read_none()
Definition: hdf5.cc:902
HDF5::DataSet::global_no_collective_cause
uint32_t global_no_collective_cause
Definition: hdf5.h:930
HDF5::HDF5Object::get_name
std::string get_name() const
Definition: hdf5.cc:599
HDF5::DataSet::get_local_no_collective_cause_as_hdf5_type
uint32_t get_local_no_collective_cause_as_hdf5_type()
Definition: hdf5.cc:1244
HDF5::DataSet::dataspace
std::shared_ptr< hid_t > dataspace
Definition: hdf5.h:895
HDF5::Group::write_dataset
void write_dataset(const std::string &name, const Container &data) const
Definition: hdf5.cc:1381
HDF5::DataSet::rank
unsigned int rank
Definition: hdf5.h:884
HDF5::File::FileAccessMode
FileAccessMode
Definition: hdf5.h:1043
HDF5::Group::GroupAccessMode::open
HDF5::Group
Definition: hdf5.h:938
HDF5::HDF5Object::HDF5Object
HDF5Object(const std::string &name, const bool mpi)
Definition: hdf5.cc:396
HDF5::Group::Group
Group(const std::string &name, const Group &parent_group, const bool mpi, const GroupAccessMode mode)
Definition: hdf5.cc:1302
HDF5::File::File
File(const std::string &name, const FileAccessMode mode)
Definition: hdf5.cc:1391
HDF5::DataSet::write_none
void write_none()
Definition: hdf5.cc:1132
HDF5::DataSet::get_io_mode
std::string get_io_mode()
Definition: hdf5.cc:1187
HDF5::DataSet::write_selection
void write_selection(const Container &data, const std::vector< hsize_t > &coordinates)
Definition: hdf5.cc:974
HDF5::HDF5Object::hdf5_reference
std::shared_ptr< hid_t > hdf5_reference
Definition: hdf5.h:379
HDF5::DataSet::dimensions
std::vector< hsize_t > dimensions
Definition: hdf5.h:890
HDF5::DataSet::query_io_mode
bool query_io_mode
Definition: hdf5.h:911
HDF5::DataSet::io_mode
H5D_mpio_actual_io_mode_t io_mode
Definition: hdf5.h:916
HDF5::DataSet::size
unsigned int size
Definition: hdf5.h:900
HDF5::DataSet::get_io_mode_as_hdf5_type
H5D_mpio_actual_io_mode_t get_io_mode_as_hdf5_type()
Definition: hdf5.cc:1221
HDF5::Group::create_group
Group create_group(const std::string &name) const
Definition: hdf5.cc:1353