# How to use ElementMeshInterpolation to interpolate to deformed mesh?

I'm solving a problem in solid mechanics, but I ran into problems when I tried to plot some stuff over the deformed mesh, because the plots are cut off. They end when the undeformed mesh ends.

ClearAll["Global*"]
Needs["NDSolveFEM"]

pars = <|"MaterialModel" -> "NeoHookeanIsotropic", "LameParameter" -> 10^6,
"ShearModulus" -> 5000, "ModelForm" -> "PlaneStress", "Thickness" -> 0.01,
"InitialStress" -> {$$MachineEpsilon,$$MachineEpsilon}|>;
vars = {{u[x, y], v[x, y]}, {x, y}};
\[CapitalOmega] = Rectangle[{0, 0}, {1, 1}];
mesh = ToElementMesh[\[CapitalOmega]];

pde = {SolidMechanicsPDEComponent[vars, pars] ==
SolidBoundaryLoadValue[x == 1, vars,
pars, <|"Pressure" -> {p, 0}|>],
SolidFixedCondition[x == 0, vars, pars]};
AbsoluteTiming[
displacement =
NDSolveValue[
pde /. p -> 3000, {u[x, y], v[x, y]}, {x, y} \[Element] mesh];]

deformedMesh =
ElementMeshDeformation[mesh, displacement, "ScalingFactor" -> 1];


Now comes the plotting part:

F = Map[Grad[#, {x, y}] &, displacement];
h = Function[{x, y}, F . {{1}, {0}} // Flatten // Evaluate];
StreamPlot[h[x, y], {x, y} \[Element] deformedMesh,
StreamPoints -> Coarse, StreamScale -> None,
StreamColorFunction -> None, PlotRange -> All]


This gives the following result. In the background you can see the deformed mesh, but the lines are cut off at 1. They are plotted only over the undeformed mesh.

Same thing happens when I try to plot norm of Cauchy stress.

strain = SolidMechanicsStrain[vars, pars, displacement];
cauchyStress = SolidMechanicsStress[vars, pars, strain, displacement];
cauchyNorm = Norm[cauchyStress, "Frobenius"];
ContourPlot[cauchyNorm, {x, y} \[Element] deformedMesh, PlotLegends -> Automatic]


The plot is also cut off.

I tried to use ElementMeshInterpolation to interpolate to the deformed mesh. I tried to follow the examples in documentation:

values = Function[{x, y}, h] @@@ mesh["Coordinates"];
if = ElementMeshInterpolation[{mesh}, values];


But this results in error "Interpolation on unstructured grids is currently only supported for
machine numbers."

• Have look in the solid mechanics tutorial, there are examples showing how to do this in the introduction art example section. You'd need to map the displacement to the deformed mesh. Commented Nov 5, 2022 at 6:18
• Actually, all functions defined on $\Omega$, not on deformedMesh. It is why StreamPlot and ContourPlot cat off picture. We can use VectorDisplacementPlot to show h on deformedMesh. Commented Nov 5, 2022 at 16:42

You can use:

deformedH =
Partition[
ElementMeshInterpolation[deformedMesh, #["ValuesOnGrid"]][x,
y] & /@ Flatten[F][[All, 0]], 2] . {1, 0};
StreamPlot[deformedH, {x, y} \[Element] deformedMesh,
StreamPoints -> Coarse, StreamScale -> None,
StreamColorFunction -> None, PlotRange -> All]


and

cauchyNorm2 = EvaluateOnElementMesh[{x, y}, cauchyNorm, mesh];
deformedCauchyNorm =
ElementMeshInterpolation[deformedMesh,
cauchyNorm2["ValuesOnGrid"]];
ContourPlot[deformedCauchyNorm[x, y], {x, y} \[Element] deformedMesh,
PlotLegends -> Automatic(*,PlotRange->All*)]


If by, cut off, you mean the re-scaled plot then you can specify PlotRange->All` to 'fix' that.

• Thank you, I was stuck on it for a long time. Commented Nov 8, 2022 at 13:15
• @lemurman Maybe, I should add more such examples in the documentation? Commented Nov 8, 2022 at 13:16
• I think it would be useful. Commented Nov 8, 2022 at 16:43