Cannot write function to XDMF with DG elements

Hi!

I’m trying to export a function from a DG function space to XDMF but obtain the following error:

  File "/home/remidm/festimx/mwe.py", line 14, in <module>
    xdmf_file.write_function(u)
  File "/home/remidm/miniconda3/envs/dolfinx/lib/python3.11/site-packages/dolfinx/io/utils.py", line 235, in write_function
    super().write_function(getattr(u, "_cpp_object", u), t, mesh_xpath)
RuntimeError: Function and Mesh dof layouts do not match. Maybe the Function needs to be interpolated?

Obtained with the following MWE:

from dolfinx import mesh, fem
from mpi4py import MPI
from dolfinx.io import XDMFFile

msh = mesh.create_unit_square(MPI.COMM_WORLD, 8, 8)

V = fem.FunctionSpace(msh, ("DG", 1))

u = fem.Function(V)

xdmf_file = XDMFFile(MPI.COMM_WORLD, "u.xdmf", "w")
xdmf_file.write_mesh(msh)
xdmf_file.write_function(u)

Works just fine with CG elements.

This used to work fine even with DG so maybe it is a recent change?

Any idea?
Thanks!

This is an explicit change to highlight the limitations of the XDMF file format, as in comparison to VTX.

In DOLFINx<0.7.0 any function was interpolated into the function space of the mesh geometry (N-th order Lagrange space, N usually 1).
Now you have to interpolate this function into (“CG”, 1) explicitly to save it to xdmf, or use the VTXWriter, which supports arbitrary order “CG”/“DG” elements.

Understood!
I suppose we would need a write_checkpoint method for this then?

We are not aiming for long term support of XDMF, as it is no longer actively developed (Xdmf / Xdmf · GitLab, no commit in three years), and thus we are not aiming to add checkpointing to it.

I was working on an ADIOS2 based checkpoint/visualization code, but hit some speed-bumps, such as:

and thus I don’t have a good proposal for a format that can be both used as a checkpoint and be visualized with tools such as Paraview.

I’ve got checkpoint functionality at: GitHub - jorgensd/adios4dolfinx: Interface of ADIOS2 for DOLFINx
which I aim to make 0.7.0 compatible over the weekend.

2 Likes

Gotcha. I’ll stick with VTXWriter for now then. Not sure how to read it with paraview though. Is there any demo available?

VTXWriter created a .bp folder, that you can open in paraview. It should then Give you the option og fides or VTX (choose Vtx)

Hm I have the folder but it’s not opening in paraview 5.11.1, just hangs forever.

This is how I export it, does it seem right?

from dolfinx import mesh, fem
from mpi4py import MPI
from dolfinx.io import XDMFFile
from dolfinx.io import VTXWriter

msh = mesh.create_unit_square(MPI.COMM_WORLD, 8, 8)

V = fem.FunctionSpace(msh, ("DG", 1))

u = fem.Function(V)


V_CG1 = fem.FunctionSpace(msh, ("CG", 1))

u_cg = fem.Function(V_CG1)
u_cg.interpolate(u)

xdmf_file = XDMFFile(MPI.COMM_WORLD, "u.xdmf", "w")
xdmf_file.write_mesh(msh)
xdmf_file.write_function(u_cg)

with VTXWriter(msh.comm, "out.bp", [u]) as vtx:
    vtx.write(0.0)

Try

with VTXWriter(msh.comm, "out.bp", [u], engine="BP4") as vtx:
    vtx.write(0.0)

after removing the old directory. Paraview doesn’t support BP5 yet, Which is the default engine for adios2

Progress: now Paraview doesn’t hang anymore but I have this error

ERROR: In vtkADIOS2CoreImageReader.cxx, line 648
vtkADIOS2CoreImageReader (000002A5F7ABD6D0): Can not use the dimension of array NumberOfEntities to set the dimension of image data. Its size is neither 2 nor 3

There should be another reader there (that is not image data). Do you Get the option: ADIOS2VTXReader
(paraview.simple.ADIOS2VTXReader — ParaView/Python 5.8.0-RC3-1-g56631fdd9a documentation)

Hm, I wasn’t offered the choice of reader.

This is the list of readers I find when going in OpenFile :

That is strange. How did you install paraview and what kind of system are you using?

I’m on Windows, I installed it on the Paraview download page (v5.11.1)

I would Ask on the paraview discourse:

as I dont have a Windows computer to test this on

Will do, I have the same bug in paraview 5.11.2

@dokken It seems the ADIOS2VTX reader has been removed from the docs of Paraview after 5.8

This is 5.11:
https://kitware.github.io/paraview-docs/v5.11.0/python/paraview.servermanager_proxies.html

I’m using 5.11-r2, and as you can see from the screenshot below, I got access to ADIOS2VTXReader:


This is running on a ubuntu 20.04 machine, using the binary download from the Paraview webpage.

It would seem it has to do with needing the MPI version

Is this the MPI version?

Yes. As adios2 features alot of MPI functionality.

1 Like