KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
List of all members
Kratos::HDF5::File Class Reference

A base class for reading and writing an HDF5 file. More...

#include <hdf5_file.h>

Collaboration diagram for Kratos::HDF5::File:

Public Member Functions

Life Cycle
 File (const DataCommunicator &rDataCommunicator, Parameters Settings)
 
 File (const File &rOther)=delete
 
 File (File &&rOther)
 
virtual ~File ()
 
Fileoperator= (const File &rOther)=delete
 
Fileoperator= (File &&rOther)
 
Public operations
bool HasPath (const std::string &rPath) const
 Checks if the given rPath exists. More...
 
bool IsGroup (const std::string &rPath) const
 Checks if rPath contains a group. More...
 
bool IsDataSet (const std::string &rPath) const
 Checks if rPath is a dataset. More...
 
bool HasAttribute (const std::string &rObjectPath, const std::string &rName) const
 Checks if the given rName attribute exists in rObjectPath. More...
 
template<class TDataType >
bool HasAttributeType (const std::string &rObjectPath, const std::string &rName) const
 Checks if the attribute is of the specified type. More...
 
std::vector< hsize_t > GetAttributeDimensions (const std::string &rObjectPath, const std::string &rName) const
 Get the Attribute Dimensions. More...
 
void DeleteAttribute (const std::string &rObjectPath, const std::string &rName)
 Deletes the specified attribute from the dataset or group. More...
 
std::vector< std::string > GetAttributeNames (const std::string &rObjectPath) const
 Get the Attributes' Names list. More...
 
void CreateGroup (const std::string &rPath)
 Create a Group. More...
 
std::vector< std::string > GetLinkNames (const std::string &rGroupPath) const
 Get the link names under a group. More...
 
std::vector< std::string > GetGroupNames (const std::string &rGroupPath) const
 Get the sub group names under a group. More...
 
std::vector< std::string > GetDataSetNames (const std::string &rGroupPath) const
 Get the dataset names under a group. More...
 
void AddPath (const std::string &rPath)
 Add a group to the path recursively. More...
 
template<class TDataType >
void WriteAttribute (const std::string &rObjectPath, const std::string &rName, const TDataType &rValue)
 Write attributes to specified group or dataset. More...
 
void WriteAttribute (const std::string &rObjectPath, const Parameters Attributes)
 Write attributes in a Parameters object to dataset or group. More...
 
template<class TDataType >
void WriteDataSet (const std::string &rPath, const TDataType &rData, WriteInfo &rInfo)
 Write a dataset to the hDF5 file. More...
 
template<class TDataType >
void WriteDataSetIndependent (const std::string &rPath, const TDataType &rData, WriteInfo &rInfo)
 Independently write dataset to the HDF5 file. More...
 
std::vector< unsigned > GetDataDimensions (const std::string &rPath) const
 Get the shape of the dataset stored at the specified path. More...
 
bool HasIntDataType (const std::string &rPath) const
 Checks if the dataset at path is of int type. More...
 
bool HasFloatDataType (const std::string &rPath) const
 Checks if the dataset at path is of double type. More...
 
template<class TDataType >
bool HasDataType (const std::string &rPath) const
 Checks the datast at path is of TDataType. More...
 
void Flush ()
 Flush the content to HDF5 file. More...
 
void Close ()
 Terminate access to the HDF5 file. More...
 
unsigned GetFileSize () const
 
std::string GetFileName () const
 
int GetEchoLevel () const
 
void SetEchoLevel (int Level)
 
const DataCommunicatorGetDataCommunicator () const
 
unsigned GetPID () const
 Get the process rank. More...
 
unsigned GetTotalProcesses () const
 Get the Total number of processes with file access. More...
 
template<class TDataType >
void ReadAttribute (const std::string &rObjectPath, const std::string &rName, TDataType &rValue) const
 Read attribute from a group or dataset. More...
 
Parameters ReadAttribute (const std::string &rObjectPath) const
 Read attributes from a dataset or group to a Parameters object. More...
 
template<class TDataType >
void ReadDataSet (const std::string &rPath, TDataType &rData, const unsigned StartIndex, const unsigned BlockSize) const
 Read a dataset from the HDF5 file. More...
 
template<class TDataType >
void ReadDataSetIndependent (const std::string &rPath, TDataType &rData, const unsigned StartIndex, const unsigned BlockSize) const
 Independently read a dataset from the HDF5 file. More...
 
unsigned GetOpenObjectsCount () const
 

Type Definitions

template<class T >
using Vector = HDF5::Vector< T >
 
template<class T >
using Matrix = HDF5::Matrix< T >
 
 KRATOS_CLASS_POINTER_DEFINITION (File)
 Pointer definition. More...
 

Detailed Description

A base class for reading and writing an HDF5 file.

This class stores the file id and is responsible for reading and writing meta data. Reading and writing data sets is the responsibility of the derived class.

Member Typedef Documentation

◆ Matrix

template<class T >
using Kratos::HDF5::File::Matrix = HDF5::Matrix<T>

◆ Vector

template<class T >
using Kratos::HDF5::File::Vector = HDF5::Vector<T>

Constructor & Destructor Documentation

◆ File() [1/3]

Kratos::HDF5::File::File ( const DataCommunicator rDataCommunicator,
Parameters  Settings 
)
explicit

◆ File() [2/3]

Kratos::HDF5::File::File ( const File rOther)
delete

◆ File() [3/3]

Kratos::HDF5::File::File ( File &&  rOther)

◆ ~File()

Kratos::HDF5::File::~File ( )
virtual

Member Function Documentation

◆ AddPath()

void Kratos::HDF5::File::AddPath ( const std::string &  rPath)

Add a group to the path recursively.

This method creates all the parent groups to create the final rPath.

Exceptions
Ifany of the parents in the rPath is not a group.
Parameters
rPathPath to be created.

◆ Close()

void Kratos::HDF5::File::Close ( )

Terminate access to the HDF5 file.

Exceptions
Ifthe underlying HDF5 call fails.
Returns
* void

◆ CreateGroup()

void Kratos::HDF5::File::CreateGroup ( const std::string &  rPath)

Create a Group.

Parameters
rPathPath of the group to be created.

◆ DeleteAttribute()

void Kratos::HDF5::File::DeleteAttribute ( const std::string &  rObjectPath,
const std::string &  rName 
)

Deletes the specified attribute from the dataset or group.

Parameters
rObjectPathPath of a dataset or group.
rNameAttribute name to be deleted.

◆ Flush()

void Kratos::HDF5::File::Flush ( )

Flush the content to HDF5 file.

◆ GetAttributeDimensions()

std::vector< hsize_t > Kratos::HDF5::File::GetAttributeDimensions ( const std::string &  rObjectPath,
const std::string &  rName 
) const

Get the Attribute Dimensions.

Parameters
rObjectPathDataset or group path.
rNameAttribute name.
Returns
std::vector<hsize_t> Size in each dimension.

◆ GetAttributeNames()

std::vector< std::string > Kratos::HDF5::File::GetAttributeNames ( const std::string &  rObjectPath) const

Get the Attributes' Names list.

Parameters
rObjectPathPath of a dataset or group.
Returns
std::vector<std::string> List of attribute names.

◆ GetDataCommunicator()

const DataCommunicator & Kratos::HDF5::File::GetDataCommunicator ( ) const

◆ GetDataDimensions()

std::vector< unsigned > Kratos::HDF5::File::GetDataDimensions ( const std::string &  rPath) const

Get the shape of the dataset stored at the specified path.

Parameters
rPathDataset path.
Returns
std::vector<unsigned> Dimensions of the dataset.

◆ GetDataSetNames()

std::vector< std::string > Kratos::HDF5::File::GetDataSetNames ( const std::string &  rGroupPath) const

Get the dataset names under a group.

Parameters
rGroupPathGroup path.
Returns
std::vector<std::string> List of sub dataset names.

◆ GetEchoLevel()

int Kratos::HDF5::File::GetEchoLevel ( ) const

◆ GetFileName()

std::string Kratos::HDF5::File::GetFileName ( ) const

◆ GetFileSize()

unsigned Kratos::HDF5::File::GetFileSize ( ) const

◆ GetGroupNames()

std::vector< std::string > Kratos::HDF5::File::GetGroupNames ( const std::string &  rGroupPath) const

Get the sub group names under a group.

Parameters
rGroupPathGroup path.
Returns
std::vector<std::string> List of sub group names.

◆ GetLinkNames()

std::vector< std::string > Kratos::HDF5::File::GetLinkNames ( const std::string &  rGroupPath) const

Get the link names under a group.

Parameters
rGroupPathGroup path.
Returns
std::vector<std::string> List of link names.

◆ GetOpenObjectsCount()

unsigned Kratos::HDF5::File::GetOpenObjectsCount ( ) const

◆ GetPID()

unsigned Kratos::HDF5::File::GetPID ( ) const

Get the process rank.

◆ GetTotalProcesses()

unsigned Kratos::HDF5::File::GetTotalProcesses ( ) const

Get the Total number of processes with file access.

◆ HasAttribute()

bool Kratos::HDF5::File::HasAttribute ( const std::string &  rObjectPath,
const std::string &  rName 
) const

Checks if the given rName attribute exists in rObjectPath.

Parameters
rObjectPathPath of a dataset or a group.
rNameAttribute name.
Returns
true True if attribute exists in the dataset or group, otherwise false.

◆ HasAttributeType()

template<class TDataType >
bool Kratos::HDF5::File::HasAttributeType ( const std::string &  rObjectPath,
const std::string &  rName 
) const

Checks if the attribute is of the specified type.

Template Parameters
TDataTypeData type to check.
Parameters
rObjectPathDataset or group path.
rNameAttribute name.
Returns
true If the attribute has data of type TDataType.
false If the attribute does not has the data of type TDataType.

◆ HasDataType()

template<class TDataType >
bool Kratos::HDF5::File::HasDataType ( const std::string &  rPath) const

Checks the datast at path is of TDataType.

Template Parameters
TDataTypeDatatype to check against.
Parameters
rPathDataset path.
Returns
true If dataset is of TDataType.
false If dataset is not of TDataType.

◆ HasFloatDataType()

bool Kratos::HDF5::File::HasFloatDataType ( const std::string &  rPath) const

Checks if the dataset at path is of double type.

Parameters
rPathDataset path.
Returns
true If dataset of double type.
false If dataset is not of double type.

◆ HasIntDataType()

bool Kratos::HDF5::File::HasIntDataType ( const std::string &  rPath) const

Checks if the dataset at path is of int type.

Parameters
rPathDataset path.
Returns
true If dataset of int type.
false If dataset is not of int type.

◆ HasPath()

bool Kratos::HDF5::File::HasPath ( const std::string &  rPath) const

Checks if the given rPath exists.

Exceptions
Ifa string with invalid characters is given.
Parameters
rPathPath to be checked.
Returns
true True if rPath exists, otherwise false.

◆ IsDataSet()

bool Kratos::HDF5::File::IsDataSet ( const std::string &  rPath) const

Checks if rPath is a dataset.

Parameters
rPathPath to be checked for.
Returns
true True if rPath exists and it is a dataset, otherwise false.

◆ IsGroup()

bool Kratos::HDF5::File::IsGroup ( const std::string &  rPath) const

Checks if rPath contains a group.

Parameters
rPathPath to be checked for.
Returns
true True if rPath exists and it is a group., otherwise false.

◆ KRATOS_CLASS_POINTER_DEFINITION()

Kratos::HDF5::File::KRATOS_CLASS_POINTER_DEFINITION ( File  )

Pointer definition.

◆ operator=() [1/2]

File& Kratos::HDF5::File::operator= ( const File rOther)
delete

◆ operator=() [2/2]

File & Kratos::HDF5::File::operator= ( File &&  rOther)

◆ ReadAttribute() [1/2]

Parameters Kratos::HDF5::File::ReadAttribute ( const std::string &  rObjectPath) const

Read attributes from a dataset or group to a Parameters object.

Parameters
rObjectPathDataset or group path.
Returns
Parameters Parameters object containing attribute name, value pairs.

◆ ReadAttribute() [2/2]

template<class TDataType >
void Kratos::HDF5::File::ReadAttribute ( const std::string &  rObjectPath,
const std::string &  rName,
TDataType &  rValue 
) const

Read attribute from a group or dataset.

Template Parameters
TDataTypeDatatype of the attribute.
Parameters
rObjectPathGroup or dataset path.
rNameAttribute name.
rValueAttribute value to be written to.

◆ ReadDataSet()

template<class TDataType >
void Kratos::HDF5::File::ReadDataSet ( const std::string &  rPath,
TDataType &  rData,
const unsigned  StartIndex,
const unsigned  BlockSize 
) const

Read a dataset from the HDF5 file.

Performs collective read in MPI. Throws if out of range.

Exceptions
ifout of range.
Template Parameters
TDataTypeDatatype of the read data.
Parameters
rPathPath of the dataset.
rDataData to be written to.
StartIndexStarting offset of data for this rank.
BlockSizeNumber of data points for this rank.

◆ ReadDataSetIndependent()

template<class TDataType >
void Kratos::HDF5::File::ReadDataSetIndependent ( const std::string &  rPath,
TDataType &  rData,
const unsigned  StartIndex,
const unsigned  BlockSize 
) const

Independently read a dataset from the HDF5 file.

Performs independent read in MPI. Throws if out of range.

Template Parameters
TDataTypeDatatype of the read data.
Parameters
rPathPath of the dataset.
rDataData to be written to.
StartIndexStarting offset of data for this rank.
BlockSizeNumber of data points for this rank.

◆ SetEchoLevel()

void Kratos::HDF5::File::SetEchoLevel ( int  Level)

◆ WriteAttribute() [1/2]

void Kratos::HDF5::File::WriteAttribute ( const std::string &  rObjectPath,
const Parameters  Attributes 
)

Write attributes in a Parameters object to dataset or group.

Parameters
rObjectPathDataset or group path.
AttributesAttributes to be written to.

◆ WriteAttribute() [2/2]

template<class TDataType >
void Kratos::HDF5::File::WriteAttribute ( const std::string &  rObjectPath,
const std::string &  rName,
const TDataType &  rValue 
)

Write attributes to specified group or dataset.

Template Parameters
TDataTypeData type of the attribute.
Parameters
rObjectPathGroup or dataset path.
rNameAttribute name.
rValueAtribute data.

◆ WriteDataSet()

template<class TDataType >
void Kratos::HDF5::File::WriteDataSet ( const std::string &  rPath,
const TDataType &  rData,
WriteInfo rInfo 
)

Write a dataset to the hDF5 file.

Performs collective write in MPI. The data is written blockwise according to processor rank.

Template Parameters
TDataTypeData type of the provided data.
Parameters
rPathPath to which the data is written.
rDataData to be written.
rInfoInformation about the written data (output).

◆ WriteDataSetIndependent()

template<class TDataType >
void Kratos::HDF5::File::WriteDataSetIndependent ( const std::string &  rPath,
const TDataType &  rData,
WriteInfo rInfo 
)

Independently write dataset to the HDF5 file.

Performs independent write in MPI. Must be called collectively. Throws if more than one process has non-empty data.

Template Parameters
TDataTypeData type of the Data.
Parameters
rPathPath to which the data is written.
rDataData to be written.
rInfoInformation about the written data (output).

The documentation for this class was generated from the following files: