VolumeData.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <cstdint>
8 #include <hdf5.h>
9 #include <string>
10 #include <vector>
11 
12 #include "IO/H5/Object.hpp"
13 #include "IO/H5/OpenGroup.hpp"
14 
15 /// \cond
16 class DataVector;
18 /// \endcond
19 
20 namespace h5 {
21 /*!
22  * \ingroup HDF5Group
23  * \brief A volume data subfile written inside an H5 file.
24  *
25  * The volume data inside the subfile can be of any dimensionality greater than
26  * zero. This means that in a 3D simulation, data on 2-dimensional surfaces are
27  * written as a VolumeData subfile. Data can be written using the
28  * `insert_tensor_data()` method. An integral observation id is used to keep
29  * track of the observation instance at which the data is written, and
30  * associated with it is a floating point observation value, such as the
31  * simulation time at which the data was written. The observation id will
32  * generally be the result of hashing the temporal identifier used for the
33  * simulation.
34  *
35  * The data stored in the subfile are the tensor components passed to the
36  * `insert_tensor_data()` method as a `ExtentsAndTensorVolumeData`. The name of
37  * each tensor component must follow the format
38  * `GRID_NAME/TENSOR_NAME_COMPONENT`, e.g. `Element0/T_xx`. Typically the
39  * `GRID_NAME` should be the output of the stream operator of the spatial ID of
40  * the parallel component element sending the data to be observed. For example,
41  * in the case of a dG evolution where the spatial IDs are `ElementId`s, the
42  * grid names would be of the form `[B0,(L2I3,L2I3,L2I3)]`.
43  *
44  * \warning Currently the topology of the grids is assumed to be tensor products
45  * of lines, i.e. lines, quadrilaterals, and hexahedrons. However, this can be
46  * extended in the future. If support for more topologies is required, please
47  * file an issue.
48  */
49 class VolumeData : public h5::Object {
50  public:
51  static std::string extension() noexcept { return ".vol"; }
52 
53  VolumeData(bool exists, detail::OpenGroup&& group, hid_t location,
54  const std::string& name, uint32_t version = 1) noexcept;
55 
56  VolumeData(const VolumeData& /*rhs*/) = delete;
57  VolumeData& operator=(const VolumeData& /*rhs*/) = delete;
58  VolumeData(VolumeData&& /*rhs*/) noexcept = delete; // NOLINT
59  VolumeData& operator=(VolumeData&& /*rhs*/) noexcept = delete; // NOLINT
60 
61  ~VolumeData() override = default;
62 
63  /*!
64  * \returns the header of the VolumeData file
65  */
66  const std::string& get_header() const noexcept { return header_; }
67 
68  /*!
69  * \returns the user-specified version number of the VolumeData file
70  *
71  * \note h5::Version returns a uint32_t, so we return one here too for the
72  * version
73  */
74  uint32_t get_version() const noexcept { return version_; }
75 
76  /// Insert tensor components at `observation_id` with floating point value
77  /// `observation_value`
78  ///
79  /// \requires The names of the tensor components is of the form
80  /// `GRID_NAME/TENSOR_NAME_COMPONENT`, e.g. `Element0/T_xx`
81  void insert_tensor_data(
82  size_t observation_id, double observation_value,
83  const ExtentsAndTensorVolumeData& extents_and_tensors) noexcept;
84 
85  /// List all the integral observation ids in the subfile
87 
88  /// Get the observation value at the the integral observation id in the
89  /// subfile
90  double get_observation_value(size_t observation_id) const noexcept;
91 
92  /// List all the grid ids at the the integral observation id in the
93  /// subfile
94  std::vector<std::string> list_grids(size_t observation_id) const noexcept;
95 
96  /// List all the tensor components on the grid `grid_name` at observation id
97  /// `observation_id`
99  size_t observation_id, const std::string& grid_name) const noexcept;
100 
101  /// Read a tensor component with name `tensor_component` from the grid
102  /// `grid_name` at the observation id `observation_id`
103  DataVector get_tensor_component(size_t observation_id,
104  const std::string& grid_name,
105  const std::string& tensor_component) const
106  noexcept;
107 
108  /// Read the extents of the grid `grid_name` at the observation id
109  /// `observation_id`
110  std::vector<size_t> get_extents(size_t observation_id,
111  const std::string& grid_name) const noexcept;
112 
113  private:
114  detail::OpenGroup group_{};
115  std::string name_{};
116  uint32_t version_{};
117  detail::OpenGroup volume_data_group_{};
118  std::string header_{};
119 };
120 } // namespace h5
std::vector< std::string > list_tensor_components(size_t observation_id, const std::string &grid_name) const noexcept
List all the tensor components on the grid grid_name at observation id observation_id ...
Defines class OpenGroup for opening groups in HDF5.
Contains functions and classes for manipulating HDF5 files.
Definition: AccessType.cpp:10
Defines class h5::Object abstract base class.
void insert_tensor_data(size_t observation_id, double observation_value, const ExtentsAndTensorVolumeData &extents_and_tensors) noexcept
Insert tensor components at observation_id with floating point value observation_value ...
std::vector< std::string > list_grids(size_t observation_id) const noexcept
List all the grid ids at the the integral observation id in the subfile.
std::vector< size_t > list_observation_ids() const noexcept
List all the integral observation ids in the subfile.
Abstract base class representing an object in an HDF5 file.
Definition: Object.hpp:14
DataVector get_tensor_component(size_t observation_id, const std::string &grid_name, const std::string &tensor_component) const noexcept
Read a tensor component with name tensor_component from the grid grid_name at the observation id obse...
A volume data subfile written inside an H5 file.
Definition: VolumeData.hpp:49
std::vector< size_t > get_extents(size_t observation_id, const std::string &grid_name) const noexcept
Read the extents of the grid grid_name at the observation id observation_id
uint32_t get_version() const noexcept
Definition: VolumeData.hpp:74
Stores a collection of function values.
Definition: DataVector.hpp:46
Holds the extents of the mesh and the tensor components on the mesh.
Definition: TensorData.hpp:55
const std::string & get_header() const noexcept
Definition: VolumeData.hpp:66
double get_observation_value(size_t observation_id) const noexcept
Get the observation value at the the integral observation id in the subfile.