OpenImpala
Image-based parallel transport property solver
Loading...
Searching...
No Matches
HDF5Reader.H
Go to the documentation of this file.
1
4#ifndef HDF5_READER_H
5#define HDF5_READER_H
6
7#include <string>
8#include <vector> // Still needed for other things potentially
9#include <map>
10#include <stdexcept> // For std::runtime_error
11
12#include <AMReX_REAL.H>
13#include <AMReX_Box.H>
14#include <AMReX_iMultiFab.H> // Now central
15
16// --- HDF5 C++ API Include ---
17#include <H5Cpp.h>
18
19namespace OpenImpala {
20
38public:
42 HDF5Reader();
43
56 explicit HDF5Reader(const std::string& filename, const std::string& hdf5dataset);
57
61 virtual ~HDF5Reader() = default;
62
63 // --- Deleted Copy Operations ---
64 HDF5Reader(const HDF5Reader&) = delete;
65 HDF5Reader& operator=(const HDF5Reader&) = delete;
66
67 // --- Optional: Default Move Operations (C++11) ---
68 HDF5Reader(HDF5Reader&&) = default;
70
82 bool readFile(const std::string& filename, const std::string& hdf5dataset);
83
98 void threshold(double raw_threshold, amrex::iMultiFab& mf) const;
99
117 void threshold(double raw_threshold, int value_if_true, int value_if_false,
118 amrex::iMultiFab& mf) const;
119
126 amrex::Box box() const;
127
129 int width() const;
130
132 int height() const;
133
135 int depth() const;
136
142 std::string getAttribute(const std::string& attr_name) const;
143
150 std::map<std::string, std::string> getAllAttributes() const;
151
153 bool isRead() const {
154 return m_is_read;
155 }
156
158 H5::DataType getNativeDataType() const {
159 return m_native_type;
160 }
161
162
163 // --- Implementation methods (public for CUDA __device__ lambda compatibility) ---
164 // Template function to read a hyperslab and apply thresholding
165 // Needed because the native type read from file varies.
166 template <typename T_Native>
167 void readAndThresholdFab(H5::DataSet& dataset, double raw_threshold, int value_if_true,
168 int value_if_false, const amrex::Box& box,
169 amrex::IArrayBox& fab) const;
170
171private:
178 bool readMetadataInternal();
179
180 // --- Member Variables ---
181 std::string m_filename;
182 std::string m_hdf5dataset;
183 int m_width = 0;
184 int m_height = 0;
185 int m_depth = 0;
186 bool m_is_read = false;
187 H5::DataType m_native_type;
188
189}; // class HDF5Reader
190
191} // namespace OpenImpala
192
193#endif // HDF5_READER_H
HDF5Reader(const HDF5Reader &)=delete
void readAndThresholdFab(H5::DataSet &dataset, double raw_threshold, int value_if_true, int value_if_false, const amrex::Box &box, amrex::IArrayBox &fab) const
Definition HDF5Reader.cpp:266
void threshold(double raw_threshold, amrex::iMultiFab &mf) const
Reads data chunk-by-chunk into an iMultiFab based on thresholding.
Definition HDF5Reader.cpp:444
std::map< std::string, std::string > getAllAttributes() const
Reads all attributes from the HDF5 dataset. Attempts to read attribute values as strings.
Definition HDF5Reader.cpp:230
H5::DataType getNativeDataType() const
Get the native HDF5 data type detected in the dataset.
Definition HDF5Reader.H:158
virtual ~HDF5Reader()=default
Virtual default destructor.
std::string getAttribute(const std::string &attr_name) const
Reads a specific string attribute from the HDF5 dataset.
Definition HDF5Reader.cpp:213
HDF5Reader & operator=(const HDF5Reader &)=delete
bool isRead() const
Check if metadata has been successfully read.
Definition HDF5Reader.H:153
int width() const
Get width (X-dimension) of the dataset in pixels/voxels.
Definition HDF5Reader.cpp:193
HDF5Reader()
Default constructor. Creates an empty reader. Use readFile() later.
Definition HDF5Reader.cpp:82
int depth() const
Get depth (Z-dimension) of the dataset in pixels/voxels.
Definition HDF5Reader.cpp:199
int height() const
Get height (Y-dimension) of the dataset in pixels/voxels.
Definition HDF5Reader.cpp:196
HDF5Reader(HDF5Reader &&)=default
HDF5Reader & operator=(HDF5Reader &&)=default
amrex::Box box() const
Returns the index space Box covering the entire image domain [0, w-1] x [0, h-1] x [0,...
Definition HDF5Reader.cpp:202
bool readFile(const std::string &filename, const std::string &hdf5dataset)
Reads metadata (dimensions, datatype) from the specified HDF5 file and dataset.
Definition HDF5Reader.cpp:101
Definition CathodeWrite.cpp:12