# FEniCSx 0.9 interpolate\_nonmatching

**URL:** <https://fenicsproject.discourse.group/t/fenicsx-0-9-interpolate-nonmatching/16516>\
**Category:** Errors\
**Created:** [December 15, 2024, 4:33pm UTC](https://fenicsproject.discourse.group/t/fenicsx-0-9-interpolate-nonmatching/16516 "2024-12-15T16:33:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mungerct](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@Mungerct](https://fenicsproject.discourse.group/u/Mungerct)\
**Post date:** [December 15, 2024, 4:33pm UTC](https://fenicsproject.discourse.group/t/fenicsx-0-9-interpolate-nonmatching/16516/1 "2024-12-15T16:33:49Z")

</div>

I am in the process of updating my code to FEniCSx 0.9, and part of that update is using the new “interpolate\_nonmatching” function. I have created a test script to practice the new function, however I get the error:

```auto
  File "/home/mungerct/research/Stabilized_Stokes_Flow_FEniCSx/FE_Practice/interpolate_nonmatching_example.py", line 30, in <module>
    interpolation_data = fem.create_interpolation_data(mesh0, mesh1, # interpolating form mesh1 to mesh0
            cells, padding=1.0e-6)
  File "/home/mungerct/miniconda3/envs/fenicsx/lib/python3.13/site-packages/dolfinx/fem/ __init__.py", line 94, in create_interpolation_data
    V_to.mesh._cpp_object.geometry, V_to.element, V_from.mesh._cpp_object, cells, padding
    ^^^^^^^^^
AttributeError: 'Mesh' object has no attribute 'mesh'

```

Below is the code I am using to practice interpolating between non-matching meshes. I am trying to interpolate a 2D solution onto a 3D solution because in my research, I need to interpolate a 2D solution as the boundary condition for a 3D problem.

I could not find any code examples for the new `interpolate_nonmatching` function, if any are out there please let me know so I can look at them for additional help.

```auto
Here is my code:
from dolfinx.mesh import create_unit_square, create_unit_cube, CellType
from basix.ufl import element
from dolfinx import fem
from mpi4py import MPI
import numpy as np

xtype = np.float64

cell_type0 = CellType.hexahedron
cell_type1 = CellType.triangle

mesh0 = create_unit_cube(MPI.COMM_WORLD, 5, 6, 7, cell_type=cell_type0, dtype=xtype) # 3D mesh
mesh1 = create_unit_square(MPI.COMM_WORLD, 5, 4, cell_type=cell_type1, dtype=xtype) # 2D mesh

el0 = element("Lagrange", mesh0.topology.cell_name(), 1)
V0 = fem.functionspace(mesh0, el0)
el1 = element("Lagrange", mesh1.topology.cell_name(), 1)
V1 = fem.functionspace(mesh1, el1)

# Interpolate on 2D mesh

u1 = fem.Function(V1, dtype=xtype)
u1.interpolate(lambda x: 7 * x[1] + 3 * x[0]) # Sample function to interpolate
u1.x.scatter_forward()

# Interpolate 2D->3D

msh_cell_map = mesh0.topology.index_map(mesh0.topology.dim)
num_cells_on_proc = msh_cell_map.size_local + msh_cell_map.num_ghosts
cells = np.arange(num_cells_on_proc, dtype=np.int32)
interpolation_data = fem.create_interpolation_data(mesh0, mesh1, # interpolating form mesh1 to mesh0
cells, padding=1.0e-6)
mesh0.sub(0).interpolate_nonmatching(mesh0, cells, interpolation_data)

```

I am using FEniCSx 0.9 installed on Linux (Ubuntu) using anaconda

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [December 15, 2024, 5:10pm UTC](https://fenicsproject.discourse.group/t/fenicsx-0-9-interpolate-nonmatching/16516/2 "2024-12-15T17:10:14Z")

</div>

See;

> <https://github.com/FEniCS/dolfinx/blob/9ee46f0925da2930fa76ca046d047a55555dfbff/python/test/unit/fem/test_interpolation.py#L913>

and the documentation

[https://docs.fenicsproject.org/dolfinx/v0.9.0/python/generated/dolfinx.fem.html#dolfinx.fem.create\_interpolation\_data](https://docs.fenicsproject.org/dolfinx/v0.9.0/python/generated/dolfinx.fem.html#dolfinx.fem.create_interpolation_data)

[https://docs.fenicsproject.org/dolfinx/v0.9.0/python/generated/dolfinx.fem.html#dolfinx.fem.Function.interpolate\_nonmatching](https://docs.fenicsproject.org/dolfinx/v0.9.0/python/generated/dolfinx.fem.html#dolfinx.fem.Function.interpolate_nonmatching)
