|
Nektar++
|
Writes a time series of point data to a HDF5 file. More...
#include <PtsIOHdf5.h>
Public Member Functions | |
| PtsIOHdf5 (LibUtilities::CommSharedPtr pComm, const std::string &fileName, const NekDouble time, const PtsFieldSharedPtr &ptsField, const size_t expectedRows=0) | |
Opens fileName and prepares it to receive the fields described by ptsField, discarding any data at or after time. expectedRows is an optional hint at how many times will be written, used only to choose a chunk size; zero means it is not known. | |
| ~PtsIOHdf5 () | |
| void | Write (const PtsFieldSharedPtr &ptsField, const NekDouble time) |
Appends the field values held by ptsField at time time. | |
| void | Close () |
| Flushes and closes the file. Called by the destructor. | |
Private Member Functions | |
| size_t | ChunkRows (const size_t rowLength, const size_t expectedRows) const |
| Number of time rows in a single chunk. | |
| NekDouble | ReadTime (const H5::DataSetSharedPtr &dataSet, const hsize_t row) const |
Reads the time stored in the first column of row row. | |
| hsize_t | FindRestartRow (const H5::DataSetSharedPtr &dataSet, const hsize_t nRows, const NekDouble time) const |
Index of the first row whose time is at or after time. | |
Private Attributes | |
| LibUtilities::CommSharedPtr | m_comm |
| const std::string | m_fileName |
| Name of file. | |
| bool | m_isRoot = false |
| True on the process that owns the file. | |
| size_t | m_nPts = 0 |
| Number of points, fixed when the file is opened. | |
| hsize_t | m_row = 0 |
| Index of the next row to be written. | |
| H5::FileSharedPtr | m_file |
| H5::GroupSharedPtr | m_timeGroup |
| std::vector< H5::DataSetSharedPtr > | m_fieldData |
| std::vector< NekDouble > | m_rowBuffer |
| Scratch space for one row: time followed by one value per point. | |
Static Private Attributes | |
| static constexpr size_t | TargetChunkBytes = 64 * 1024 |
| Target size of a single HDF5 chunk, in bytes. Chunks much smaller than this make the chunk index dominate the file; chunks much larger risk exceeding the default chunk cache. | |
| static constexpr size_t | MinChunkRows = 64 |
| Fewest time rows in a chunk. A chunk holding only a handful of rows costs more in index entries than it saves in allocated space. | |
Writes a time series of point data to a HDF5 file.
The file is laid out as
NEKTAR/
COORDINATES/
x - dataset, [npoints]
y - dataset, [npoints]
z - dataset, [npoints]
TIME-DATA/
<field1> - dataset, [ntimes x (npoints + 1)]
...
<fieldN> - dataset, [ntimes x (npoints + 1)]
The coordinates are fixed for the lifetime of the file and are written once. Each field is a single two-dimensional dataset, extensible along the time dimension, whose first column holds the time and whose remaining columns hold that field's value at each point. Storing the time in the datasets themselves means a row is self-describing and the whole time history of a field can be read with a single call.
Definition at line 74 of file PtsIOHdf5.h.
| Nektar::LibUtilities::PtsIOHdf5::PtsIOHdf5 | ( | LibUtilities::CommSharedPtr | pComm, |
| const std::string & | fileName, | ||
| const NekDouble | time, | ||
| const PtsFieldSharedPtr & | ptsField, | ||
| const size_t | expectedRows = 0 |
||
| ) |
Opens fileName and prepares it to receive the fields described by ptsField, discarding any data at or after time. expectedRows is an optional hint at how many times will be written, used only to choose a chunk size; zero means it is not known.
Opens the file and prepares it to receive data.
If fileName does not exist it is created. If it does exist, the coordinates it holds are checked against ptsField and any rows at or after time are discarded, so that a simulation restarted from an earlier time overwrites the history it is about to recompute rather than appending to it.
Only the root process touches the file; see Write().
| pComm | Communicator |
| fileName | Name of file |
| time | Physical time at which output will start |
| ptsField | Supplies the point coordinates and the field names. The field values it holds are not used. |
| expectedRows | Hint at the number of times that will be written, or zero if unknown. Only affects the chunk size. |
Definition at line 64 of file PtsIOHdf5.cpp.
References ASSERTL0, ChunkRows(), Nektar::LibUtilities::H5::File::Create(), Nektar::LibUtilities::H5::PList::DatasetCreate(), FindRestartRow(), m_comm, m_fieldData, m_file, m_fileName, m_isRoot, m_nPts, m_row, m_rowBuffer, m_timeGroup, Nektar::LibUtilities::H5::DataType::OfObject(), Nektar::LibUtilities::H5::DataSpace::OneD(), and Nektar::LibUtilities::H5::File::Open().
| Nektar::LibUtilities::PtsIOHdf5::~PtsIOHdf5 | ( | ) |
Definition at line 197 of file PtsIOHdf5.cpp.
References Close().
|
private |
Number of time rows in a single chunk.
HDF5 allocates a chunk as soon as any part of it is written, so a chunk sized for a long run would be mostly empty after a short one. The chunk is therefore capped at PtsIOHdf5::TargetChunkBytes, which keeps the chunk index small, and then reduced to expectedRows where that is known to be smaller, subject to a floor of PtsIOHdf5::MinChunkRows.
Definition at line 211 of file PtsIOHdf5.cpp.
References MinChunkRows, and TargetChunkBytes.
Referenced by PtsIOHdf5().
| void Nektar::LibUtilities::PtsIOHdf5::Close | ( | ) |
Flushes and closes the file. Called by the destructor.
Definition at line 333 of file PtsIOHdf5.cpp.
References m_fieldData, m_file, and m_timeGroup.
Referenced by ~PtsIOHdf5().
|
private |
Index of the first row whose time is at or after time.
Times increase down the dataset, so this is a binary search; only the rows it visits are read, rather than the whole time column.
Definition at line 247 of file PtsIOHdf5.cpp.
References hi, Nektar::LibUtilities::IsRealEqual(), lo, mid(), and ReadTime().
Referenced by PtsIOHdf5().
|
private |
Reads the time stored in the first column of row row.
Definition at line 228 of file PtsIOHdf5.cpp.
Referenced by FindRestartRow().
| void Nektar::LibUtilities::PtsIOHdf5::Write | ( | const PtsFieldSharedPtr & | ptsField, |
| const NekDouble | time | ||
| ) |
Appends the field values held by ptsField at time time.
Appends one row of field values.
Each field's dataset is extended by a single row, which is then filled with time followed by that field's value at each point.
Note that the file is written by the root process, so distributed data must be communicated to it before calling this function. This limitation might be relaxed in the future: because each field is one dataset, each process could write the points it owns directly as a collective operation.
| ptsField | PtsField holding the values for this time |
| time | Physical time |
Definition at line 287 of file PtsIOHdf5.cpp.
References ASSERTL0, ASSERTL1, m_fieldData, m_file, m_isRoot, m_nPts, m_row, and m_rowBuffer.
|
private |
Definition at line 112 of file PtsIOHdf5.h.
Referenced by PtsIOHdf5().
|
private |
Definition at line 128 of file PtsIOHdf5.h.
Referenced by Close(), PtsIOHdf5(), and Write().
|
private |
Definition at line 126 of file PtsIOHdf5.h.
Referenced by Close(), PtsIOHdf5(), and Write().
|
private |
|
private |
True on the process that owns the file.
Definition at line 118 of file PtsIOHdf5.h.
Referenced by PtsIOHdf5(), and Write().
|
private |
Number of points, fixed when the file is opened.
Definition at line 121 of file PtsIOHdf5.h.
Referenced by PtsIOHdf5(), and Write().
|
private |
Index of the next row to be written.
Definition at line 124 of file PtsIOHdf5.h.
Referenced by PtsIOHdf5(), and Write().
|
private |
Scratch space for one row: time followed by one value per point.
Definition at line 131 of file PtsIOHdf5.h.
Referenced by PtsIOHdf5(), and Write().
|
private |
Definition at line 127 of file PtsIOHdf5.h.
Referenced by Close(), and PtsIOHdf5().
|
staticconstexprprivate |
Fewest time rows in a chunk. A chunk holding only a handful of rows costs more in index entries than it saves in allocated space.
Definition at line 104 of file PtsIOHdf5.h.
Referenced by ChunkRows().
|
staticconstexprprivate |
Target size of a single HDF5 chunk, in bytes. Chunks much smaller than this make the chunk index dominate the file; chunks much larger risk exceeding the default chunk cache.
Definition at line 100 of file PtsIOHdf5.h.
Referenced by ChunkRows().