About problems occur when loading the xdmf result file obtained through dolfinx into paraview

Hi~ :wave: It’s been a while since I posted. :smiley:
The reason I left a post is a problem occurred while editing ‘The equations of linear elasticity(link)’ example code to 2D, edit the load condition code and relocation write_mesh code line.

When the edited code was executed in a mesh domain with a smaller size(e.g., 500 X 500) execution and xdmf file results were obtained without any problems.
But I declared a mesh domain of 1,000 X 1,000 in the code and open the xdmf file in paraview, the following vtk time-out error occurred.

The dolfinx version is 0.5.2
The paraview version I am using(in ubuntu, linux) is 5.10.0-RC1.

The error is

ERROR: In ./VTK/Common/ExecutionModel/vtkExecutive.cxx, line 752
vtkPVCompositeDataPipeline (0x55c714783800): Algorithm vtkFileSeriesReader(0x55c711138e70) returned failure for request: vtkInformation (0x55c70ebf2210)
  Debug: Off
  Modified Time: 1739747
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA_OBJECT
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

ERROR: In ./VTK/Common/ExecutionModel/vtkExecutive.cxx, line 752
vtkPVCompositeDataPipeline (0x55c71a1d35b0): Algorithm vtkXdmfReader(0x55c7197f17b0) returned failure for request: vtkInformation (0x55c7147e6dd0)
  Debug: Off
  Modified Time: 1739634
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA_OBJECT
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

ERROR: In ./VTK/Common/ExecutionModel/vtkExecutive.cxx, line 752
vtkPVCompositeDataPipeline (0x55c71a1d35b0): Algorithm vtkXdmfReader(0x55c7197f17b0) returned failure for request: vtkInformation (0x55c7147e6dd0)
  Debug: Off
  Modified Time: 1739634
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA_OBJECT
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

ERROR: In ./VTK/Common/ExecutionModel/vtkExecutive.cxx, line 752
vtkPVCompositeDataPipeline (0x55c714783800): Algorithm vtkFileSeriesReader(0x55c711138e70) returned failure for request: vtkInformation (0x55c70ebf2210)
  Debug: Off
  Modified Time: 1739747
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA_OBJECT
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

ERROR: In ./VTK/Common/ExecutionModel/vtkExecutive.cxx, line 752
vtkPVCompositeDataPipeline (0x55c71a1d35b0): Algorithm vtkXdmfReader(0x55c7197f17b0) returned failure for request: vtkInformation (0x55c7147e6dd0)
  Debug: Off
  Modified Time: 1739634
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA_OBJECT
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

ERROR: In ./VTK/Common/ExecutionModel/vtkExecutive.cxx, line 752
vtkPVCompositeDataPipeline (0x55c71a1d35b0): Algorithm vtkXdmfReader(0x55c7197f17b0) returned failure for request: vtkInformation (0x55c7147e6dd0)
  Debug: Off
  Modified Time: 1739634
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA_OBJECT
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

ERROR: In ./VTK/Common/ExecutionModel/vtkExecutive.cxx, line 752
vtkPVCompositeDataPipeline (0x55c714783800): Algorithm vtkFileSeriesReader(0x55c711138e70) returned failure for request: vtkInformation (0x55c70ebf2210)
  Debug: Off
  Modified Time: 1739747
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA_OBJECT
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

ERROR: In ./VTK/Common/ExecutionModel/vtkExecutive.cxx, line 752
vtkPVCompositeDataPipeline (0x55c71a1d35b0): Algorithm vtkXdmfReader(0x55c7197f17b0) returned failure for request: vtkInformation (0x55c7147e6dd0)
  Debug: Off
  Modified Time: 1739634
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA_OBJECT
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

ERROR: In ./VTK/Common/ExecutionModel/vtkExecutive.cxx, line 752
vtkPVCompositeDataPipeline (0x55c71a1d35b0): Algorithm vtkXdmfReader(0x55c7197f17b0) returned failure for request: vtkInformation (0x55c7147e6dd0)
  Debug: Off
  Modified Time: 1739634
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_DATA_OBJECT
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

The work code is

# import packages
import numpy as np
import ufl
from dolfinx import fem, mesh, io
from mpi4py import MPI
from petsc4py import PETSc

# scaled variable
_mu, lmd = PETSc.ScalarType(0.4), PETSc.ScalarType(0.6)
# input parameters
nelx = 1000 # no problem when set nelx = 500
nely = 1000 # no problem when set nely = 500

# function deblaration
sigma = lambda _u: 2.0*_mu*ufl.sym(ufl.grad(_u)) + lmd*ufl.tr(ufl.sym(ufl.grad(_u)))*ufl.Identity(len(_u))
psi = lambda _u: lmd/2*(ufl.tr(ufl.sym(ufl.grad(_u))) ** 2) + _mu*ufl.tr(ufl.sym(ufl.grad(_u))*ufl.sym(ufl.grad(_u)))

# set mesh & function space
msh = mesh.create_rectangle(MPI.COMM_WORLD, np.array([[0.0, 0.0], [nelx, nely]]), [nelx, nely], cell_type=mesh.CellType.quadrilateral)
U = fem.VectorFunctionSpace(msh, ("CG", 1))
D = fem.FunctionSpace(msh, ("DG", 0))
u, v = ufl.TrialFunction(U), ufl.TestFunction(U)
rho = fem.Function(D)
rho.vector.array = 1

# write mesh
with io.XDMFFile(MPI.COMM_WORLD, f"outfile/plot.xdmf", "w") as file:
    file.write_mesh(msh)

# define support
def left_clamp(x):
    return np.isclose(x[0], 0.0)
f_dim = msh.topology.dim - 1
bc_facets = mesh.locate_entities_boundary(msh, f_dim, left_clamp)
u_zero = np.array([0.0, 0.0], dtype=PETSc.ScalarType)
bc_l = fem.dirichletbc(u_zero, fem.locate_dofs_topological(U, f_dim, bc_facets), U)
bcs = [bc_l]

# define load
load_points = [(1, lambda x: np.logical_and(x[0] == nelx, x[1] <= 2))]
facet_indices, facet_markers = [], []
for (marker, locator) in load_points:
    facets = mesh.locate_entities(msh, f_dim, locator)
    facet_indices.append(facets)
    facet_markers.append(np.full(len(facets), marker))
facet_indices = np.array(np.hstack(facet_indices), dtype=np.int32)
facet_markers = np.array(np.hstack(facet_markers), dtype=np.int32)
sorted_facets = np.argsort(facet_indices)
facet_tag = mesh.meshtags(msh, f_dim, facet_indices[sorted_facets], facet_markers[sorted_facets])
ds = ufl.Measure("ds", domain=msh, subdomain_data=facet_tag)
f = ufl.dot(v, fem.Constant(msh, (0.0, -1.0)))*ds(1)

# set linear problem
k = ufl.inner(rho ** 3.0*sigma(u), ufl.grad(v))*ufl.dx
problem = fem.petsc.LinearProblem(k, f, bcs=bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"})

# solve problem
u_sln = problem.solve()

# write displacement
u_sln.name = "Deformation"
file.write_function(u_sln)
file.close()

There was no problem when the write_mesh code line was executed as follows at the end line to solve the following error.

with io.XDMFFile(MPI.COMM_WORLD, f"outfile/plot.xdmf", "w") as file:
    # write mesh
    file.write_mesh(msh)
    # write displacement
    u_sln.name = "Deformation"
    file.write_function(u_sln)
file.close()

In my opinion, I simply changed the location of write_mesh, but I’m not sure why the vtk time-out error occurs.

Is this part a bug? Or is there a solution?
Thanks for reading the post. :pray:

This is using a context manager (27. Context Managers — Python Tips 0.1 documentation) which means that the file is closed when you exit the indentation.

If you want to use with:

you should call

file = io.XDMFFile(MPI.COMM_WORLD, f"outfile/plot.xdmf", "w")
file.write_mesh(mesh)
# do other stuff then call your code above and close the file.
1 Like

Thank you for reply asap, @dokken ! :raised_hands:
Oh! The file runs fine without errors. Thanks for the ideas you gave!

Then, this is a question after resolving the error.
If so, why does an error not occur even we using the python context manager method when the mesh size is small?

Because Python does garbage collection whenever it feels like (which isn’t directly after things going out of scope), thus for a small mesh, it might not have deleted the object yet, while for a larger problem the garbage collector has done its job prior to you reaching that code.

1 Like

Aha, that’s why!
I wondered why the code didn’t have any logic problems, but now I know the reason well.
thank you! :pray: