Create_box with 2nd order elements, C++

I am using a mesh generated by FEniCSx using the create_box function. When I use 2nd order elements in the ufl I get the following error.

UFL mesh and CoordinateElement do not match.

I have looked into the source code and I have seen that the create_box function initializes a CoordinateElement with degree 1 which is the reason for the error. I have tried copying the function to modify it to work with second order polynomials however I would like to know if there are there any other quick work arounds for this?

Could you share your minimal working example?

If you are referring to DOLFINx: dolfinx::mesh Namespace Reference
this function creates a mesh with a first order coordinate element, i.e. the element sent into mesh in the ufl file should be

c_el = ufl.VectorElement("Lagrange", ufl.hexahedron/ufl.tetrahedron, 1)
mesh = ufl.Mesh(c_el)

while the function space (if it is higher order) should be defined with another element

el = ufl.VectorElement("Lagrange", ufl.hexahedron/ufl.tetrahedron, 2)
V = ufl.FunctionSpace(mesh, el)
2 Likes