---
title: "ElementMeshInterpolation"
language: "en"
type: "Symbol"
summary: "ElementMeshInterpolation[{emesh}, {f1, f2, ...}] constructs an InterpolatingFunction object of the function values fj, corresponding to coordinate j of an ElementMesh object. ElementMeshInterpolation[{{t1, t2, ...}, emesh}, {{{f11, f12, ...}}, {{f21, f22, ...}}, ...}] constructs an interpolation of the function values fij, corresponding to discrete ti and coordinate j of an ElementMesh object."
keywords: 
- Interpolation
- Element
- Mesh
- ElementMesh
- Element Mesh
- Mesh Interpolation
- Element Mesh Interpolation
- InterpolatingFunction
- InterpolatingFunction Mesh
- InterpolatingFunction ElementMesh
- Extrapolation
- Mesh Extrapolation
- Extrapolation Handler
canonical_url: "https://reference.wolfram.com/language/FEMDocumentation/ref/ElementMeshInterpolation.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Finite Element Method"
    link: "https://reference.wolfram.com/language/FEMDocumentation/guide/FiniteElementMethodGuide.en.md"
related_tutorials: 
  - 
    title: "Finite Element Best Practice"
    link: "https://reference.wolfram.com/language/FEMDocumentation/tutorial/FiniteElementBestPractice.en.md#1204935447"
  - 
    title: "Element Mesh Generation"
    link: "https://reference.wolfram.com/language/FEMDocumentation/tutorial/ElementMeshCreation.en.md"
  - 
    title: "Finite Element Programming"
    link: "https://reference.wolfram.com/language/FEMDocumentation/tutorial/FiniteElementProgramming.en.md"
---
## NDSolve\`FEM\`

# ElementMeshInterpolation

ElementMeshInterpolation[{emesh}, {f1, f2, …}] constructs an InterpolatingFunction object of the function values fj, corresponding to coordinate j of an ElementMesh object.

ElementMeshInterpolation[{{t1, t2, …}, emesh}, 
	{{{f11, f12, …}}, {{f21, f22, …}}, …}] constructs an interpolation of the function values fij, corresponding to discrete ti and coordinate j of an ElementMesh object.

## Details and Options

* ``ElementMeshInterpolation`` returns an ``InterpolatingFunction`` object, which can be used like any other pure function.

* The function values ``f`` can be real or complex numbers.

* The ``ElementMesh`` object may contain curved elements.

* ``ElementMeshInterpolation`` works by fitting polynomial curves between data points belonging to the same element.

* The degree of the polynomial curves is specified by the option ``InterpolationOrder``.

* The default ``InterpolationOrder`` is the order of the ``ElementMesh``.

* You can do linear interpolation by using the setting ``InterpolationOrder -> 1``.

* ``ElementMeshInterpolation[data]`` generates an ``InterpolatingFunction`` object that returns values with ``MachinePrecision``.

* ``ElementMeshInterpolation`` has the same options as ``Interpolation``, with the following additions:

"ExtrapolationHandler" 	[`Automatic`](https://reference.wolfram.com/language/ref/Automatic.en.md)	specify how extrapolation is handled

* Setting the option from ``NDSolve`` and related functions is explained in [NDSolve Finite Element Options](https://reference.wolfram.com/language/FEMDocumentation/tutorial/FiniteElementOptions.en.md).

---

## Examples (9)

### Basic Examples (2)

Load the package:

```wl
In[1]:= Needs["NDSolve`FEM`"]
```

Set up an ``ElementMesh`` :

```wl
In[2]:= mesh = ToElementMesh[Disk[]]

Out[2]= ElementMesh[{{-1., 1.}, {-1., 1.}}, {TriangleElement[<504>]}]
```

Set up function values at the mesh coordinates:

```wl
In[3]:= Short[values = Function[{x, y}, x ^ 2 + y ^ 2]@@@mesh["Coordinates"]]

Out[3]//Short= {1., 1., «1054», 1.}
```

Create an ``InterpolatingFunction`` :

```wl
In[4]:= if = ElementMeshInterpolation[{mesh}, values]

Out[4]=
InterpolatingFunction[{{-1.0000000000000067, 1.000000000000007}, 
  {-1.0000000000000067, 1.0000000000000067}}, {5, 4225, 0, {1057, 0}, {3, 0}, 0, 0, 0, 0, 
  Automatic, {}, {}, False}, {NDSolve`FEM`ElementMesh[CompressedData["«16975»"], 
   {NDSol ...  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}]}]}, CompressedData["«7541»"], {Automatic}]
```

Apply the function to find interpolated values:

```wl
In[5]:= if[0, 0]

Out[5]= 3.469446951953614`*^-18
```

Plot the interpolating function:

```wl
In[6]:= Plot3D[if[x, y], {x, y}∈Disk[]]

Out[6]= [image]
```

---

Generate function values for a time-dependent interpolation:

```wl
In[1]:=
time = Range[0, 1, 0.1];
data = {values * #}& /@ Sin[time];
```

Construct a time-dependent interpolating function:

```wl
In[2]:= tif = ElementMeshInterpolation[{time, mesh}, data]

Out[2]=
InterpolatingFunction[{{0., 1.}, {-1.0000000000000067, 1.000000000000007}, 
  {-1.0000000000000067, 1.0000000000000067}}, {5, 4225, 0, {11, 1057, 0}, {4, 3, 0}, 0, 0, 0, 0, 
  Automatic, {}, {}, False}, {{0., 0.1, 0.2, 0.30000000000000004, 0.4, 0.5 ...  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}]}]}, CompressedData["«74563»"], {Automatic, Automatic}]
```

### Options (6)

#### "ExtrapolationHandler" (6)

Construct an ``InterpolatingFunction`` :

```wl
In[1]:= if = ElementMeshInterpolation[{mesh}, values]

Out[1]=
InterpolatingFunction[{{-1.0000000000000067, 1.000000000000007}, 
  {-1.0000000000000067, 1.0000000000000067}}, {5, 4225, 0, {1057, 0}, {3, 0}, 0, 0, 0, 0, 
  Automatic, {}, {}, False}, {NDSolve`FEM`ElementMesh[CompressedData["«16979»"], 
   {NDSol ...  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}]}]}, CompressedData["«7537»"], {Automatic}]
```

Query the ``InterpolatingFunction`` outside of its domain:

```wl
In[2]:= if[2, 2]
```

InterpolatingFunction::femdmval: Input value {2.,2.} lies outside the range of data in the interpolating function.

```wl
Out[2]= 8.
```

Construct an ``InterpolatingFunction`` with an extrapolation handler that returns ``Indeterminate`` for queries outside the domain:

```wl
In[3]:= if = ElementMeshInterpolation[{mesh}, values, "ExtrapolationHandler" -> {Function[Indeterminate]}]

Out[3]=
InterpolatingFunction[{{-1.0000000000000067, 1.000000000000007}, 
  {-1.0000000000000067, 1.0000000000000067}}, {5, 4225, 0, {1057, 0}, {3, 0}, 0, 0, 0, 0, 
  Indeterminate & , {}, {}, False}, 
 {NDSolve`FEM`ElementMesh[CompressedData["«16979»"], 
 ...  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}]}]}, CompressedData["«7537»"], {Automatic}]
```

Query the ``InterpolatingFunction`` outside of its domain:

```wl
In[4]:= if[2, 2]
```

InterpolatingFunction::femdmval: Input value {2.,2.} lies outside the range of data in the interpolating function.

```wl
Out[4]= Indeterminate
```

---

Construct an ``InterpolatingFunction`` with an extrapolation handler that extrapolates outside its domain and does not give a warning message:

```wl
In[1]:= if = ElementMeshInterpolation[{mesh}, values, "ExtrapolationHandler" -> {Automatic, "WarningMessage" -> False}]

Out[1]=
InterpolatingFunction[{{-1.0000000000000067, 1.000000000000007}, 
  {-1.0000000000000067, 1.0000000000000067}}, {5, 4224, 0, {1057, 0}, {3, 0}, 0, 0, 0, 0, 
  Automatic, {}, {}, False}, {NDSolve`FEM`ElementMesh[CompressedData["«16979»"], 
   {NDSol ...  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}]}]}, CompressedData["«7537»"], {Automatic}]
```

Query the ``InterpolatingFunction`` outside of its domain:

```wl
In[2]:= if[2, 2]

Out[2]= 8.
```

---

Construct an ``InterpolatingFunction`` with an extrapolation handler that returns 0 outside its domain:

```wl
In[1]:= if = ElementMeshInterpolation[{mesh}, values, "ExtrapolationHandler" -> {Function[0.]}]

Out[1]=
InterpolatingFunction[{{-1.0000000000000067, 1.000000000000007}, 
  {-1.0000000000000067, 1.0000000000000067}}, {5, 4225, 0, {1057, 0}, {3, 0}, 0, 0, 0, 0, 0. & , 
  {}, {}, False}, {NDSolve`FEM`ElementMesh[CompressedData["«16979»"], 
   {NDSolve`F ...  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}]}]}, CompressedData["«7537»"], {Automatic}]
```

Query the ``InterpolatingFunction`` outside of its domain:

```wl
In[2]:= if[2, 2]
```

InterpolatingFunction::femdmval: Input value {2.,2.} lies outside the range of data in the interpolating function.

```wl
Out[2]= 0.
```

---

Construct an ``InterpolatingFunction`` with an extrapolation handler that returns ``Indeterminate`` outside its domain and does not give a warning message:

```wl
In[1]:= if = ElementMeshInterpolation[{mesh}, values, "ExtrapolationHandler" -> {Function[Indeterminate], "WarningMessage" -> False}]

Out[1]=
InterpolatingFunction[{{-1.0000000000000067, 1.000000000000007}, 
  {-1.0000000000000067, 1.0000000000000067}}, {5, 4224, 0, {1057, 0}, {3, 0}, 0, 0, 0, 0, 
  Indeterminate & , {}, {}, False}, 
 {NDSolve`FEM`ElementMesh[CompressedData["«16979»"], 
 ...  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}]}]}, CompressedData["«7537»"], {Automatic}]
```

Query the ``InterpolatingFunction`` outside of its domain:

```wl
In[2]:= if[2, 2]

Out[2]= Indeterminate
```

---

The default for ``NDSolve`` and the finite element method is to return ``InterpolatingFunction`` objects that do not extrapolate outside of the given domain:

```wl
In[1]:=
ifun = NDSolveValue[{Laplacian[u[x, y], {x, y}] == 1, DirichletCondition[u[x, y] == 0, True]}, u, {x, y}∈Disk[]];
ifun[2, 0]
```

InterpolatingFunction::femdmval: Input value {2.,0.} lies outside the range of data in the interpolating function.

```wl
Out[1]= Indeterminate
```

Allow ``InterpolatingFunction`` objects generated by ``NDSolve`` to extrapolate when evaluated outside of the simulation domain and not warn about it:

```wl
In[2]:=
ifun = NDSolveValue[{Laplacian[u[x, y], {x, y}] == 1, DirichletCondition[u[x, y] == 0, True]}, u, {x, y}∈Disk[], "ExtrapolationHandler" -> {Automatic, "WarningMessage" -> False}];
ifun[2, 0]

Out[2]= 0.752285
```

---

While it is not generally possible to construct periodic interpolating functions for arbitrary meshes, one can mimic periodic interpolating functions based on rectangular regions by specifying an ``"ExtrapolatiopnHandler"``.

Generate data and a mesh:

```wl
In[1]:=
data = Flatten[Table[{i, j, Sin[i + j]}, {i, 0, 2 π, 2 π / 50}, {j, 0, 2 π, 2 π / 50}], 1];
mesh = ToElementMesh["Coordinates" -> data[[All, {1, 2}]]]

Out[1]= ElementMesh[{{0., 6.28319}, {0., 6.28319}}, {TriangleElement[<5000>]}]
```

Generate a temporary interpolating function from this mesh and data:

```wl
In[2]:= temp = ElementMeshInterpolation[{mesh}, data[[All, 3]]];
```

Use the extrapolation handler to map the coordinates outside of the meshed domain back into the domain and evaluate over the temporary interpolating function:

```wl
In[3]:= f = ElementMeshInterpolation[{mesh}, data[[ ;; , -1]], "ExtrapolationHandler" -> {Function[{x, y}, temp[Mod[x, 2 π], Mod[y, 2 π]]]}]

Out[3]=
InterpolatingFunction[{{0., 6.283185307179586}, {0., 6.283185307179586}}, 
 {5, 4225, 0, {2601, 0}, {2, 0}, 0, 0, 0, 0, Function[{x, y}, temp[Mod[x, 2*Pi], Mod[y, 2*Pi]]], 
  {}, {}, False}, {NDSolve`FEM`ElementMesh[CompressedData["«10375»"], {NDSolve`FEM`TriangleElement[CompressedData["«26229»"]]}, 
   {NDSolve`FEM`LineElement[CompressedData["«683»"]]}]}, CompressedData["«485»"], {Automatic}]
```

To verify that the interpolation is now periodic, visualize the function ``f`` both inside and outside the original domain:

```wl
In[4]:= {ContourPlot[f[x, y], {x, 0, 2 π}, {y, 0, 2 π}], ContourPlot[f[x, y], {x, 0, 4 π}, {y, 0, 4 π}]}

Out[4]= [image]
```

### Properties & Relations (1)

For time-independent interpolation, ``ListInterpolation`` can also be used:

```wl
In[1]:= ListInterpolation[values, mesh]

Out[1]=
InterpolatingFunction[{{-1.0000000000000067, 1.000000000000007}, 
  {-1.0000000000000067, 1.0000000000000067}}, {5, 4225, 0, {1057, 0}, {3, 0}, 0, 0, 0, 0, 
  Automatic, {}, {}, False}, {NDSolve`FEM`ElementMesh[CompressedData["«16975»"], 
   {NDSol ...  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}]}]}, CompressedData["«7541»"], {Automatic}]
```

## See Also

* [`Interpolation`](https://reference.wolfram.com/language/ref/Interpolation.en.md)
* [`ListInterpolation`](https://reference.wolfram.com/language/ref/ListInterpolation.en.md)
* [ToElementMesh](https://reference.wolfram.com/language/FEMDocumentation/ref/ToElementMesh.en.md)
* [ElementMesh](https://reference.wolfram.com/language/FEMDocumentation/ref/ElementMesh.en.md)
* [EvaluateOnElementMesh](https://reference.wolfram.com/language/FEMDocumentation/ref/EvaluateOnElementMesh.en.md)
* [DiscontinuousInterpolatingFunction](https://reference.wolfram.com/language/FEMDocumentation/ref/DiscontinuousInterpolatingFunction.en.md)

## Tech Notes

* [Finite Element Best Practice](https://reference.wolfram.com/language/FEMDocumentation/tutorial/FiniteElementBestPractice.en.md#1204935447)
* [Element Mesh Generation](https://reference.wolfram.com/language/FEMDocumentation/tutorial/ElementMeshCreation.en.md)
* [Finite Element Programming](https://reference.wolfram.com/language/FEMDocumentation/tutorial/FiniteElementProgramming.en.md)

## Related Guides

* [Finite Element Method](https://reference.wolfram.com/language/FEMDocumentation/guide/FiniteElementMethodGuide.en.md)