FieldHDF.h

template<typename FileDataType, typename Field, typename Mesh, typename Dir = size_t>
void Cubism::IO::FieldWriteHDF(const std::string &fname, const std::string &aname, const Field &field, const Mesh &mesh, const double time, const Dir face_dir = 0, const bool create_xdmf = true)

Write field data to HDF file.

Write the data carried by field to an HDF5 container file. The data that is written to the file is specified by the index space described in mesh.

Note

The variables field and mesh are only related by the index space they span. If there is no common intersection, no data will be written to the file. If the mesh spans a larger index space and full or partially contains the index space spanned by field then the index space spanned by mesh is clipped to that spanned by field.

Example:

#include "Cubism/Block/Field.h"
#include "Cubism/Core/Index.h"
#include "Cubism/Mesh/StructuredUniform.h"
#include "Cubism/IO/FieldHDF.h"

using Mesh = Cubism::Mesh::StructuredUniform<double, 3>;
using MeshIntegrity = typename Mesh::MeshIntegrity;
using PointType = typename Mesh::PointType;
using IRange = typename Mesh::IndexRangeType;
using MIndex = typename Mesh::MultiIndex;

using CellField = Cubism::Block::CellField<double, Mesh::Dim>;

int main(void)
{
    // mesh in [0,1]^3 with 16^3 cells
    const PointType end(1);
    const MIndex cells(16);
    Mesh m(end, cells, MeshIntegrity::FullMesh);

    // cell field spans an index space [6,10)^3
    const IRange cell_range(6, 10);
    CellField cf(cell_range);

    // write field to file (since the mesh fully contains cell_range, the
    // file contains 64 doubles at the coordinates defined in m using the
    // indices in cell_range
    Cubism::IO::FieldWriteHDF<double>(
        "filename", "attributename", cf, m, 0.0);
    return 0;
}

Template Parameters
  • FileDataType: HDF file data type

  • Field: Field type

  • Mesh: Mesh type

  • Dir: Special type that defines a cast to size_t

Parameters
  • fname: Output full filename without file extension

  • aname: Name of quantity in field

  • field: Input field

  • mesh: Input mesh

  • time: Current time

  • face_dir: Face direction (relevant for Cubism::EntityType::Face)

  • create_xdmf: Flag for XDMF wrapper

template<typename FileDataType, typename Field, typename Mesh, typename Dir = size_t>
void Cubism::IO::FieldReadHDF(const std::string &fname, Field &field, const Mesh &mesh, const Dir face_dir = 0)

Read field data from HDF file.

Read the data of an HDF5 container file into field. The data that is read from the file is specified by the index space described in mesh.

Template Parameters
  • FileDataType: HDF file data type

  • Field: Field type

  • Mesh: Mesh type

  • Dir: Special type that defines a cast to size_t

Parameters
  • fname: Input full filename without file extension

  • field: Field populated with file data

  • mesh: Field (sub)mesh

  • face_dir: Face direction (relevant for Cubism::EntityType::Face)