I/O from XDMF/HDF5 files in dolfin-x

In your example, only 0 and 1 should work.
I can reproduce the expected behavior with the following script:



import os
import sys
import numpy as np
import ufl
import dolfinx
from dolfinx import fem, io
from dolfinx.fem.petsc import assemble_matrix
from dolfinx.fem import FunctionSpace, Function

from mpi4py import MPI

new_path = r"/usr/local/lib/python3/dist-packages" #Need to add this path for access to adios2 which is required by adios4dolfinx
sys.path.append(new_path)

import adios4dolfinx as a4dx

comm = MPI.COMM_WORLD
mesh = dolfinx.mesh.create_unit_square(comm, 100,100, cell_type=dolfinx.mesh.CellType.triangle)
filename = f"./{comm.size}proc.bp"

v_cg2 = ufl.VectorElement("CG", mesh.ufl_cell(), 2)
V = FunctionSpace(mesh, v_cg2)
u = Function(V)
x = ufl.SpatialCoordinate(mesh)
dfnx_expr = fem.Expression(x, V.element.interpolation_points())
u.interpolate(dfnx_expr)
a4dx.write_mesh(mesh, "./mesh/square.bp")
a4dx.write_function(u, filename)

mesh_new = a4dx.read_mesh(comm, "./mesh/square.bp", "BP4", dolfinx.mesh.GhostMode.shared_facet)
v_new = ufl.VectorElement("CG", mesh_new.ufl_cell(), 2)
W = FunctionSpace(mesh_new, v_new)
w = Function(W)

v = Function(V)
a4dx.read_function(w, filename)
a4dx.read_function(v, filename)
#v.x.array[:] = o.x.array # array sizes not compatible?
with io.XDMFFile(comm, f"./0_{comm.size}proc.xdmf", "w") as xdmf:
    # Should work
    xdmf.write_mesh(mesh_new)
    xdmf.write_function(w)

with io.XDMFFile(comm, f"./1_{comm.size}proc.xdmf", "w") as xdmf:
    # Should work
    xdmf.write_mesh(mesh)
    xdmf.write_function(u)

with io.XDMFFile(comm, f"./2_{comm.size}proc.xdmf", "w") as xdmf:
    # Should not work
    xdmf.write_mesh(mesh)
    xdmf.write_function(w)

with io.XDMFFile(comm, f"./3_{comm.size}proc.xdmf", "w") as xdmf:
    # Should not work
    xdmf.write_mesh(mesh_new)
    xdmf.write_function(u)

with io.XDMFFile(comm, f"./4_{comm.size}proc.xdmf", "w") as xdmf:
    # Should not work
    xdmf.write_mesh(mesh)
    xdmf.write_function(v)

with

docker run -ti -v $(pwd):/root/shared -w /root/shared --rm ghcr.io/fenics/dolfinx/dolfinx:v0.6.0-r1
python3 -m pip install -U pip setuptools
python3 -m pip install git+https://github.com/jorgensd/adios4dolfinx@v0.1.0
mpirun -n 3 python3 name_of_script.py