Loading...
Searching...
No Matches
HDF5File.hpp
/*
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef HDF5_FILE_HPP
#define HDF5_FILE_HPP
#include <opm/simulators/utils/ParallelCommunication.hpp>
#include <hdf5.h>
#include <string>
#include <vector>
namespace Opm {
class HDF5File {
public:
enum class OpenMode {
APPEND,
OVERWRITE,
READ
};
enum class DataSetMode {
ROOT_ONLY,
PROCESS_SPLIT
};
HDF5File(const std::string& fileName,
OpenMode mode,
Parallel::Communication comm);
~HDF5File();
void write(const std::string& group,
const std::string& dset,
const std::vector<char>& buffer,
DataSetMode mode = DataSetMode::PROCESS_SPLIT) const;
void read(const std::string& group,
const std::string& dset,
std::vector<char>& buffer,
DataSetMode mode = DataSetMode::PROCESS_SPLIT) const;
std::vector<std::string> list(const std::string& group) const;
private:
void writeSplit(hid_t grp,
const std::vector<char>& buffer,
const std::string& dset) const;
void writeRootOnly(hid_t grp,
const std::vector<char>& buffer,
const std::string& group,
const std::string& dset) const;
hid_t getCompression(hsize_t size) const;
void writeDset(int rank, hid_t dataset_id,
hid_t dxpl, hsize_t size, const void* data) const;
hid_t m_file = H5I_INVALID_HID;
Parallel::Communication comm_;
};
}
#endif
Opm::HDF5File::HDF5File
HDF5File(const std::string &fileName, OpenMode mode, Parallel::Communication comm)
Opens HDF5 file for I/O.
Definition HDF5File.cpp:53
Opm::HDF5File::write
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
Opm::HDF5File::OpenMode
OpenMode
Enumeration of file opening modes.
Definition HDF5File.hpp:37
Opm::HDF5File::OpenMode::OVERWRITE
@ OVERWRITE
Overwrite and write to an existing file.
Definition HDF5File.hpp:39
Opm::HDF5File::OpenMode::READ
@ READ
Open existing file for reading.
Definition HDF5File.hpp:40
Opm::HDF5File::OpenMode::APPEND
@ APPEND
Append to an existing file (creates new if not).
Definition HDF5File.hpp:38
Opm::HDF5File::~HDF5File
~HDF5File()
Destructor clears up any opened files.
Definition HDF5File.cpp:92
Opm::HDF5File::DataSetMode
DataSetMode
Enumeration of dataset modes.
Definition HDF5File.hpp:44
Opm::HDF5File::DataSetMode::PROCESS_SPLIT
@ PROCESS_SPLIT
One separate data set for each parallel process.
Definition HDF5File.hpp:46
Opm::HDF5File::DataSetMode::ROOT_ONLY
@ ROOT_ONLY
A single dataset created at the root process.
Definition HDF5File.hpp:45
Opm::HDF5File::read
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
Opm::HDF5File::list
std::vector< std::string > list(const std::string &group) const
Lists the entries in a given group.
Definition HDF5File.cpp:175
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43