This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to interpolate a function from mesh to another different mesh

+3 votes

The geometry is a cube with a hole inside and I have a function defined on the two boundaries( internal and external boundaries) I will use this function as a Neumann boundary condition for another problem in the cube (but without hole) with a new mesh form. So I need to interpolate the function in the new mesh. Any help is appreciated

asked Jul 18, 2013 by meftahi FEniCS Novice (300 points)

2 Answers

+3 votes
parameters['allow_extrapolation'] = True
u = Function(V_hole)
parameters['allow_extrapolation'] = False
u = project(u, V_without_hole)

Note that currently projection/interpolation/evaluation on non-matching meshes does not work in parallel.

answered Jul 18, 2013 by Jan Blechta FEniCS Expert (51,420 points)

with this code
parameters['allow_extrapolation'] = True
u = Function(V_hole)
parameters['allow_extrapolation'] = False
u = project(u, V_without_hole)

I have got the following error

DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at


*** https://answers.launchpad.net/dolfin


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to evaluate function at point.
*** Reason: No matching cell found.
*** Where: This error was encountered inside Function.cpp.
*** Process: 0

Ok, maybe parameters['allow_extrapolation'] = True is not able to interpolate to holes. Nevertheless could you supply include a minimal running example to reproduce the error?

Should project and interpolate be able to project and interpolate between two different meshes? I have not been able to get either of them to work.

I tried mikael-mortensen's interpolate_nonmatching_mesh below but I have not been able to install mpi4py and so I have not been able to get it to run.

If project and interpolate do not work between non-matching meshes there is some reason. For instance it is known that it does not work in parallel.

Parallel interpolate_nonmatching_mesh has been implemented into DOLFIN (and improved) as LagrangeInterpolator thanks to Mikael and others.

+4 votes

Hi,

I have some code that you can use to interpolate from one mesh to another:

https://github.com/mikaem/fenicstools/wiki/Interpolate-nonmatching-mesh

It should run in parallel as well. (It may not work with the newest dolfin because there was recently some major changes to the mesh intersection code and I've been away for 3 weeks...)

Best regards

Mikael

answered Jul 23, 2013 by mikael-mortensen FEniCS Expert (29,340 points)

Hi Mikael,

when i use interpolate_nonmatching_mesh i get name Error

The code only works with a late dolfin version. You probably have an older version?

I have downloaded the last version dolfin 1.2.0 for mac osx 10.6 and i still get the same error to use interpolate_nonmatching_mesh

You need an even newer version. Did you try a snapshot version

...