SpECTRE  v2024.09.29
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
h5 Namespace Reference

Contains functions and classes for manipulating HDF5 files. More...

Classes

class  Cce
 Represents Cauchy-Characteristic Extraction (CCE) bondi variables inside of an HDF5 file. More...
 
class  Dat
 Represents a multicolumn dat file inside an HDF5 file. More...
 
class  EosTable
 An equation of state table subfile written inside an H5 file. More...
 
class  H5File
 Opens an HDF5 file for access and allows manipulation of data. More...
 
class  Header
 Writes header info about the build, git commit, branch, etc. More...
 
class  Object
 Abstract base class representing an object in an HDF5 file. More...
 
class  SourceArchive
 Writes an archive of the source tree into a dataset. More...
 
class  StellarCollapseEos
 Reads in tabulated equation of state file from stellarcollapse.org More...
 
class  Version
 Used to store the version of the file. More...
 
class  VolumeData
 A volume data subfile written inside an H5 file. More...
 

Enumerations

enum class  AccessType { AccessType::ReadWrite , AccessType::ReadOnly }
 Set the access type to the H5File. More...
 

Functions

std::ostreamoperator<< (std::ostream &os, AccessType t)
 
bool check_src_files_match (const std::vector< std::string > &input_filenames)
 Check if all files within input_filenames have the same source archive.
 
bool check_observation_ids_match (const std::vector< std::string > &input_filenames, const std::string &subfile_name)
 Check if all files within input_filenames with volume subfile subfile_name have the same set of observation ids.
 
void combine_h5_vol (const std::vector< std::string > &file_names, const std::string &subfile_name, const std::string &output, std::optional< double > start_value=std::nullopt, std::optional< double > stop_value=std::nullopt, const std::optional< std::vector< std::string > > &blocks_to_combine=std::nullopt, bool check_src=true)
 Combine a volume subfile across different HDF5 files. More...
 
void combine_h5_dat (const std::vector< std::string > &h5_files_to_combine, const std::string &output_h5_filename, Verbosity verbosity=Verbosity::Silent)
 Combine the h5::Dat subfiles of multiple h5::H5Files into a single H5 file. More...
 
bool types_equal (hid_t dtype1, hid_t dtype2)
 Check if dtype1 and dtype2 are the same HDF5 data type.
 
template<typename T >
void write_data (hid_t group_id, const std::vector< T > &data, const std::vector< size_t > &extents, const std::string &name="scalar", const bool overwrite_existing=false)
 Write a std::vector named name to the group group_id
 
void write_data (hid_t group_id, const DataVector &data, const std::string &name, const bool overwrite_existing=false)
 Write a DataVector named name to the group group_id
 
template<size_t Dim>
void write_extents (hid_t group_id, const Index< Dim > &extents, const std::string &name="Extents")
 Write the extents as an attribute named name to the group group_id.
 
template<typename Type >
void write_to_attribute (hid_t location_id, const std::string &name, const Type &value)
 Write a value of type Type to an HDF5 attribute named name
 
template<typename T >
void write_to_attribute (hid_t group_id, const std::string &name, const std::vector< T > &data)
 Write the vector data to the attribute attribute_name in the group group_id.
 
template<typename T , size_t Size>
void write_to_attribute (hid_t group_id, const std::string &name, const std::vector< std::array< T, Size > > &data)
 Write the vector<array<fundamental, size>> data to the attribute name in the group group_id.
 
template<typename Type >
Type read_value_attribute (hid_t location_id, const std::string &name)
 Read a value of type Type from an HDF5 attribute named name
 
template<typename Type >
std::vector< Type > read_rank1_attribute (hid_t group_id, const std::string &name)
 Read rank-1 of type Type from an HDF5 attribute named name
 
template<typename T , size_t Size>
std::vector< std::array< T, Size > > read_rank1_array_attribute (hid_t group_id, const std::string &name)
 Read the vector<array<fundamental, size>> from the attribute name in the group group_id.
 
std::vector< std::stringget_attribute_names (hid_t file_id, const std::string &group_name)
 Get the names of all the attributes in a group.
 
void write_connectivity (hid_t group_id, const std::vector< int > &connectivity)
 Write the connectivity into the group in the H5 file.
 
void delete_connectivity (hid_t group_id)
 Delete the connectivity from the group in the H5 file.
 
std::array< hsize_t, 2 > append_to_dataset (hid_t file_id, const std::string &name, const std::vector< double > &data, hsize_t number_of_rows, const std::array< hsize_t, 2 > &current_file_size)
 Append rows to an existing dataset. More...
 
std::vector< std::stringget_group_names (hid_t file_id, const std::string &group_name)
 Get the names of all the groups and datasets in a group.
 
bool contains_dataset_or_group (hid_t id, const std::string &group_name, const std::string &dataset_name)
 Check if name is a dataset or group in the subgroup group_name of id. More...
 
bool contains_attribute (hid_t file_id, const std::string &group_name, const std::string &attribute_name)
 Check if an attribute is in a group.
 
hid_t open_dataset (hid_t group_id, const std::string &dataset_name)
 Open an HDF5 dataset.
 
void close_dataset (hid_t dataset_id)
 Close an HDF5 dataset.
 
hid_t open_dataspace (hid_t dataset_id)
 Open an HDF5 dataspace.
 
void close_dataspace (hid_t dataspace_id)
 Close an HDF5 dataspace.
 
template<size_t Rank, typename T >
read_data (hid_t group_id, const std::string &dataset_name)
 Read an array of rank 0-3 into an object. More...
 
template<size_t Dim>
Index< Dim > read_extents (hid_t group_id, const std::string &extents_name="Extents")
 Read the HDF5 attribute representing extents from a group.
 
template<typename T >
hid_t h5_type ()
 Returns the HDF5 datatype for the corresponding type T More...
 
hid_t fortran_string ()
 Create an H5 FORTRAN string.
 
std::pair< size_t, size_t > offset_and_length_for_grid (const std::string &grid_name, const std::vector< std::string > &all_grid_names, const std::vector< std::vector< size_t > > &all_extents)
 Find the interval within the contiguous dataset stored in h5::VolumeData that holds data for a particular grid_name. More...
 
template<size_t Dim>
Mesh< Dim > mesh_for_grid (const std::string &grid_name, const std::vector< std::string > &all_grid_names, const std::vector< std::vector< size_t > > &all_extents, const std::vector< std::vector< Spectral::Basis > > &all_bases, const std::vector< std::vector< Spectral::Quadrature > > &all_quadratures)
 
auto h5f_acc_rdonly ()
 
auto h5f_acc_rdwr ()
 
auto h5f_acc_trunc ()
 
auto h5p_default ()
 
auto h5s_all ()
 
auto h5s_unlimited ()
 
auto h5s_scalar ()
 
template<typename T >
retrieve_dataset (hid_t file_id, const std::array< hsize_t, 2 > &file_size)
 Convert the data in a dataset to a Matrix or a std::vector<std::vector<double>>
 
template<typename T >
retrieve_dataset_subset (hid_t file_id, const std::vector< size_t > &these_columns, size_t first_row, size_t num_rows, const std::array< hsize_t, 2 > &file_size)
 Convert the data in a dataset to a Matrix or a std::vector<std::vector<double>>
 

Detailed Description

Contains functions and classes for manipulating HDF5 files.

Wraps many underlying C H5 routines making them easier to use and easier to manipulate H5 files.

Function Documentation

◆ combine_h5_dat()

void h5::combine_h5_dat ( const std::vector< std::string > &  h5_files_to_combine,
const std::string output_h5_filename,
Verbosity  verbosity = Verbosity::Silent 
)

Combine the h5::Dat subfiles of multiple h5::H5Files into a single H5 file.

Details

The times in each h5::Dat subfile can be unordered. The necessary sorting will be handled in this function. However, the h5_files_to_combine must be mononitcally increasing in time; meaning the earliest time in File1.h5 must come before the earliest time in File2.h5.

If there are overlapping times, the "latest" one is always used; meaning if you have data in File1.h5 and File2.h5 and if the earliest time in File2.h5 is before some times in File1.h5, those times in File1.h5 will be discarded and won't appear in the combined H5 file.

If the H5 files in h5_files_to_combine have other types of subfiles, those will be ignored and will not appear in output_h5_filename.

If h5_files_to_combine is empty, an error will occur.

If there are no h5::Dat files in the h5_files_to_combine, an error will occur.

If the legend or version of an h5::Dat is not the same in all of h5_files_to_combine, an error will occur.

Parameters
h5_files_to_combineVector of H5 files to combine. They must all have the same h5::Dat filenames, and those h5::Dat subfiles must have the same legends and versions. If not, an error will occur.
output_h5_filenameName of the combined H5 file. The h5::Dat subfile structure will be identical to the ones in h5_files_to_combine.
verbosityControls how much is printed to stdout. Defaults to no Verbosity::Silent or no output.

◆ combine_h5_vol()

void h5::combine_h5_vol ( const std::vector< std::string > &  file_names,
const std::string subfile_name,
const std::string output,
std::optional< double >  start_value = std::nullopt,
std::optional< double >  stop_value = std::nullopt,
const std::optional< std::vector< std::string > > &  blocks_to_combine = std::nullopt,
bool  check_src = true 
)

Combine a volume subfile across different HDF5 files.

The argument blocks_to_combine can list block names and block groups that should be combined. We ignore other blocks when combining the HDF5 files. This provides a way to filter volume data for easier visualization.

◆ offset_and_length_for_grid()

std::pair< size_t, size_t > h5::offset_and_length_for_grid ( const std::string grid_name,
const std::vector< std::string > &  all_grid_names,
const std::vector< std::vector< size_t > > &  all_extents 
)

Find the interval within the contiguous dataset stored in h5::VolumeData that holds data for a particular grid_name.

h5::VolumeData stores data for all grids that compose the volume contiguously. This function helps with reconstructing which part of that contiguous dataset belongs to a particular grid. See the h5::VolumeData documentation for more information on how it stores data.

To use this function, call h5::VolumeData::get_grid_names and h5::VolumeData::get_extents and pass the results for the all_grid_names and all_extents arguments, respectively. This means you can retrieve this information from an h5::VolumeData once and use it to call offset_and_length_for_grid multiple times with different grid_names.

Here is an example for using this function:

const auto all_grid_names = volume_file.get_grid_names(observation_id);
const auto all_extents = volume_file.get_extents(observation_id);
const auto first_grid_offset_and_length = h5::offset_and_length_for_grid(
grid_names.front(), all_grid_names, all_extents);
std::pair< size_t, size_t > offset_and_length_for_grid(const std::string &grid_name, const std::vector< std::string > &all_grid_names, const std::vector< std::vector< size_t > > &all_extents)
Find the interval within the contiguous dataset stored in h5::VolumeData that holds data for a partic...
See also
h5::VolumeData