Applying Lifting operation using PETSc

Hi everyone! I am following the beam example using PETSc interface for solving a deflection of a beam posted here:

I am using FenicsX v0.9 and I am encountering a problem in the following lines from the example:

g = dolfinx.fem.Function(V)
g.x.array[:] = 0
dolfinx.fem.set_bc(g.x.array, bcs)
g.x.scatter_forward()
L_lifted = L - ufl.action(a, g)

I am getting the following error:

TypeError: set(): incompatible function arguments. The following argument types are supported:1. set(self, b: ndarray[dtype=float64, shape=(), order=‘C’], x0: ndarray[dtype=float64, writable=False, shape=(), order=‘C’] | None, alpha: float) → None
Invoked with types: dolfinx.cpp.fem.DirichletBC_float64, ndarray, NoneType, int

Additionally, when I started to investigate a little about this error, it seems that dolfinx.fem.set_bc() is deprecated and it is recommended to use dolfinx.fem.DirichletBC class instead. Would someone please guide me to find a work around to this issue?

Thanks in advance for your time!

Cheers!

I am not getting that error when using the dolfinx/dolfinx:v0.9.0 docker image. Could you describe your set-up?

Thanks for the quick response. I’m running FenicsX v0.9.0 under Ubuntu 22.04. Please let me know if you need extra information.

cheers!

That’s a very minimal description of your set-up :wink:

Based on the dolfinx:v0.9.0 docker image running the code properly, there must be some sort of installation inconsistency on your end. In that image:

dolfinx.__version__ == '0.9.0' # Obviously...
petsc4py.__version__ == '3.22.0'
numpy.__version__ == '2.0.2' # I suspect the issue is here. Simply `pip3 install numpy --upgrade`

Hi Stein, thanks for the quick response and apologies for gaving such a minimal description of my set-up. I’m running FenicsX v0.9.0 installed on Ubuntu 22.04 via conda. In what follows, I expand on my packages set-up:

dolfinx.version == ‘0.9.0’
petsc4py.version == ‘3.23.4’
numpy.version == ‘2.3.1’

It seems that these packages are newer comparing with those you pointed previously. Could it be a change of interphase between numpy or petsc4py versions?

Many thanks for taking the time for reviewing this and helping to understand what would be the problem.

Cheers!