opm-simulators
HDF5File.hpp
1 /*
2  This file is part of the Open Porous Media project (OPM).
3 
4  OPM is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 2 of the License, or
7  (at your option) any later version.
8 
9  OPM is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with OPM. If not, see <http://www.gnu.org/licenses/>.
16 
17  Consult the COPYING file in the top-level source directory of this
18  module for the precise wording of the license and the list of
19  copyright holders.
20 */
21 #ifndef HDF5_FILE_HPP
22 #define HDF5_FILE_HPP
23 
24 #include <opm/simulators/utils/ParallelCommunication.hpp>
25 
26 #include <hdf5.h>
27 
28 #include <string>
29 #include <vector>
30 
31 namespace Opm {
32 
34 class HDF5File {
35 public:
37  enum class OpenMode {
38  APPEND,
39  OVERWRITE,
40  READ
41  };
42 
44  enum class DataSetMode {
45  ROOT_ONLY,
47  };
48 
53  HDF5File(const std::string& fileName,
54  OpenMode mode,
55  Parallel::Communication comm);
56 
58  ~HDF5File();
59 
66  void write(const std::string& group,
67  const std::string& dset,
68  const std::vector<char>& buffer,
70 
77  void read(const std::string& group,
78  const std::string& dset,
79  std::vector<char>& buffer,
81 
84  std::vector<std::string> list(const std::string& group) const;
85 
86 private:
91  void writeSplit(hid_t grp,
92  const std::vector<char>& buffer,
93  const std::string& dset) const;
94 
99  void writeRootOnly(hid_t grp,
100  const std::vector<char>& buffer,
101  const std::string& group,
102  const std::string& dset) const;
103 
106  hid_t getCompression(hsize_t size) const;
107 
114  void writeDset(int rank, hid_t dataset_id,
115  hid_t dxpl, hsize_t size, const void* data) const;
116  hid_t m_file = H5I_INVALID_HID;
117  Parallel::Communication comm_;
118 };
119 
120 }
121 
122 #endif
~HDF5File()
Destructor clears up any opened files.
Definition: HDF5File.cpp:92
std::vector< std::string > list(const std::string &group) const
Lists the entries in a given group.
Definition: HDF5File.cpp:175
void write(const std::string &group, const std::string &dset, const std::vector< char > &buffer, DataSetMode mode=DataSetMode::PROCESS_SPLIT) const
Write a char buffer to a specified location in file.
Definition: HDF5File.cpp:99
HDF5File(const std::string &fileName, OpenMode mode, Parallel::Communication comm)
Opens HDF5 file for I/O.
Definition: HDF5File.cpp:53
One separate data set for each parallel process.
OpenMode
Enumeration of file opening modes.
Definition: HDF5File.hpp:37
Open existing file for reading.
Append to an existing file (creates new if not)
void read(const std::string &group, const std::string &dset, std::vector< char > &buffer, DataSetMode mode=DataSetMode::PROCESS_SPLIT) const
Read a char buffer from a specified location in file.
Definition: HDF5File.cpp:154
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Overwrite and write to an existing file.
DataSetMode
Enumeration of dataset modes.
Definition: HDF5File.hpp:44
Class handling simple output to HDF5.
Definition: HDF5File.hpp:34
A single dataset created at the root process.