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
800  get_io_mode_as_hdf5_type();
801 
820  std::string
821  get_local_no_collective_cause();
822 
843  uint32_t
844  get_local_no_collective_cause_as_hdf5_type();
845 
864  std::string
865  get_global_no_collective_cause();
866 
887  uint32_t
888  get_global_no_collective_cause_as_hdf5_type();
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
GroupAccessMode
Definition: hdf5.h:974
std::string get_name() const
Definition: hdf5.cc:599
T get_attribute(const std::string &attr_name) const
Definition: hdf5.cc:405
HDF5Object(const std::string &name, const bool mpi)
Definition: hdf5.cc:396
std::shared_ptr< hid_t > hdf5_reference
Definition: hdf5.h:403
FileAccessMode
Definition: hdf5.h:1073
unsigned int size
Definition: hdf5.h:930
bool query_io_mode
Definition: hdf5.h:941
static const char T
void set_attribute(const std::string &attr_name, const T value)
Definition: hdf5.cc:505
const std::string name
Definition: hdf5.h:394
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
int create_group(const MPI_Comm &comm, const MPI_Group &group, const int tag, MPI_Comm *new_comm)
Definition: mpi.cc:160
std::vector< hsize_t > dimensions
Definition: hdf5.h:920
unsigned int rank
Definition: hdf5.h:914
std::shared_ptr< hid_t > dataspace
Definition: hdf5.h:925
Definition: hdf5.h:331
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
uint32_t local_no_collective_cause
Definition: hdf5.h:953
uint32_t global_no_collective_cause
Definition: hdf5.h:960
const bool mpi
Definition: hdf5.h:408
H5D_mpio_actual_io_mode_t io_mode
Definition: hdf5.h:946
static const bool value