OGS
HdfData.cpp
Go to the documentation of this file.
1 
10 #include "HdfData.h"
11 
12 #include <hdf5.h>
13 
14 #include <map>
15 
16 #include "BaseLib/Error.h"
17 #include "BaseLib/Logging.h"
18 #include "partition.h"
19 
20 namespace MeshLib::IO
21 {
22 static hid_t meshPropertyType2HdfType(MeshPropertyDataType const ogs_data_type)
23 {
24  std::map<MeshPropertyDataType const, hid_t> ogs_to_hdf_type = {
25  {MeshPropertyDataType::float64, H5T_NATIVE_DOUBLE},
26  {MeshPropertyDataType::float32, H5T_NATIVE_FLOAT},
27  {MeshPropertyDataType::int32, H5T_NATIVE_INT32},
28  {MeshPropertyDataType::int64, H5T_NATIVE_INT64},
29  {MeshPropertyDataType::uint32, H5T_NATIVE_UINT32},
30  {MeshPropertyDataType::uint64, H5T_NATIVE_UINT64},
31  {MeshPropertyDataType::int8, H5T_NATIVE_INT8},
32  {MeshPropertyDataType::uint8, H5T_NATIVE_UINT8}};
33  try
34  {
35  return ogs_to_hdf_type.at(ogs_data_type);
36  }
37  catch (std::exception const& e)
38  {
39  OGS_FATAL("No known HDF5 type for OGS type. {:s}", e.what());
40  }
41 }
42 
43 HdfData::HdfData(void const* data_start, std::size_t const size_partitioned_dim,
44  std::size_t const size_tuple, std::string const& name,
45  MeshPropertyDataType const mesh_property_data_type,
46  unsigned int const n_files)
47  : data_start(data_start), name(name)
48 {
49  auto const& partition_info =
50  getPartitionInfo(size_partitioned_dim, n_files);
51  auto const& offset_partitioned_dim = partition_info.local_offset;
52  offsets = {offset_partitioned_dim, 0};
53 
54  std::size_t unified_length = partition_info.local_length;
55 
56  chunk_space =
57  (size_tuple > 1)
58  ? std::vector<Hdf5DimType>{partition_info.longest_local_length,
59  size_tuple}
60  : std::vector<Hdf5DimType>{partition_info.longest_local_length};
61 
62  data_space = (size_tuple > 1)
63  ? std::vector<Hdf5DimType>{unified_length, size_tuple}
64  : std::vector<Hdf5DimType>{unified_length};
65  file_space =
66  (size_tuple > 1)
67  ? std::vector<Hdf5DimType>{partition_info.global_length, size_tuple}
68  : std::vector<Hdf5DimType>{partition_info.global_length};
69 
70  data_type = meshPropertyType2HdfType(mesh_property_data_type);
71 
72  DBUG(
73  "HDF: dataset name: {:s}, offset: {:d}, data_space: {:d}, chunk_space "
74  "{:d}, file_space: {:d}, tuples: {:d}",
75  name, partition_info.local_offset, data_space[0], chunk_space[0],
76  file_space[0], size_tuple);
77 }
78 } // namespace MeshLib::IO
#define OGS_FATAL(...)
Definition: Error.h:26
Collects and holds all metadata for writing HDF5 file.
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
MeshPropertyDataType
static hid_t meshPropertyType2HdfType(MeshPropertyDataType const ogs_data_type)
Definition: HdfData.cpp:22
PartitionInfo getPartitionInfo(std::size_t const size, unsigned int const n_files)
Definition: partition.cpp:33
Dispatches functions specific to execution platform (w/o MPI)
std::vector< Hdf5DimType > file_space
Definition: HdfData.h:32
std::vector< Hdf5DimType > offsets
Definition: HdfData.h:31
std::vector< Hdf5DimType > chunk_space
Definition: HdfData.h:33
std::string name
Definition: HdfData.h:34
int64_t data_type
Definition: HdfData.h:35
std::vector< Hdf5DimType > data_space
Definition: HdfData.h:30
HdfData(void const *data_start, std::size_t size_partitioned_dim, std::size_t size_tuple, std::string const &name, MeshPropertyDataType mesh_property_data_type, unsigned int n_files)
Definition: HdfData.cpp:43