EvaluateOnElementMesh[{x1,…},f,mesh]
returns an InterpolatingFunction where f depending on formal parameters {x1,…} was evaluated on the ElementMesh mesh.
EvaluateOnElementMesh[{x1,…},{f1,…},mesh]
evaluates multiple expressions {f1,…} on the same mesh mesh.
EvaluateOnElementMesh[{x1,…},f,mesh]
returns a DiscontinuousInterpolatingFunction if mesh has multiple material regions.
EvaluateOnElementMesh
EvaluateOnElementMesh[{x1,…},f,mesh]
returns an InterpolatingFunction where f depending on formal parameters {x1,…} was evaluated on the ElementMesh mesh.
EvaluateOnElementMesh[{x1,…},{f1,…},mesh]
evaluates multiple expressions {f1,…} on the same mesh mesh.
EvaluateOnElementMesh[{x1,…},f,mesh]
returns a DiscontinuousInterpolatingFunction if mesh has multiple material regions.
Details and Options
- EvaluateOnElementMesh either returns an InterpolatingFunction or a DiscontinuousInterpolatingFunction.
- The interpolating function is created by solving a system of equations
where the solution
is the values at the nodes of the mesh.
is the discretized matrix of the weak form of
, with shape function
and test function
. - EvaluateOnElementMesh never evaluates
at mesh nodes, but evaluates at the integration point of the mesh elements. - EvaluateOnElementMesh has the following options:
-
"DiscontinuousInterpolation" Automatic switch off automatic discontinuity handling "ExtrapolationHandler" Automatic specify how extrapolation is handled "MarkerPriority" Automatic speficy behavior at the boundary
Examples
open all close allBasic Examples (2)
<<NDSolve`FEM`Generate an element mesh for a disk:
mesh = ToElementMesh[Disk[]]Evaluate the function
on the mesh:
fun = EvaluateOnElementMesh[{x, y}, Sin[x ^ 2 + y ^ 2], mesh]Plot3D[fun[x, y], {x, y}∈mesh]Create and visualize a multi-material ElementMesh:
mesh = ToElementMesh[RegionDifference[Rectangle[], Disk[{1 / 2, 1 / 2}, 1 / 6]], "RegionHoles" -> None, "RegionMarker" -> {{{1 / 5, 1 / 5}, 1}}];
mesh["Wireframe"["MeshElementStyle" -> {FaceForm[Gray], FaceForm[White]}]]Create a function that is discontinuous in the material region:
function = If[ElementMarker == 1, 0, 1];Evaluate the discontinuous function on the mesh:
difun = EvaluateOnElementMesh[{x, y}, function, mesh]Visualize the discontinuous interpolation function:
Plot3D[difun[x, y], {x, y}∈mesh, Mesh -> All]Options (3)
"DiscontinuousInterpolation" (1)
Discontinuous interpolation is the default, if a mesh with several material markers is given. In case discontinuous interpolation is not wanted, it can be turned off with the option "DiscontinuousInterpolation" False.
Generate and visualize a mesh with multiple regions:
mesh = ToElementMesh[RegionDifference[Rectangle[], Disk[{1 / 2, 1 / 2}, 1 / 6]], "RegionHoles" -> None, "RegionMarker" -> {{{1 / 5, 1 / 5}, 1}}];
mesh["Wireframe"["MeshElementStyle" -> {FaceForm[Gray], FaceForm[White]}]]Create a function that is discontinuous in the material region:
function = If[ElementMarker == 1, 0, 1];Evaluate the discontinuous function on the mesh:
EvaluateOnElementMesh[{x, y}, function, mesh]Evaluate the discontinuous function on the mesh but generate an InterpolatingFunction:
EvaluateOnElementMesh[{x, y}, function, mesh, "DiscontinuousInterpolation" -> False]"ExtrapolationHandler" (1)
By default, the InterpolatingFunction or the DiscontinuousInterpolatingFunction generated through EvaluateOnElementMesh will handle extrapolation by giving a warning message and performing an extrapolation. This behavior can be changed.
Evaluate the function
on the mesh:
mesh = ToElementMesh[Disk[]];
fun = EvaluateOnElementMesh[{x, y}, Sin[x ^ 2 + y ^ 2], mesh]Query the InterpolatingFunction outside of its domain:
fun[2, 2]Construct an InterpolatingFunction with an extrapolation handler that returns Indeterminate for queries outside the domain:
fun = EvaluateOnElementMesh[{x, y}, Sin[x ^ 2 + y ^ 2], mesh, "ExtrapolationHandler" -> {Function[Indeterminate]}]fun[2, 2]Construct an InterpolatingFunction with an extrapolation handler that extrapolates and does not give a warning message for queries outside the domain:
fun = EvaluateOnElementMesh[{x, y}, Sin[x ^ 2 + y ^ 2], mesh, "ExtrapolationHandler" -> {Automatic, "WarningMessage" -> False}]fun[2, 2]More information on extrapolation handling can be found in ElementMeshInterpolation.
"MarkerPriority" (1)
Specifying a marker priority allows you to control which value will be used at the material interface. Consider this 1D example mesh:
mesh = ToElementMesh[ToBoundaryMesh["Coordinates" -> {{-1}, {0}, {1}}, "BoundaryElements" -> {PointElement[{{1}, {2}, {3}}]}], "RegionMarker" -> {{{-1 / 2}, 10}, {{1 / 2}, 20}}]The mesh has markers 10 and 20:
mesh["MeshElementMarkerUnion"]Write a function that will give a value of –1 for all elements with marker 10 and a value of 1 for all other elements:
function = If[ElementMarker == 10, -1, 1];Create a discontinuous interpolating function:
fun = EvaluateOnElementMesh[{x}, function, mesh]Plot[fun[x], {x, -1, 1}]Evaluate the discontinuous function at the interface position at
:
fun[0]By inspecting the marker priority of the discontinuous interpolating function, you can see that the marker 10 precedes the marker 20. This means values associated with marker 10 will have a higher precedence than the values associated with marker 10:
fun["MarkerPriority"]The value at the interface can be set by changing the precedence of the markers:
fun = EvaluateOnElementMesh[{x}, function, mesh, "MarkerPriority" -> {20, 10}]Now, the marker priority has changed:
fun["MarkerPriority"]The value at the interface position
has changed to the value associated with marker 20:
fun[0]The overall plot looks the same, as only the value at the interface has changed:
Plot[fun[x], {x, -1, 1}]Possible Issues (1)
Computing a gradient of an InterpolatingFunction with EvaluateOnElementMesh can be problematic.
bmesh = ToBoundaryMesh["Coordinates" -> {{0, 0}, {1, 0}, {1, 1 / 2}, {1, 1}, {0, 1}, {0, 1 / 2}}, "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 1}, {3, 6}}]}];
mesh = ToElementMesh[bmesh, "RegionMarker" -> {{{1 / 2, 1 / 3}, 1}, {{1 / 2, 2 / 3}, 2}}];Set up the partial differential equation with a discontinuous coefficient:
op = Inactive[Div][-Piecewise[{{3, ElementMarker == 1}}, 1] * IdentityMatrix[2].Inactive[Grad][u[x, y], {x, y}], {x, y}];Subscript[Γ, D] = {DirichletCondition[u[x, y] == 1, y == 0], DirichletCondition[u[x, y] == 0, y == 1]};uFun = NDSolveValue[{op == 0, Subscript[Γ, D]}, u, {x, y}∈mesh];Plot3D[uFun[x, y], {x, y}∈mesh]Find the gradient of the solution on the mesh:
field = EvaluateOnElementMesh[{x, y}, Grad[-uFun[x, y], {x, y}], mesh]Visualize the gradient in the
direction along the
axis:
Plot[field[[2]][x, 0.5], {x, 0, 1}]A continuous value would be expected. This comes up because the gradient was computed on the interpolating function directly and then evaluated on the element mesh. A better approach is to first convert the interpolating function to a DiscontinuousInterpolatingFunction:
duFun = DiscontinuousInterpolatingFunction[uFun]Compute the gradient on the DiscontinuousInterpolatingFunction:
field = -Grad[duFun[x, y], {x, y}]Visualize the gradient in the
direction along the
axis at
:
Plot[Evaluate[field[[2]] /. y -> 0.5], {x, 0, 1}]Visualize the gradient in the
direction along the
axis at
:
Plot[Evaluate[field[[2]] /. x -> 0.5], {y, 0, 1}]The value of the constant at
can be changed by specifying a different "MarkerPriority":
duFun = DiscontinuousInterpolatingFunction[uFun, "MarkerPriority" -> {2, 1}];
field = -Grad[duFun[x, y], {x, y}];
Plot[Evaluate[field[[2]] /. y -> 0.5], {x, 0, 1}]Related Guides
Text
Wolfram Research (2024), EvaluateOnElementMesh, Wolfram Language function, https://reference.wolfram.com/language/FEMDocumentation/ref/EvaluateOnElementMesh.html.
CMS
Wolfram Language. 2024. "EvaluateOnElementMesh." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/FEMDocumentation/ref/EvaluateOnElementMesh.html.
APA
Wolfram Language. (2024). EvaluateOnElementMesh. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/FEMDocumentation/ref/EvaluateOnElementMesh.html
BibTeX
@misc{reference.wolfram_2026_evaluateonelementmesh, author="Wolfram Research", title="{EvaluateOnElementMesh}", year="2024", howpublished="\url{https://reference.wolfram.com/language/FEMDocumentation/ref/EvaluateOnElementMesh.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_evaluateonelementmesh, organization={Wolfram Research}, title={EvaluateOnElementMesh}, year={2024}, url={https://reference.wolfram.com/language/FEMDocumentation/ref/EvaluateOnElementMesh.html}, note=[Accessed: 13-June-2026]}