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.
|
A base class for reading and writing an HDF5 file. More...
#include <hdf5_file.h>
Public Member Functions | |
Life Cycle | |
File (const DataCommunicator &rDataCommunicator, Parameters Settings) | |
File (const File &rOther)=delete | |
File (File &&rOther) | |
virtual | ~File () |
File & | operator= (const File &rOther)=delete |
File & | operator= (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 DataCommunicator & | GetDataCommunicator () 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... | |
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.
using Kratos::HDF5::File::Matrix = HDF5::Matrix<T> |
using Kratos::HDF5::File::Vector = HDF5::Vector<T> |
|
explicit |
|
delete |
Kratos::HDF5::File::File | ( | File && | rOther | ) |
|
virtual |
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.
If | any of the parents in the rPath is not a group. |
rPath | Path to be created. |
void Kratos::HDF5::File::Close | ( | ) |
void Kratos::HDF5::File::CreateGroup | ( | const std::string & | rPath | ) |
Create a Group.
rPath | Path of the group to be created. |
void Kratos::HDF5::File::DeleteAttribute | ( | const std::string & | rObjectPath, |
const std::string & | rName | ||
) |
Deletes the specified attribute from the dataset or group.
rObjectPath | Path of a dataset or group. |
rName | Attribute name to be deleted. |
void Kratos::HDF5::File::Flush | ( | ) |
Flush the content to HDF5 file.
std::vector< hsize_t > Kratos::HDF5::File::GetAttributeDimensions | ( | const std::string & | rObjectPath, |
const std::string & | rName | ||
) | const |
Get the Attribute Dimensions.
rObjectPath | Dataset or group path. |
rName | Attribute name. |
std::vector< std::string > Kratos::HDF5::File::GetAttributeNames | ( | const std::string & | rObjectPath | ) | const |
Get the Attributes' Names list.
rObjectPath | Path of a dataset or group. |
const DataCommunicator & Kratos::HDF5::File::GetDataCommunicator | ( | ) | const |
std::vector< unsigned > Kratos::HDF5::File::GetDataDimensions | ( | const std::string & | rPath | ) | const |
Get the shape of the dataset stored at the specified path.
rPath | Dataset path. |
std::vector< std::string > Kratos::HDF5::File::GetDataSetNames | ( | const std::string & | rGroupPath | ) | const |
Get the dataset names under a group.
rGroupPath | Group path. |
int Kratos::HDF5::File::GetEchoLevel | ( | ) | const |
std::string Kratos::HDF5::File::GetFileName | ( | ) | const |
unsigned Kratos::HDF5::File::GetFileSize | ( | ) | const |
std::vector< std::string > Kratos::HDF5::File::GetGroupNames | ( | const std::string & | rGroupPath | ) | const |
Get the sub group names under a group.
rGroupPath | Group path. |
std::vector< std::string > Kratos::HDF5::File::GetLinkNames | ( | const std::string & | rGroupPath | ) | const |
Get the link names under a group.
rGroupPath | Group path. |
unsigned Kratos::HDF5::File::GetOpenObjectsCount | ( | ) | const |
unsigned Kratos::HDF5::File::GetPID | ( | ) | const |
Get the process rank.
unsigned Kratos::HDF5::File::GetTotalProcesses | ( | ) | const |
Get the Total number of processes with file access.
bool Kratos::HDF5::File::HasAttribute | ( | const std::string & | rObjectPath, |
const std::string & | rName | ||
) | const |
Checks if the given rName attribute exists in rObjectPath.
rObjectPath | Path of a dataset or a group. |
rName | Attribute name. |
bool Kratos::HDF5::File::HasAttributeType | ( | const std::string & | rObjectPath, |
const std::string & | rName | ||
) | const |
Checks if the attribute is of the specified type.
TDataType | Data type to check. |
rObjectPath | Dataset or group path. |
rName | Attribute name. |
bool Kratos::HDF5::File::HasDataType | ( | const std::string & | rPath | ) | const |
Checks the datast at path is of TDataType.
TDataType | Datatype to check against. |
rPath | Dataset path. |
bool Kratos::HDF5::File::HasFloatDataType | ( | const std::string & | rPath | ) | const |
Checks if the dataset at path is of double type.
rPath | Dataset path. |
bool Kratos::HDF5::File::HasIntDataType | ( | const std::string & | rPath | ) | const |
Checks if the dataset at path is of int type.
rPath | Dataset path. |
bool Kratos::HDF5::File::HasPath | ( | const std::string & | rPath | ) | const |
Checks if the given rPath exists.
If | a string with invalid characters is given. |
rPath | Path to be checked. |
bool Kratos::HDF5::File::IsDataSet | ( | const std::string & | rPath | ) | const |
Checks if rPath is a dataset.
rPath | Path to be checked for. |
bool Kratos::HDF5::File::IsGroup | ( | const std::string & | rPath | ) | const |
Checks if rPath contains a group.
rPath | Path to be checked for. |
Kratos::HDF5::File::KRATOS_CLASS_POINTER_DEFINITION | ( | File | ) |
Pointer definition.
Parameters Kratos::HDF5::File::ReadAttribute | ( | const std::string & | rObjectPath | ) | const |
Read attributes from a dataset or group to a Parameters object.
rObjectPath | Dataset or group path. |
void Kratos::HDF5::File::ReadAttribute | ( | const std::string & | rObjectPath, |
const std::string & | rName, | ||
TDataType & | rValue | ||
) | const |
Read attribute from a group or dataset.
TDataType | Datatype of the attribute. |
rObjectPath | Group or dataset path. |
rName | Attribute name. |
rValue | Attribute value to be written to. |
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.
if | out of range. |
TDataType | Datatype of the read data. |
rPath | Path of the dataset. |
rData | Data to be written to. |
StartIndex | Starting offset of data for this rank. |
BlockSize | Number of data points for this rank. |
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.
TDataType | Datatype of the read data. |
rPath | Path of the dataset. |
rData | Data to be written to. |
StartIndex | Starting offset of data for this rank. |
BlockSize | Number of data points for this rank. |
void Kratos::HDF5::File::SetEchoLevel | ( | int | Level | ) |
void Kratos::HDF5::File::WriteAttribute | ( | const std::string & | rObjectPath, |
const Parameters | Attributes | ||
) |
Write attributes in a Parameters object to dataset or group.
rObjectPath | Dataset or group path. |
Attributes | Attributes to be written to. |
void Kratos::HDF5::File::WriteAttribute | ( | const std::string & | rObjectPath, |
const std::string & | rName, | ||
const TDataType & | rValue | ||
) |
Write attributes to specified group or dataset.
TDataType | Data type of the attribute. |
rObjectPath | Group or dataset path. |
rName | Attribute name. |
rValue | Atribute data. |
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.
TDataType | Data type of the provided data. |
rPath | Path to which the data is written. |
rData | Data to be written. |
rInfo | Information about the written data (output). |
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.
TDataType | Data type of the Data. |
rPath | Path to which the data is written. |
rData | Data to be written. |
rInfo | Information about the written data (output). |