Nonsense XDMF output of a vector function of a 1d geometry

Issue #574 resolved
Tianyi Li created an issue

To parametrize the space dimension for a vector-valued unknown, it is useful to define always a VectorFunctionSpace even in the 1d case, via the identification between Expression("x[0]") and Expression(["x[0]"]). Suppose that u is such a Function, its Numpy array is well defined (1-d array) and gives correct values.

However the XDMF output of such function produces nonsense values in ParaView, as can be seen via the following MWE.

from fenics import *

mesh = UnitIntervalMesh(10)
V = VectorFunctionSpace(mesh, "CG", 1)
u = Function(V)
u.interpolate(Expression(["x[0]"]))

# XDMF output does not produce any error
# Howver in ParaView nonsense values are affected to u 
File("u.xdmf") << u

# PVD output produces an DOLFIN error
# "Don't know how to handle vector function with dimension other than 2 or 3."
File("u.pvd") << u  

Comments (12)

  1. Martin Sandve Alnæs

    I guess it should be treated as a scalar function in the xdmf file? Would you like to take a look at it? Search for the error message in the source code, it might be easy to fix.

  2. Chris Richardson

    Scalars in 1D work, but there is a bit of a workaround, because XDMF does not support 1D geometry.

  3. Chris Richardson

    The problem is that XDMF does not support 1D geometry. At the moment, we supply dummy zero Y and Z components, so XDMF thinks it is getting a dataset in 3D. When it gets a VectorFunctionSpace, it expects it to have 3 components. I've pushed a fix to next.

  4. Joshua Chen

    What about for, say a mixed function space, say for Stokes with u,p = y \in V_mixed? Can the XMDF writing interface be written such that writing y to XDMF will make sense?

  5. Log in to comment