29 #ifndef NEMOSYS_HDF5READER_H_ 30 #define NEMOSYS_HDF5READER_H_ 42 #include <vtkCellTypes.h> 43 #include <vtkDataSet.h> 44 #include <vtkIdList.h> 45 #include <vtkPoints2D.h> 46 #include <vtkSmartPointer.h> 47 #include <vtkUnstructuredGrid.h> 51 #include <H5Exception.h> 52 #ifndef H5_NO_NAMESPACE 67 hdf5Reader(std::string fname, std::string _outputFname,
int _verb = 0)
70 outputFname(_outputFname),
74 std::size_t _loc = h5FileName.find_last_of(
".");
75 baseH5FileName = h5FileName.substr(0, _loc);
101 int readTopDataSet(std::string dsetName, std::string &buffer);
107 int readDataSet(DataSet dset, std::string &buffer);
117 std::cout <<
"H5_VERS_MAJOR = " << H5_VERS_MAJOR << std::endl;
118 std::cout <<
"H5_VERS_MINOR = " << H5_VERS_MINOR << std::endl;
119 std::cout <<
"H5_VERS_RELEASE = " << H5_VERS_RELEASE << std::endl;
120 std::cout <<
"H5_VERS_SUBRELEASE = " << H5_VERS_SUBRELEASE << std::endl;
122 DataSet dset = file.openDataSet(dsetName);
123 readDataSet(dset, buffer);
126 catch (FileIException error) {
127 #if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 8 && H5_VERS_RELEASE >= 20 128 error.printErrorStack();
129 #elif H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 10 && H5_VERS_RELEASE >= 2 130 error.printErrorStack();
131 #elif H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 11 && H5_VERS_RELEASE >= 0 132 error.printErrorStack();
148 template <
class T>
int readDataSet(DataSet dset, std::vector<T> &buffer) {
151 DataType dtype = dset.getDataType();
153 dset.read(&buffer[0], dtype);
158 catch (DataSetIException error) {
159 #if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 8 && H5_VERS_RELEASE >= 20 160 error.printErrorStack();
161 #elif H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 10 && H5_VERS_RELEASE >= 2 162 error.printErrorStack();
163 #elif H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 11 && H5_VERS_RELEASE >= 0 164 error.printErrorStack();
180 int readGroup(std::string groupName, Group &group);
191 std::vector<T> &buffer) {
194 DataSet dset = group.openDataSet(dsetName);
196 DataType dtype = dset.getDataType();
198 dset.read(&buffer[0], dtype);
203 catch (GroupIException error) {
204 #if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 8 && H5_VERS_RELEASE >= 20 205 error.printErrorStack();
206 #elif H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 10 && H5_VERS_RELEASE >= 2 207 error.printErrorStack();
208 #elif H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 11 && H5_VERS_RELEASE >= 0 209 error.printErrorStack();
214 }
catch (DataSetIException error) {
215 #if H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 8 && H5_VERS_RELEASE >= 20 216 error.printErrorStack();
217 #elif H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 10 && H5_VERS_RELEASE >= 2 218 error.printErrorStack();
219 #elif H5_VERS_MAJOR >= 1 && H5_VERS_MINOR >= 11 && H5_VERS_RELEASE >= 0 220 error.printErrorStack();
234 std::string getFileName();
242 std::vector<T> &flatBuffer) {
244 for (
auto bufItr1 = originalBuffer.begin(); bufItr1 != originalBuffer.end();
246 for (
auto bufItr2 = (*bufItr1).begin(); bufItr2 != (*bufItr1).end();
248 flatBuffer.push_back(*bufItr2);
259 std::vector<std::vector<T>> &originalBuffer) {
261 auto flatItr = flatBuffer.begin();
262 for (
auto bufItr1 = originalBuffer.begin(); bufItr1 != originalBuffer.end();
264 for (
auto bufItr2 = (*bufItr1).begin(); bufItr2 != (*bufItr1).end();
294 void exportToVTKMesh();
298 vtkSmartPointer<vtkDataSet> getVTKMesh();
301 void exportToMeshBase();
317 void setFields(
meshBase *myMeshBase, std::vector<std::string> dataNames,
318 std::vector<std::vector<double>>
data,
int pointOrCell);
325 void setNumberOfVertices(
int numVertices);
329 void setNumberOfElements(
int numElements);
333 void setNumberOfDimensions(
int numDimensions);
337 void setCoordinates(std::vector<double> xCrd);
342 void setCoordinates(std::vector<double> xCrd, std::vector<double> yCrd);
348 void setCoordinates(std::vector<double> xCrd, std::vector<double> yCrd,
349 std::vector<double> zCrd);
353 void setConnectivities(
354 std::vector<std::map<
int, std::vector<int>>> elementConnectivity);
358 void setElementTypes(std::vector<int> vtkElementTypes);
362 void setElementTypesList(std::vector<int> vtkElementTypesList);
368 std::vector<int> getElementConnectivity(
int elementId);
381 std::vector<double> xCrd, yCrd,
zCrd;
382 std::vector<std::map<int, std::vector<int>>>
393 #endif // NEMOSYS_HDF5READER_H_
data_type data
Edge/face with sorted point ids (a, b, c, ...) is located at some index i in data[b], with data[b][i].first == [a, c] (for edges, third point id treated as -1).
H5File file
HDF5 file object.
std::string baseH5FileName
base of HDF5 filename
void unflattenBuffer2d(std::vector< T > flatBuffer, std::vector< std::vector< T >> &originalBuffer)
Unflatten 2d data buffer.
std::vector< int > vtkElementTypesList
vector storing list of each unique VTK element type
A brief description of meshBase.
std::vector< std::map< int, std::vector< int > > > elementConnectivity
element connectivity table
int readDataSet(DataSet dset, std::vector< T > &buffer)
Read numeric data from generic HDF5 DataSet.
vtkSmartPointer< vtkDataSet > vtkMesh
VTK DataSet object.
int numVertices
number of vertices in mesh
hdf5Reader(std::string fname, std::string _outputFname, int _verb=0)
Construct HDF5 reader object.
void flattenBuffer2d(std::vector< std::vector< T >> originalBuffer, std::vector< T > &flatBuffer)
Flatten 2d data buffer.
int numDimensions
number of spatial dimensions
meshBase * myMeshBase
meshBase object
std::vector< double > zCrd
vector of coordinates
std::string h5FileName
HDF5 filename.
int readTopDataSet(std::string dsetName, std::vector< T > &buffer)
Read numeric data from top level HDF5 DataSet.
int numElements
number of elements in mesh
std::string outputFname
VTK output filename.
int readGroupDataSet(std::string dsetName, Group &group, std::vector< T > &buffer)
Read numeric data from HDF5 group.
std::vector< int > vtkElementTypes
vector of VTK element type for each element
Class for reading data from HDF5 files.