PETSc error with mesh from meshio

Hi everyone,

I’m using a mesh that I converted using meshio.
Available here: mesh.zip - Google Drive

When trying to solve a simple problem on it, I get this error:

No Jacobian form specified for nonlinear variational problem.
Differentiating residual form F to obtain Jacobian J = F'.
Solving nonlinear variational problem.
  Newton iteration 0: r (abs) = 5.430e+01 (tol = 1.000e-10) r (rel) = 1.000e+00 (tol = 1.000e-09)
Traceback (most recent call last):
  File "/home/remidm/Fusion-TES-Modeling/MWE.py", line 32, in <module>
    solve(F == 0, u, bcs)
  File "/home/remidm/miniconda3/envs/tes-model-env/lib/python3.11/site-packages/dolfin/fem/solving.py", line 220, in solve
    _solve_varproblem(*args, **kwargs)
  File "/home/remidm/miniconda3/envs/tes-model-env/lib/python3.11/site-packages/dolfin/fem/solving.py", line 266, in _solve_varproblem
    solver.solve()
RuntimeError: 

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to successfully call PETSc function 'MatSetValuesLocal'.
*** Reason:  PETSc error code is: 63 (Argument out of range).
*** Where:   This error was encountered inside /home/conda/feedstock_root/build_artifacts/fenics-pkgs_1696906506503/work/dolfin/dolfin/la/PETScMatrix.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2019.1.0
*** Git changeset:  2e001bd1aae8e14d758264f77382245e6eed04b0
*** -------------------------------------------------------------------------

I have noticed that depending on how I use dx in the formulation it does or doesn’t work.

I’m guessing it may be a tagging issue? Although when I inspect volume_markers it only contains 6 and it has the same size as the mesh (141787 cells).

Here is my MWE:

from fenics import *

inlet_id = 8
outlet_id = 7
fluid_id = 6

mesh = Mesh()
XDMFFile("mesh_cells.xdmf").read(mesh)

# create dx from the volume markers
volume_markers = MeshFunction("size_t", mesh, mesh.topology().dim())
XDMFFile("mesh_cells.xdmf").read(volume_markers)
dx = Measure("dx", domain=mesh, subdomain_data=volume_markers)

surface_markers = MeshValueCollection("size_t", mesh, mesh.topology().dim() - 1)
XDMFFile("mesh_facets.xdmf").read(surface_markers, "f")
surface_markers = MeshFunction("size_t", mesh, surface_markers)

V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
v = TestFunction(V)

inlet = DirichletBC(V, Constant(1), surface_markers, inlet_id)
outlet = DirichletBC(V, Constant(0), surface_markers, outlet_id)
bcs = [inlet, outlet]

F = dot(2 * grad(u), grad(v)) * dx(fluid_id)  # doesn't work
# F = 2 * dot(grad(u), grad(v)) * dx(fluid_id)  # doesn't works
# F = dot(grad(u), grad(v)) * dx(fluid_id)  # works
# F = dot(2 * grad(u), grad(v)) * dx  # works

solve(F == 0, u, bcs)

XDMFFile("solution.xdmf").write(u)

Has anyone ever experienced this?

Cheers
Remi

This is what surface markers look like:

Volume markers:

Update

After a bit of digging it appears that when I install meshio in a seperate env the issue doesn’t appear…

How did you install meshio? Did you use python3 -m pip install --no-binary=h5py h5py meshio?
Otherwise you might get issues with HDF5 conflicts.

I installed it from a conda yml file
I will try this pip install method, don’t know how to do this with the yml file but I’ll look around

If it is installed with conda it should not cause an issue (as long as dolfin also was installed with conda).

it “should” or should not?

name: tes-model-env

channels:
  - conda-forge
  - defaults

dependencies:
  - pip
  - fenics
  - numpy==1.24
  - pip:
    - meshio[all]

This is how I was doing it

I corrected the comment above. It should not cause an issue if you do it purely through conda, i.e.

name: tes-model-env

channels:
  - conda-forge
  - defaults

dependencies:
  - pip
  - fenics
  - numpy==1.24
  - meshio

as meshio is a package on conda-forge: GitHub - conda-forge/meshio-feedstock: A conda-smithy repository for meshio.

Right, I didn’t know it had a conda package. Thanks!