XDMF write_checkpoint questions

When using write_checkpoint for a time dependent file, is there a way to write multiple fields to the same file (which I can do with write)?

Also, per Loading xdmf data back in, if write_checkpoint actually encodes the function space, is there a way data can be loaded in without having to first reconstruct the function space?

I guess you can write multiple fields by varying the two first arguments in write checkpoint (function and name).

As for your second question. How would you load something into dolfin without the function space information? As i explained in the referenced post, write only saved data at vertices, and would remove data required to reconstruct a function. If you only want to use lower order data when loading it back in, you could project your function to a lower order function space before saving it.

Ok, this code does not work as expected (for recording to two fields):

from dolfin import *
nx = ny = 8
mesh = UnitSquareMesh(nx, ny)
V = FunctionSpace(mesh, 'P', 1)

alpha = 3; beta = 1.2
f = Expression('1 + x[0]*x[0] + alpha*x[1]*x[1] + beta*t', degree=2, alpha=alpha, beta=beta, t=0)
g =  Expression('1 + sin(x[0]) + cos(t*x[1])', degree=2,  t=0)
data_out = XDMFFile("test.xdmf")
data_out.write_checkpoint(project(f, V), "f", 0, XDMFFile.Encoding.HDF5, False)  # Not appending to file
data_out.write_checkpoint(project(g, V), "g", 0, XDMFFile.Encoding.HDF5, True)  # Not appending to file
for j in range(1,5):
    t = float(j/5)
    f.t = t
    g.t = t
    data_out.write_checkpoint(project(f,V), "f",t, XDMFFile.Encoding.HDF5, True)  #appending to file
    data_out.write_checkpoint(project(g,V), "g",t, XDMFFile.Encoding.HDF5, True)  #appending to file

data_out.close()

Regarding the second point, what Iā€™m trying to understand is the minimal amount of information I need to save in order to reconstruct the output. For instance, even if I got the above code working as intended, how would I recover the mesh structure from the output file so as to be able to build the function space back to then load the field variables?

1 Like

@gideonsimpson were you able to find a way to save two or more fields in the same file using write_checkpoint?