HDF5Serializer.hpp
Go to the documentation of this file.
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_SERIALIZER_HPP
22#define HDF5_SERIALIZER_HPP
23
24#include <opm/common/utility/Serializer.hpp>
25
29
30#include <cstddef>
31#include <limits>
32#include <string>
33
34namespace Opm {
35
37class HDF5Serializer : public Serializer<Serialization::MemPacker> {
38public:
39 HDF5Serializer(const std::string& fileName,
42 : Serializer<Serialization::MemPacker>(m_packer_priv)
43 , m_h5file(fileName, mode, comm)
44 {}
45
49 template<class T>
50 void write(T& data,
51 const std::string& group,
52 const std::string& dset,
54 {
55 try {
56 this->pack(data);
57 } catch (...) {
58 m_packSize = std::numeric_limits<std::size_t>::max();
59 throw;
60 }
61
62 m_h5file.write(group, dset, m_buffer, mode);
63 }
64
72 void writeHeader(const std::string& simulator_name,
73 const std::string& module_version,
74 const std::string& time_stamp,
75 const std::string& case_name,
76 const std::string& params,
77 int num_procs);
78
82 template<class T>
83 void read(T& data,
84 const std::string& group,
85 const std::string& dset,
87 {
88 m_h5file.read(group, dset, m_buffer, mode);
89 this->unpack(data);
90 }
91
93 int lastReportStep() const;
94
96 std::vector<int> reportSteps() const;
97
98private:
99 const Serialization::MemPacker m_packer_priv{};
100 HDF5File m_h5file;
101};
102
103}
104
105#endif // HDF5_SERIALIZER_HPP
Class handling simple output to HDF5.
Definition: HDF5File.hpp:34
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.
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.
OpenMode
Enumeration of file opening modes.
Definition: HDF5File.hpp:37
DataSetMode
Enumeration of dataset modes.
Definition: HDF5File.hpp:44
@ PROCESS_SPLIT
One separate data set for each parallel process.
Class for (de-)serializing using HDF5.
Definition: HDF5Serializer.hpp:37
int lastReportStep() const
Returns the last report step stored in file.
std::vector< int > reportSteps() const
Returns a list of report steps stored in restart file.
void read(T &data, const std::string &group, const std::string &dset, HDF5File::DataSetMode mode=HDF5File::DataSetMode::PROCESS_SPLIT)
Read data and deserialize from restart file.
Definition: HDF5Serializer.hpp:83
HDF5Serializer(const std::string &fileName, HDF5File::OpenMode mode, Parallel::Communication comm)
Definition: HDF5Serializer.hpp:39
void writeHeader(const std::string &simulator_name, const std::string &module_version, const std::string &time_stamp, const std::string &case_name, const std::string &params, int num_procs)
Writes a header to the file.
void write(T &data, const std::string &group, const std::string &dset, HDF5File::DataSetMode mode=HDF5File::DataSetMode::PROCESS_SPLIT)
Serialize and write data to restart file.
Definition: HDF5Serializer.hpp:50
std::size_t pack(const PV &privar)
Definition: priVarsPacking.hpp:31
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: BlackoilPhases.hpp:27