Issues visualizing multiple fields stored in single XDMF file [dolfinx]

Hey all,

I am experiencing some issues trying to visualize vector fields in ParaView 5.11.1 when multiple functions are stored in a single XDMF file. Maybe this turns out to be a ParaView question, but my impression is that something is wrong with how I write the XDMF files.

Consider the following MWE that creates and writes 2 vector fields:

import dolfinx
import numpy as np
from dolfinx import fem, io
from mpi4py import MPI
from petsc4py import PETSc

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 16, 16)
V = fem.VectorFunctionSpace(mesh, ("CG", 1))
u = fem.Function(V, name="u")
v = fem.Function(V, name="v")

def f(x):
    values = np.zeros((2, x.shape[1]), dtype=PETSc.ScalarType)
    values[0] = x[1]*(1.0 - x[1])
    return values


with io.XDMFFile(MPI.COMM_WORLD, "test.xdmf", "w") as xf:
    xf.write_function(u, 0.0)
    xf.write_function(v, 0.0)

In ParaView, selecting the Xdmf3ReaderT and XDMF Reader, the magnitude and component fields are correctly displayed (Xdmf3ReaderS does not display any values). Whenever multiple functions are stored in a single file, the functions are named u (partial), v (partial), etc – not sure if that’s intended?

  1. Visualizing vectors (workaround):
    Applying the Glyphs filter to visualize the vector fields does not work as expected: in the above example, depending on which field is selected as orientation, scale array and for colors, different errors occur. Both fields are shown together, the arrows are not scaled and/or not colored, etc.
    Using the Extract Block twice to extract and separate both fields allows correctly visualizing the vectors. But I’d expect this to work without this workaround.

  2. WarpByVector (no solution):
    For a case of elasticity I want to warp the domain by a displacement vector field and to display the stresses or the velocity field on the warped domain.
    Applying the WarpByVectors filter only warps the field itself that was selected as the warping field, the other remains unchanged. Curiously, applying the filter will visualize both fields, the warped and the unwarped. Using Extract Block can separate both, but I couldn’t find a setup where I could visualize field v warped by field u.

This reads like a long ParaView question, but, again, my impression is that the functions are not written correctly.

Thank you for your input!

  1. If you same multiple fields to the same mesh, you need to use extract block to extract each field.

  2. In can reproduce this, but I do not think it is an issue of DOLFINx, rather a limitation of Paraview.

In general, xdmf is going to be phased out, so I would suggest switching to VTXWriter (ADIOS2 based), as it does what you want to do:

with io.VTXWriter(MPI.COMM_WORLD, "test.bp", [u,v]) as xf:

1 Like

This works using the docker nightly image and the newest ParaView binary. When executing the MWE with the spack build (fenics-dolfinx@main +adios2) Paraview gives me a segfault.

Both the docker and spack builds use the same dolfinx commit, f90b48.

edit: some more infos: The content of test.bp differs in both cases. Spack produces a file mmd.0 which docker does not.
Not sure about the relevance, but profiling.json differs:

  1. spack:
    { "rank":0,
                "nCalls":1}} }

  1. docker
    { "rank": 0,
        "start": "Tue_May_30_16:55:03_2023",
        "threads": 1,
        "bytes": 41477,
        "mkdir_mus": 43,
        "aggregation_mus": 0,
        "meta_sort_merge_mus": 19,
        "minmax_mus": 11,
        "memcpy_mus": 0,
        "buffering_mus": 60,
        "transport_0": { "type": "File_POSIX",
            "close_mus": 1,
            "write_mus": 24,
            "open_mus": 33},
        "transport_1": { "type": "File_POSIX",
            "close_mus": 0,
            "write_mus": 2,
            "open_mus": 22} }

Any ideas? thanks

Hey @dajuno, this may not have much to do with you question, sorry about that… But it is just a quick question. When I try to open a .bp file in paraview, it just acts like a folder and I can’t load it in. The contents are something like data.0, md.0 and profiling.json

Is VTXWriter supposed to behave in this way? I can’t find any good information about the topic.
Thank you in advance.

The .bp file is a folder with binaries. Instead of navigating in to the folder, and then open it, you need to just select the .bp folder and then press ok to launch the viewers.

Thanks for your reply. I suspected something like that, but I was confused because paraview does not let me open the folder.

(Edit) I have tried to open the folder in another computer with paraview. This time I can open the folder but I also get segmentation fault (I generated the files with the conda distribution of dolfinx).

maybe your paraview is too old, try a newer version. The list of supported files should include *.bp. Download ParaView

Regarding the issue using the spack build: I noticed that the adios2 versions were different, docker nightly uses 2.8.3 while spack’s default is 2.9.0. Fixing adios2@2.8.3 works!

Hi there, please take a look at FEplot, it may help with visualizing xdmf files.

Could you please expand a little bit more on how to do Extract Block? I guess it is in Paraview but no clue to make it with multiple fileds visualization in one single XDMF.

Open filters menu, choose extract block. You can now choose one of the slemts in the file fir visualization.