Problem regarding assembling matrix using dolfinx_mpc

Hello, I want to use dolfinx_mpc to impose periodic boundary condition to solve the Poisson equation, but I got some PETSC ERROR

I define my linear and bilinear forms as follows:

create the mesh and function space

The periodic condition and relation are defined here

Then I create the MPC as follows(maybe it is not correct

and when I tried to assemble the matrix:

I get error, the error message is


and

It seems like the way I assemble the matrix causes the error, the problems may be within here:

la::petsc::Matrix::set_block_fn(A.mat(), ADD_VALUES)
la::petsc::Matrix::set_fn(A.mat(), ADD_VALUES)

is there anyone know how to solve this issue? Thanks very much!

With screenshots it is really hard to reproduce your error. Please use the DOLFINx_mpc issue tracker on github and attach a minimal reproducible example.

Hi, thanks for reminding! I will do that in the future.

I have figured out the problem, it is because the way I created the matrix is not correct, when MPC is applied, we should creat the matrix using sparsity_pattern, instead of using only the form.