I am saving my solutions in an xdmffile. But i would really like to also store some metadata in the same file describing the experiment parameters. Is there a way i can store an arbitrary string in an xdmf file? Maybe something similar to the attributes in an hdf5file (see commented lines in code below)?
def save_xdmf(fname, mesh, usol, psol, metadata_dict):
with XDMFFile(fname) as xf:
usol.rename("u", "velocity")
psol.rename("p", "pressure")
xf.write(usol, 0)
xf.write(psol, 1)
xf.write_checkpoint(usol, "usol", 0, XDMFFile.Encoding.HDF5, True)
xf.write_checkpoint(psol, "psol", 0, XDMFFile.Encoding.HDF5, True)
#att = hdf.attributes("/mesh")
#att["metadata_dict"] = str(metadata_dict)
def load_xdmf(fname):
with XDMFFile(fname) as xf:
mesh = Mesh()
xf.read(mesh)
fs_u = VectorFunctionSpace(mesh, "CG", degree=2, dim=3)
fs_p = FunctionSpace(mesh, "CG", 1)
usol = Function(fs_u)
psol = Function(fs_p)
xf.read_checkpoint(usol, "usol", 0)
xf.read_checkpoint(psol, "psol", 0)
#att = hdf.attributes("/mesh")
#metadata_dict= literal_eval(att["metadata_dict"])
return (mesh, usol, psol, metadata_dict)