Interpolation on non-matching meshes

Hello everyone,

I’m currently working on a time-dependent problem, where my geometry evolves over time. To future prove this, I would like to work with dolfinx, however, I need to adjust/refine my mesh from time to time. Is there a way to interpolate a function on non-matching meshes in dolfinx? Or is there any workaround I could use?

Best regards
Max

See: Interpolation between different meshes by massimiliano-leoni · Pull Request #2245 · FEniCS/dolfinx · GitHub

1 Like

Thank you for your answer. Can you estimate when this pull request will be included in the current version?

It is hard to do estimates on this. I would think quite soon (within a week or two), but I cannot promise anything.

1 Like

Thank you. This sounds great, then I can continue with working in dolfinx.

Hi,

Was this feature eventually included in dolfinx? I just tried to do it in the way described in old docs and it didn’t work. Here is an MWE

import gmsh, dolfinx, ufl, mpi4py, petsc4py
import numpy as np
from dolfinx.io import gmshio

a = 1
L = 8*a
c1 = (L/2, L/2) # center of circle in first geometry
c2 = (L/2+0.1, L/2) # center of circle in second geometry
Um = 1

gmsh.initialize()
gdim = 2
model_rank = 0
occ = gmsh.model.occ

rectangle = occ.addRectangle(0,0,0, L, L)
obstacle = occ.addDisk(c1[0], c1[1], 0, a, a)
occ.synchronize()
geom, _ = occ.cut([(gdim, rectangle)], [(gdim, obstacle)])
occ.synchronize()

domains = gmsh.model.getEntities(dim=gdim)
assert(len(domains) == 1)
gmsh.model.addPhysicalGroup(domains[0][0], [domains[0][1]], 1)
gmsh.model.setPhysicalName(domains[0][0], 1, "Fluid")

gmsh.model.mesh.generate(gdim)
gmsh.model.mesh.refine()
mesh1, ct1, ft1 = gmshio.model_to_mesh(gmsh.model, mpi4py.MPI.COMM_WORLD, model_rank, gdim=gdim)

gmsh.clear()

rectangle = occ.addRectangle(0,0,0, L, L)
obstacle = occ.addDisk(c2[0], c2[1], 0, a, a)
occ.synchronize()
geom, _ = occ.cut([(gdim, rectangle)], [(gdim, obstacle)])
occ.synchronize()

domains = gmsh.model.getEntities(dim=gdim)
assert(len(domains) == 1)
gmsh.model.addPhysicalGroup(domains[0][0], [domains[0][1]], 1)
gmsh.model.setPhysicalName(domains[0][0], 1, "Fluid")

gmsh.model.mesh.generate(gdim)
gmsh.model.mesh.refine()
mesh2, ct2, ft2 = gmshio.model_to_mesh(gmsh.model, mpi4py.MPI.COMM_WORLD, model_rank, gdim=gdim)
gmsh.finalize()


velocity = lambda x: 4*Um*x[1]*(L-x[1])

V1 = dolfinx.fem.FunctionSpace(mesh1, ("CG", 2))
u1 = dolfinx.fem.Function(V1)
u1.interpolate(velocity)

# now that we have u1 defined on mesh1, let us use it to define u2 on mesh2

V2 = dolfinx.fem.FunctionSpace(mesh2, ("CG",2))
u2 = dolfinx.fem.Function(V2)
u2.interpolate(u1)

Of course the last step u2.interpolate(u1) runs into error:

RuntimeError: Interpolation on different meshes not supported (yet).

The PR is still open:

The feature has now been included in DOLFINx, ref: Interpolation between different meshes by massimiliano-leoni · Pull Request #2245 · FEniCS/dolfinx · GitHub

Hello @dokken, as far as I can see, this feature is not considered in dolfinx 0.5.2 yet. Am I correct?

You are correct. It was merged after the 0.5 release, and will be in the 0.6 release

1 Like

Is there an expected timeline for this release?

Soonish, currently we are having some issues with version bumping of PETSc and some other minor things.

I cannot give an accurate estimate, but I would expect before the end of 2022.

concerning the usage of the new function
create_nonmatching_meshes_interpolation_data
From the docs I understand that I have to pass as arguments both of the function spaces between which I want to interpolate.

However, is important the order of the arguments? that is, which FunctionSpace do I have to put as first argument, the one I am intepolatin into, o the one I am interpolation from?

Thank you

See the documentation: dolfinx/interpolate.h at 8d55f950ca427228a96e96d43893b52b5071bf35 · FEniCS/dolfinx · GitHub

1 Like