# How to work with nonconforming meshes?

**URL:** <https://fenicsproject.discourse.group/t/how-to-work-with-nonconforming-meshes/17735>\
**Category:** mesh\
**Tags:** boundary-conditions\
**Created:** [June 11, 2025, 2:25pm UTC](https://fenicsproject.discourse.group/t/how-to-work-with-nonconforming-meshes/17735 "2025-06-11T14:25:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giovanni\_Esposito](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/giovanni_esposito/32/8530_2.png) [@Giovanni\_Esposito](https://fenicsproject.discourse.group/u/Giovanni_Esposito)\
**Post date:** [June 11, 2025, 2:25pm UTC](https://fenicsproject.discourse.group/t/how-to-work-with-nonconforming-meshes/17735/1 "2025-06-11T14:25:55Z")

</div>

Hi, I solved a Dirichlet problem associated to a Laplace equation with FEniCSx, in a square.  
After that, I computed the normal derivatives in the cells of the mesh adjacent to the boundary of the square.  
Then I want to map these derivatives on the dofs of the inner boundary of a domain made up by a rectangle with a hole in the centre, where the hole is the square in which I solved the problem. I managed to do this when the two meshes are conforming, but when the two meshes are not conforming how can I do this? Is there a specific function that I can use?  
I paste the code that works with conforming meshes

```auto
def map_normal_derivatives_on_dof(V, msh, inner_facets, normal_derivatives_dict):
    """
    Map the normal derivatives (from dict di interpolate_derivatives_near_boundary)
    to the DOF of the inner boundary of the rectangle with hole
    """
    import numpy as np
    import matplotlib.pyplot as plt
    from dolfinx import fem, mesh

    g_neumann = fem.Function(V)
    g_neumann.x.array[:] = 0.0

    dof_vals = np.zeros_like(g_neumann.x.array)
    dof_count = np.zeros_like(g_neumann.x.array)

    # Connettività: faccets → vertices
    msh.topology.create_connectivity(1, 0)
    edge_to_vertex = msh.topology.connectivity(1, 0)

    for facet in inner_facets:
        if facet not in normal_derivatives_dict:
            continue

        normal_derivative = normal_derivatives_dict[facet]["normal_derivative"]

        # Find the vertices (nodes) of the faccet
        nodes = edge_to_vertex.links(facet)

        for node in nodes:
            dofs = fem.locate_dofs_topological(V, 0, [node])
            for dof in dofs:
                dof_vals[dof] += normal_derivative
                dof_count[dof] += 1

    # Normalize
    mask = dof_count > 0
    g_neumann.x.array[mask] = dof_vals[mask] / dof_count[mask]

    for facet in inner_facets:
        if facet in normal_derivatives_dict:
            val = normal_derivatives_dict[facet]["normal_derivative"]
            print(f" Facet {facet}: normal_derivative = {val:.6e}")
    return g_neumann

```

This is the case that I’ studying now:

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/1/10cc33fa1013077d90368c21ae6faa1b043b839b.png)

---

<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:** [June 11, 2025, 3:15pm UTC](https://fenicsproject.discourse.group/t/how-to-work-with-nonconforming-meshes/17735/2 "2025-06-11T15:15:12Z")

</div>

If you specify the two meshes as separate `dolfinx.mesh.Mesh` instances, you can use nonmatching interpolation, see for instance:

V0.9.x:

> <https://github.com/FEniCS/dolfinx/blob/v0.9.0.post1/python/test/unit/fem/test_interpolation.py#L908-L915>

Main branch:

> <https://github.com/FEniCS/dolfinx/blob/ea9b178f5de8aeaa82b37233b0dc70dda9d88219/python/test/unit/fem/test_interpolation.py#L911-L914>
