Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
HDF5Toolbox_decl.hpp
1#ifndef HDF5TOOLBOX_DECL_hpp
2#define HDF5TOOLBOX_DECL_hpp
3
4#include <hdf5.h>
5#include <H5FDmpio.h>
6
7#include <Tpetra_Core.hpp>
8#include "feddlib/core/General/DefaultTypeDefs.hpp"
9#include "feddlib/core/LinearAlgebra/MultiVector.hpp"
10#include "feddlib/core/LinearAlgebra/Map.hpp"
11
20
21namespace FEDD {
27template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
28class HDF5Toolbox{
29
30 public:
31 typedef Teuchos::Comm<int> Comm_Type;
32 typedef Teuchos::RCP<Comm_Type> CommPtr_Type;
33 typedef Teuchos::RCP<const Comm_Type> CommConstPtr_Type;
34
35 typedef MultiVector<SC,LO,GO,NO> MultiVector_Type;
36 typedef Teuchos::RCP<MultiVector_Type> MultiVectorPtr_Type;
37 typedef Teuchos::RCP<const MultiVector_Type> MultiVectorConstPtr_Type;
38
39 typedef Map<LO,GO,NO> Map_Type;
40 typedef Teuchos::RCP<Map_Type> MapPtr_Type;
41 typedef Teuchos::RCP<const Map_Type> MapConstPtr_Type;
42
43 HDF5Toolbox(CommConstPtr_Type Comm);
44
48 void write(const std::string &GroupName, const MultiVectorConstPtr_Type X, bool writeTranspose = false);
49
50 bool isContained(std::string Name, std::string GroupName = "");
51
52 void createGroup(const std::string &GroupName);
53
54 void write(const std::string &GroupName, const std::string &DataSetName, double what);
55
56 void write(const std::string &GroupName, const std::string &DataSetName, int what);
57
58 void write(const std::string &GroupName, const std::string &DataSetName, const std::string &data);
59
60 ~HDF5Toolbox()
61 {
62 if (isOpen())
63 close();
64 }
65
66 void read(const std::string &GroupName, const MapConstPtr_Type Map, MultiVectorPtr_Type X);
67
68 void readIntVectorProperties(const std::string &GroupName, int &GlobalLength);
69
70 void read(const std::string &GroupName, const std::string &DataSetName, GO MySize, int GlobalSize, const hid_t type, void *data);
71
72 void read(const std::string &GroupName, const std::string &DataSetName, int &data);
73
74 void read(const std::string &GroupName, const std::string &DataSetName, std::string &data);
75
76 void tpetraScanSum(const Teuchos::RCP<const Teuchos::Comm<int>> &comm, const GO *sendbuf, GO *recvbuf, int count);
77
79 void create(const std::string FileName);
80
82 void open(const std::string FileName, int AccessType = H5F_ACC_RDWR);
83
85 void close()
86 {
87
88 // ssize_t nopen = H5Fget_obj_count(file_id_, H5F_OBJ_ALL);
89
90 // if (nopen > 0) {
91 // std::cout << "[Rank " << comm_->getRank()
92 // << "] HDF5 objects still open before H5Fclose: " << nopen << std::endl;
93 // H5Fget_obj_count(file_id_, H5F_OBJ_ALL);
94 // H5Fget_obj_ids(file_id_, H5F_OBJ_ALL, 0, nullptr);
95
96
97 // ssize_t num = H5Fget_obj_count(file_id_, H5F_OBJ_ALL);
98 // std::vector<hid_t> ids(num);
99 // H5Fget_obj_ids(file_id_, H5F_OBJ_ALL, num, ids.data());
100
101 // for (auto id : ids) {
102 // unsigned int type = H5Iget_type(id);
103 // const char* tname =
104 // (type == H5I_GROUP) ? "group" :
105 // (type == H5I_DATASET) ? "dataset" :
106 // (type == H5I_DATASPACE) ? "dataspace" :
107 // (type == H5I_DATATYPE) ? "datatype" :
108 // (type == H5I_ATTR) ? "attribute" : "unknown";
109
110 // std::cout << "[Rank " << comm_->getRank() << "] Still open: " << tname
111 // << " (id=" << id << ")\n";
112 // }
113 // }
114
115 H5Fclose(file_id_);
116 isOpen_ = false;
117
118 }
119
121 void flush()
122 {
123 H5Fflush(file_id_, H5F_SCOPE_GLOBAL);
124 }
125
127 bool isOpen() const
128 {
129 return(isOpen_);
130 }
131
132 private:
133 bool isOpen_; // Flag if file is open
134 CommConstPtr_Type comm_;
135 hid_t file_id_;
136 hid_t plist_id_;
137 herr_t status;
138 std::string FileName_;
139};
140
141}
142
143#endif
void open(const std::string FileName, int AccessType=H5F_ACC_RDWR)
Open specified file with given access type.
Definition HDF5Toolbox_def.hpp:576
void close()
Close the file.
Definition HDF5Toolbox_decl.hpp:85
void create(const std::string FileName)
Create a new file.
Definition HDF5Toolbox_def.hpp:327
void createGroup(const std::string &GroupName)
Create group GroupName.
Definition HDF5Toolbox_def.hpp:441
bool isContained(std::string Name, std::string GroupName="")
Checking if the dataset Name is contained in the group GroupName.
Definition HDF5Toolbox_def.hpp:410
void write(const std::string &GroupName, const MultiVectorConstPtr_Type X, bool writeTranspose=false)
Write/export a vector X to the HDF5 file under the group name GroupName.
Definition HDF5Toolbox_def.hpp:35
bool isOpen() const
Return true if a file has already been opened using Open()/Create()
Definition HDF5Toolbox_decl.hpp:127
void flush()
Flush the content to the file.
Definition HDF5Toolbox_decl.hpp:121
Definition Map_decl.hpp:30
Definition MultiVector_decl.hpp:61
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36