How to write multiple functions into one file with

Dear FEniCSx community,

I am using dolfinx 0.7.2.

I am trying to save multiple functions into one file using The current code I have is the following:

with io.VTKFFile(comm, vtk_filepath, "w") as file_vtk:
   file_vtk.write_mesh(domain) = "u"
   stress_vm_f.namem = "stress_vm"

It seems that only stress_vm is saved. Thanks in advance for any help!

Best regards,

Consider the following minimal reproducible example:

from mpi4py import MPI

import dolfinx

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10, dolfinx.cpp.mesh.CellType.triangle)
V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1))
u = dolfinx.fem.Function(V, name="u")
v = dolfinx.fem.Function(V, name="v")

with, "test.pvd", "w") as file_vtk:
    file_vtk.write_function([u, v], t=0.0)

Next time you post, please ensure that you make the code reproducible.
The code you have posted is not standalone, and contains typos:

as VTKFFile is not a dolfinx object.

1 Like