I’m trying to write vector-valued functions to view into Paraview, where the vector has a length that is not the geometrical dimension. It appears that using VTK or VTX, writing a function with shape (n,) results in X, Y and Z components regardless of the value of n: if it is more than 3 the components are either not written or not read by Paraview, I am not sure. XDMF on the other hand always displays the right number of components. It is also true for tensor-valued functions where VTK and VTX always show 9 components.
An illustrative MWE with a function space of shape (4,):
from dolfinx import mesh, fem, io
from mpi4py import MPI
domain = mesh.create_unit_square(MPI.COMM_WORLD, 10, 10, mesh.CellType.quadrilateral)
V = fem.functionspace(domain, ("Lagrange", 1, (4,)))
v = fem.Function(V, name="4comp-vector")
# Gives components X,Y,Z in Paraview
with io.VTKFile(domain.comm, "4comp_vector.pvd", "w") as vtk:
vtk.write_function(v, 0.0)
# Gives components X,Y,Z in Paraview
with io.VTXWriter(domain.comm, "4comp_vector.bp", [v]) as vtx:
vtx.write(0.0)
# Gives components 0,1,2,3 in Paraview
with io.XDMFFile(domain.comm, "4comp_vector.xdmf", "w") as xdmf:
xdmf.write_mesh(domain)
xdmf.write_function(v, 0.0)
I tried out this code on a recent commit of the main branch (May 17th) and it crashes if the dimension of the function is 4, runs for dim 3 or lower. I get: