Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
hdf5.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2018 - 2020 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 
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
330 // clang-format on
331 namespace HDF5
332 {
339  {
340  protected:
345  HDF5Object(const std::string &name, const bool mpi);
346 
347  public:
360  template <typename T>
361  T
362  get_attribute(const std::string &attr_name) const;
363 
376  template <typename T>
377  void
378  set_attribute(const std::string &attr_name, const T value);
379 
385  std::string
386  get_name() const;
387 
388  protected:
394  const std::string name;
395 
403  std::shared_ptr<hid_t> hdf5_reference;
404 
408  const bool mpi;
409  };
410 
416  class DataSet : public HDF5Object
417  {
418  friend class Group;
419 
420  protected:
425  DataSet(const std::string &name, const hid_t &parent_group_id, bool mpi);
426 
431  DataSet(const std::string & name,
432  const hid_t & parent_group_id,
433  const std::vector<hsize_t> & dimensions,
434  const std::shared_ptr<hid_t> &t_type,
435  const bool mpi);
436 
437  public:
455  template <typename Container>
456  Container
457  read();
458 
492  template <typename Container>
493  Container
494  read_selection(const std::vector<hsize_t> &coordinates);
495 
496  // clang-format off
530  // clang-format on
531  template <typename Container>
532  Container
533  read_hyperslab(const std::vector<hsize_t> &offset,
534  const std::vector<hsize_t> &count);
535 
568  template <typename Container>
569  Container
570  read_hyperslab(const std::vector<hsize_t> &data_dimensions,
571  const std::vector<hsize_t> &offset,
572  const std::vector<hsize_t> &stride,
573  const std::vector<hsize_t> &count,
574  const std::vector<hsize_t> &block);
575 
587  template <typename number>
588  void
589  read_none();
590 
609  template <typename Container>
610  void
611  write(const Container &data);
612 
641  template <typename Container>
642  void
643  write_selection(const Container & data,
644  const std::vector<hsize_t> &coordinates);
645 
646  // clang-format off
672  // clang-format on
673  template <typename Container>
674  void
675  write_hyperslab(const Container & data,
676  const std::vector<hsize_t> &offset,
677  const std::vector<hsize_t> &count);
678 
711  template <typename Container>
712  void
713  write_hyperslab(const Container & data,
714  const std::vector<hsize_t> &data_dimensions,
715  const std::vector<hsize_t> &offset,
716  const std::vector<hsize_t> &stride,
717  const std::vector<hsize_t> &count,
718  const std::vector<hsize_t> &block);
719 
737  template <typename number>
738  void
739  write_none();
740 
757  bool
758  get_query_io_mode() const;
759 
763  void
764  set_query_io_mode(const bool new_query_io_mode);
765 
780  std::string
781  get_io_mode();
782 
799  H5D_mpio_actual_io_mode_t
801 
820  std::string
822 
843  uint32_t
845 
864  std::string
866 
887  uint32_t
889 
895  std::vector<hsize_t>
896  get_dimensions() const;
897 
901  unsigned int
902  get_size() const;
903 
907  unsigned int
908  get_rank() const;
909 
910  private:
914  unsigned int rank;
915 
920  std::vector<hsize_t> dimensions;
921 
925  std::shared_ptr<hid_t> dataspace;
926 
930  unsigned int size;
931 
942 
946  H5D_mpio_actual_io_mode_t io_mode;
947 
954 
961  };
962 
968  class Group : public HDF5Object
969  {
970  protected:
974  enum class GroupAccessMode
975  {
979  open,
983  create
984  };
993  Group(const std::string & name,
994  const Group & parent_group,
995  const bool mpi,
996  const GroupAccessMode mode);
997 
1003  Group(const std::string &name, const bool mpi);
1004 
1005  public:
1009  Group
1010  open_group(const std::string &name) const;
1011 
1015  Group
1016  create_group(const std::string &name) const;
1017 
1021  DataSet
1022  open_dataset(const std::string &name) const;
1023 
1034  template <typename number>
1035  DataSet
1036  create_dataset(const std::string & name,
1037  const std::vector<hsize_t> &dimensions) const;
1038 
1057  template <typename Container>
1058  void
1059  write_dataset(const std::string &name, const Container &data) const;
1060  };
1061 
1067  class File : public Group
1068  {
1069  public:
1073  enum class FileAccessMode
1074  {
1078  open,
1082  create
1083  };
1084 
1090  File(const std::string &name, const FileAccessMode mode);
1091 
1099  File(const std::string & name,
1100  const FileAccessMode mode,
1101  const MPI_Comm mpi_communicator);
1102 
1103  private:
1111  File(const std::string & name,
1112  const FileAccessMode mode,
1113  const bool mpi,
1114  const MPI_Comm mpi_communicator);
1115  };
1116 } // namespace HDF5
1117 
1119 
1120 
1121 #endif // DEAL_II_WITH_HDF5
1122 
1123 #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
@ open
HDF5::File::FileAccessMode::create
@ 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:1067
HDF5::HDF5Object::name
const std::string name
Definition: hdf5.h:394
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:331
HDF5::DataSet
Definition: hdf5.h:416
MPI_Comm
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:338
HDF5::HDF5Object::mpi
const bool mpi
Definition: hdf5.h:408
HDF5::DataSet::local_no_collective_cause
uint32_t local_no_collective_cause
Definition: hdf5.h:953
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:974
HDF5::DataSet::read_hyperslab
Container read_hyperslab(const std::vector< hsize_t > &offset, const std::vector< hsize_t > &count)
Definition: hdf5.cc:795
LAPACKSupport::T
static const char T
Definition: lapack_support.h:163
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
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
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
@ 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:960
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:925
HDF5::Group::write_dataset
void write_dataset(const std::string &name, const Container &data) const
Definition: hdf5.cc:1381
value
static const bool value
Definition: dof_tools_constraints.cc:433
HDF5::DataSet::rank
unsigned int rank
Definition: hdf5.h:914
HDF5::File::FileAccessMode
FileAccessMode
Definition: hdf5.h:1073
HDF5::Group::GroupAccessMode::open
@ open
HDF5::Group
Definition: hdf5.h:968
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
config.h
hdf5.h
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:403
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
HDF5::DataSet::dimensions
std::vector< hsize_t > dimensions
Definition: hdf5.h:920
HDF5::DataSet::query_io_mode
bool query_io_mode
Definition: hdf5.h:941
HDF5::DataSet::io_mode
H5D_mpio_actual_io_mode_t io_mode
Definition: hdf5.h:946
HDF5::DataSet::size
unsigned int size
Definition: hdf5.h:930
HDF5::DataSet::get_io_mode_as_hdf5_type
H5D_mpio_actual_io_mode_t get_io_mode_as_hdf5_type()
Definition: hdf5.cc:1221
full_matrix.h
HDF5::Group::create_group
Group create_group(const std::string &name) const
Definition: hdf5.cc:1353