Automatic update to Fenicsx 0.8 broke ufl.FiniteElement

Hello,
My working 0.7 installation was automatically upgraded from Ubuntu 22 PPAs to version 0.8 and is now broken. The following error was issued on previously working code:

Traceback (most recent call last):
  File "/home/bill/Cluster/Fenics2020/DielectricResonators/4Resonator/QuadResonatorFilterwMonopole.py", line 183, in <module>
    elem = ufl.FiniteElement('Nedelec 1st kind H(curl)', mesh.ufl_cell(), degree=2)
AttributeError: module 'ufl' has no attribute 'FiniteElement'. Did you mean: 'finiteelement'?

I also tried to change the attribute to “finiteelement” and it th efollowing error popped out:

Traceback (most recent call last):
  File "/home/bill/Cluster/Fenics2020/DielectricResonators/4Resonator/QuadResonatorFilterwMonopole.py", line 183, in <module>
    elem = ufl.finiteelement('Nedelec 1st kind H(curl)', mesh.ufl_cell(), degree=2)
TypeError: 'module' object is not callable

Has anyone else seen this error? How can I fix it?

Hi,

I think there have been some changes in the API. Look here.

cf. also Replace UFL elements with Basix elements in tests and demos by mscroggs · Pull Request #2381 · FEniCS/dolfinx · GitHub
(inspect the patches to the demos)

Thanks for the tip.
Following the Github notes, I added the basix importation lines

from slepc4py import SLEPc
from petsc4py import PETSc
from mpi4py import MPI as nMPI
import basix
import basix.ufl_wrapper
import meshio
import ufl
from dolfinx.mesh import locate_entities_boundary, meshtags
from dolfinx.io import gmshio
from dolfinx import fem
from dolfinx import io
from dolfinx.fem.petsc import LinearProblem
import gmsh

and changed the element creation lines to

    elem = basix.ufl_wrapper.create_element('Nedelec 1st kind H(curl)', mesh.ufl_cell().cellname(), degree=2)
    V = fem.FunctionSpace(mesh, elem)
    u = ufl.TrialFunction(V)
    v = ufl.TestFunction(V)

Unfortunately, I get an error that basix.ufl_wrapper does not exist.

ModuleNotFoundError: No module named 'basix.ufl_wrapper'
    import basix.ufl_wrapper

What is the correct way to define the element? Is the wrapper under another name?

You’re probably best to look at how it’s done in the demos (https://fenicsproject.org/documentation/).
DOLFINx documentation — DOLFINx 0.8.0 documentation

Other demos and tutorials are available at The FEniCSx tutorial — FEniCSx tutorial

For instance there are Nedelec examples at Electromagnetic scattering from a wire with perfectly matched layer condition — DOLFINx 0.8.0 documentation

I think it should be like this:

elem = basix.ufl.element("Nedelec 1st kind H(curl)", mesh.ufl_cell().cellname(), degree=2)
V = fem.functionspace(mesh, elem)
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)

Thanks for the links! They really helped. It is all working again. :white_check_mark: