xdmf output of VectorFunctionSpace with dim < 3

Issue #1001 new
Marco Morandini created an issue

xdmf outut of VectorFunctionSpaces works only for dim > 2: the following code

from dolfin import *
mesh = UnitSquareMesh(8, 8)
el = FiniteElement("CG", mesh.ufl_cell(), degree=1)
V = VectorFunctionSpace(mesh, el, degree=1, dim=2)
u = Function(V, name="u")
c = Constant([1., 2])
u.vector()[:] = interpolate(c, V).vector()
filex = XDMFFile('pippo.xdmf')
filex.write(u, 0.)

leads to

        <Attribute Name="u" AttributeType="Vector" Center="Node">
          <DataItem Dimensions="81 3" Format="HDF">pippo.h5:/VisualisationVector/0</DataItem>
        </Attribute>

inside file pippo.xdmf instead of

        <Attribute Name="u" AttributeType="Vector" Center="Node">
          <DataItem Dimensions="81 2" Format="HDF">pippo.h5:/VisualisationVector/0</DataItem>
        </Attribute>

When the dim=1 (instead of 2 as in this example; note that I'm not claiming it's a good idea to have dim=1) paraview is badly confused by the missing data in pippo.h5.

Comments (5)

  1. Michal Habera

    I wouldn't consider this an DOLFIN issue. ParaView's internals embed everything into 3D space, so it can understand vector only if it has 3 components (2nd order tensor if it has 9 components, ...). That is the reason for 0-value padding done in DOLFIN IO, see method XDMFFile::get_padded_width.

    In principal, we can save a 2D vector field, but ParaView then reads just 2-tuple of scalars without additional meaning - you can't simply apply Glyph filter etc.

    If you mind these zeros, experiment with XDMFFile::write_checkpoint, padding is done on ParaView side for the output of this method.

  2. Marco Morandini reporter

    Understood, thank you. Would you accept a patch adding parameters.add("pad_width", true); to XDMFFile::XDMFFile and checking for it inside XDMFFile::get_padded_width ?

  3. Michal Habera

    Why do you need it? I would be careful when adding a XDMF parameter. It naturally suggests that the option applies to the whole XDMFFile, but only write method would be actually affected (not write_checkpoint).

    In addition, the name pad_width is not very descriptive for users...

  4. Marco Morandini reporter

    I don't really need it, but I think that it would be nice for a user to be able to disable automatic padding and not have dolfin trying to guess what he wants. Or, at the very least, to document that write can add, (only) in some cases, padding. This was a surprise for me, and made me waste two days while chasing a bug.

    At any rate feel free to close this; I don't have a strong opinion at this point.

  5. Log in to comment