Fast mapping between overlapping meshes

Hi all,

I have two overlapping meshes, mesh_coarse (with quadratic basis functions) and mesh_fine (with linear basis functions):

mesh_fine = refine(mesh_coarse)
V1 = FunctionSpace(mesh_fine, "CG", 1)
V2 = FunctionSpace(mesh_coarse, "CG", 2)

I now want to map vectors between both meshes (in parallel). Right now, I’m using LagrangeInterpolator.interpolate, which works. This is, however, very slow and inefficient since both meshes have the same number of DOFs and the mapping actually stays the same.

Does anybody how to map between two vectors in V1 and V2 in parallel?

Thank you very much!

I found a fast solution for this. First, get a local mapping once

i1 = Function(V1)
i2 = Function(V2)
i1.vector()[:] = V1.dofmap().dofs()
LagrangeInterpolator.interpolate(i2, i1)

Then, in each time step, map between functions v1 and v2 from spaces V1 and V2, respectively, via

v2.vector()[:] = v1.vector().gather(np.array(i2.vector()[:] + 0.5).astype(int))