Skip to content

Custom Basix elements giving incorrect results #2586

@mscroggs

Description

@mscroggs

In this code snippet, the element e2 should be a copy of e1 but as a custom element, so the error should be 0. But it is around 0.66.

import dolfinx
import basix
import ufl

from mpi4py import MPI

mesh = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 5, 5, 5, dolfinx.mesh.CellType.tetrahedron)

func = lambda x: x
exact = ufl.SpatialCoordinate(mesh)

e1 = basix.create_element(
    basix.ElementFamily.N1E, basix.CellType.tetrahedron, 1, basix.LagrangeVariant.equispaced)
e2 = basix.create_custom_element(
    e1.cell_type, e1.value_shape, e1.wcoeffs, e1.x, e1.M, 0, e1.map_type, e1.sobolev_space,
    e1.discontinuous, e1.highest_complete_degree, e1.degree)

space1 = dolfinx.fem.FunctionSpace(mesh, basix.ufl_wrapper.BasixElement(e1))
space2 = dolfinx.fem.FunctionSpace(mesh, basix.ufl_wrapper.BasixElement(e2))

f1 = dolfinx.fem.Function(space1)
f2 = dolfinx.fem.Function(space2)
f1.interpolate(func)
f2.interpolate(func)

diff = f1 - f2

error = dolfinx.fem.assemble_scalar(dolfinx.fem.form(ufl.inner(diff, diff) * ufl.dx)) 

print(error)

The error is correctly 0 for Lagrange function spaces.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions