How to append to VTX file

Hi everyone!

I am trying to append to a VTX file (see MWE below).

However, it seems that the last written entry overwrites the previous ones.
In the following example, I expect to have x^2 + y^2 + z^2 in the first timestep and 3 in the second timestep.

from dolfinx.io import VTXWriter
import dolfinx
from mpi4py import MPI

mesh = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 10, 10, 10)
V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1))
u = dolfinx.fem.Function(V)

# time step 1

u.interpolate(lambda x: x[0] ** 2 + x[1] ** 2 + x[2] ** 2)

with VTXWriter(mesh.comm, "out.bp", [u], "BP4") as vtx:
    vtx.write(0.0)


# time step 2
u.interpolate(lambda x: 3 + x[0] - x[0])
with VTXWriter(mesh.comm, "out.bp", [u], "BP4") as vtx:
    vtx.write(1.0)

However, in Paraview, I see only 3 everywhere for both timesteps:

I couldn’t find an “append” argument in the write function…
Surely something silly I’m not getting.

Thanks for the help!

Oops… it was something silly…

Here’s the correct use:

from dolfinx.io import VTXWriter
import dolfinx
from mpi4py import MPI

mesh = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 10, 10, 10)
V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1))
u = dolfinx.fem.Function(V)

u.interpolate(lambda x: x[0] ** 2 + x[1] ** 2 + x[2] ** 2)

writer = VTXWriter(mesh.comm, "my_export.bp", [u], "BP4")

writer.write(1.0)

u.interpolate(lambda x: 3 + x[0] - x[0])

writer.write(2.0)
1 Like