# representation of custom deformation on a meshgrid

I am trying to represent 2D deformations on a rectangular grid. In Mathematica 10, there is a method to solve the elastic differential equations and then represent the deformation as presented here:

https://www.wolfram.com/mathematica/new-in-10/pdes-and-finite-elements/compute-a-plane-strain-deformation.html

Now I only want to visualize a deformation I actually have an analytic functional form for, i.e. I do have the functions u[x_,y_] and v[x_,y_] which represent the deformation in the x and y directions, however I cannot get it working. I thought that the PDE solver NDSolveValue returns some InterpolatingFunction so I tried to use an InterpolatingFunction type of object for u and v (which, I know it sounds stupid), but even doing so, the u["ElementMesh"] returns None so I'm completely stuck in here. Any help would be appreciated!

Bonus question: is it possible to color the mesh according to the deformation (by defining some color scale, for instance)?

You have to create your own mesh and you have to convert your u and v to mesh interpolations. (In the example in the documentation, NDSolveValue does this itself in constructing uif, vif.)

Example:

Needs["NDSolveFEM"]

mesh = ToElementMesh[FullRegion[2], {{0, 5}, {0, 1}}];

u = Function[{x, y}, x (y - 0.5)/25];
v = Function[{x, y}, -x^2/50];

uif = ElementMeshInterpolation[{mesh}, u @@@ mesh["Coordinates"]];
vif = ElementMeshInterpolation[{mesh}, v @@@ mesh["Coordinates"]];

ElementMeshDeformation[mesh, {uif, vif}][
"Wireframe"["ElementMeshDirective" -> Directive[EdgeForm[Red], FaceForm[]]]]


Update 1 - Thanks to user21 for the help with how to use ElementMeshToGraphicsComplex to process the deformed mesh.

Coloring by the norm of {u, v}, via post-processing:

nm = ElementMeshDeformation[mesh, {uif, vif}];

Show[
Graphics[
ElementMeshToGraphicsComplex[nm, All,
VertexColors -> (ColorData["Rainbow"] /@
Rescale[Norm[{u @@ #, v @@ #}] & /@ mesh["Coordinates"]])]],
nm["Wireframe"]
]


(The graphics consists of a single Polygon object inside a GraphicsComplex. This is the easiest way to get a coloring that depends on position coordinates.)

Update 2 - Various approaches to coloring.

For a function of the coordinates, use the following form for VertexColors:

colorscalar[x_, y_] := Norm[{u[x, y], v[x, y]}];
VertexColors -> (ColorData["Rainbow"] /@ Rescale[colorscalar @@@ mesh["Coordinates"]])


For a function of a point, use the following form for VertexColors:

colorscalar[{x_, y_}] := Norm[{u[x, y], v[x, y]}];
VertexColors -> (ColorData["Rainbow"] /@ Rescale[colorscalar /@ mesh["Coordinates"]])

• Awesome, it works like a charm, this is exactly what I needed! Thank you very much! – botond Dec 16 '14 at 13:00
• Any comments on the coloring?... – botond Dec 16 '14 at 13:01
• nm = ElementMeshDeformation[mesh, {uif, vif}] will give you a new mesh. You could then use Graphics[ElementMeshToGraphicsComplex[nm, All, VertexColors -> (ColorData["Rainbow"] /@ Rescale[Norm[{u @@ #, v @@ #}] & /@ nm["Coordinates"]])]] to make the conversion. – user21 Dec 16 '14 at 14:04
• @Botond You're welcome. I'm thinking that the coordinates used for the coloring ought to be the original ones mesh["Coordinates"] instead of the deformed ones nm["Coordinates"]. It makes an imperceptible difference, but doesn't using mesh seem the correct way to you? – Michael E2 Dec 16 '14 at 14:25
• @MichaelE2, I added some documentation of ElementMeshToGraphoicsComplex and a variation of this example. It's going to be available in a future version. Thanks! – user21 Dec 16 '14 at 15:55