I attempted to replicate the code by Jørgen S. Dokken from this discussion in my current version of FEniCSx (0.7.3), but I encountered the following error:
# Illustration of projection from one mesh to another
# Author: Jørgen S. Dokken
# SPDX License: MIT
import ufl
import dolfinx
from mpi4py import MPI
import basix.ufl
import dolfinx.fem.petsc
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
# Compute function on fine mesh
V = dolfinx.fem.functionspace(mesh, (("Lagrange", 1)))
uh = dolfinx.fem.Function(V)
uh.interpolate(lambda x: x[0]+2*x[1])
# Create coarse mesh
coarser_mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 5, 5)
V_coarse = dolfinx.fem.functionspace(coarser_mesh, ("Lagrange", 1))
# Compute function for fine grid at quadrature points of the coarse grid
degree = 4
Qe = basix.ufl.quadrature_element(
coarser_mesh.topology.cell_name(), value_shape=(),degree=degree)
V_quadrature = dolfinx.fem.functionspace(coarser_mesh, Qe)
q_e = dolfinx.fem.Function(V_quadrature)
nmmid = dolfinx.fem.create_nonmatching_meshes_interpolation_data(V_quadrature.mesh._cpp_object,
V_quadrature.element,
V.mesh._cpp_object, padding=1e-5)
q_func = dolfinx.fem.Function(V_quadrature)
q_func.interpolate(uh, nmm_interpolation_data=nmmid)
# Project fine function at quadrature points to coarse grid
u = ufl.TrialFunction(V_coarse)
v = ufl.TestFunction(V_coarse)
a_coarse = ufl.inner(u, v) * ufl.dx
L_coarse = ufl.inner(q_func, v)*ufl.dx
problem = dolfinx.fem.petsc.LinearProblem(a_coarse, L_coarse)
u_coarse = problem.solve()
with dolfinx.io.VTXWriter(coarser_mesh.comm, "u_coarse.bp", [u_coarse], engine="BP4") as bp:
bp.write(0.0)
and the error is
nmmid = dolfinx.fem.create_nonmatching_meshes_interpolation_data(V_quadrature.mesh._cpp_object,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Cannot get interpolation points - no Basix element available. Maybe this is a mixed element?
Could someone help me debug this error?