Calling assemble_vector_block in Python fails with RuntimeError: Unable to extract a mesh. if any rows of the bilinear forms provided are all None. This happens even when no boundary conditions need applying.
This problem occurs because assemble_vector_block calls apply_lifting on each row, which gets the mesh from the form (see here). Hence, if there forms are all nullptr, it can't extract a mesh.
There are a couple of solutions to this:
If there is nothing to lift, apply_lifting should probably just return without doing anything. This would be done at the C++ level.
Don't call apply_lifting when there is nothing to lift. This would mean adding a check in Python to assemble_vector_block.
I think I prefer the first option. Regardless, I think it would be good to separate the lifting and bc application out of assemble_vector_block so we'd have assemble_vector_block, apply_lifting_block, and set_bc_block. This is consistent with non-blocked problems and gives more control to the user.
How to reproduce the bug
Run the minimal example below.
Minimal Example (Python)
from mpi4py import MPI
from dolfinx import mesh, fem
import ufl
import dolfinx.fem.petsc
comm = MPI.COMM_WORLD
msh = mesh.create_unit_square(comm, 2, 2)
V = fem.functionspace(msh, ("Lagrange", 1))
W = fem.functionspace(msh, ("Lagrange", 2))
v = ufl.TestFunction(V)
w = ufl.TestFunction(W)
L = fem.form([v * ufl.dx, w * ufl.dx])
b = dolfinx.fem.petsc.assemble_vector_block(L, [[None, None], [None, None]])
Summarize the issue
Calling
assemble_vector_block
in Python fails withRuntimeError: Unable to extract a mesh.
if any rows of the bilinear forms provided are allNone
. This happens even when no boundary conditions need applying.This problem occurs because
assemble_vector_block
callsapply_lifting
on each row, which gets the mesh from the form (see here). Hence, if there forms are allnullptr
, it can't extract a mesh.There are a couple of solutions to this:
apply_lifting
should probably just return without doing anything. This would be done at the C++ level.apply_lifting
when there is nothing to lift. This would mean adding a check in Python toassemble_vector_block
.I think I prefer the first option. Regardless, I think it would be good to separate the lifting and bc application out of
assemble_vector_block
so we'd haveassemble_vector_block
,apply_lifting_block
, andset_bc_block
. This is consistent with non-blocked problems and gives more control to the user.How to reproduce the bug
Run the minimal example below.
Minimal Example (Python)
Output (Python)
No response
Version
main branch
DOLFINx git commit
No response
Installation
No response
Additional information
No response