Compute displacement field from meshes

246 views
Skip to first unread message

Franco Milicchio

unread,
Apr 6, 2017, 10:11:49 AM4/6/17
to fenics-support
Dear all,

I have a pair of homologous meshes, i.e., there is a one-to-one correspondence between vertices as you can see in the attachments. 

How can I compute the displacement field for this very basic example?

Of course, computing the nodal displacements is more than trivial, but how can I tell fenics to interpolate them on the domain?

Thanks!

PS. Right now I am doing this in python.
quads0.xml
quads1.xml

Franco Milicchio

unread,
Apr 6, 2017, 11:20:30 AM4/6/17
to fenics-support
Something is wrong with my assumptions.

This is the code I am using:

from dolfin import *

mesh0 = Mesh("quads0.xml")
mesh1 = Mesh("quads1.xml")

c0 = mesh0.coordinates()
c1 = mesh1.coordinates()

values = c1 - c0

V = VectorFunctionSpace(mesh0, "Lagrange", 1)
u = Function(V)

print(u.vector())

u.vector()[:] = values.flatten()

dolfin.File("tmp/u.pvd", "compressed") << u


My test is done now on a simpler mesh, a pure shear on X, but the results are not what I was expected (see the attached picture, the deformed shape in paraview). In case, this is the XML file of the sheared quad:

<?xml version="1.0" encoding="UTF-8"?>

<dolfin xmlns:dolfin="http://www.fenics.org/dolfin/">
<mesh celltype="triangle" dim="2">
<vertices size="9">
<vertex index="0" x="0.0" y="0.0"/>
<vertex index="1" x="1.0" y="0.0"/>
<vertex index="2" x="2.0" y="0.0"/>
<vertex index="3" x="0.2" y="1.0"/>
<vertex index="4" x="1.2" y="1.0"/>
<vertex index="5" x="2.2" y="1.0"/>
<vertex index="6" x="0.4" y="2.0"/>
<vertex index="7" x="1.4" y="2.0"/>
<vertex index="8" x="2.4" y="2.0"/>
</vertices>
<cells size="8">
<triangle index="0" v0="0" v1="1" v2="3"/>
<triangle index="1" v0="1" v1="4" v2="3"/>
<triangle index="2" v0="1" v1="2" v2="4"/>
<triangle index="3" v0="2" v1="5" v2="4"/>
<triangle index="4" v0="4" v1="5" v2="7"/>
<triangle index="5" v0="5" v1="8" v2="7"/>
<triangle index="6" v0="3" v1="4" v2="6"/>
<triangle index="7" v0="4" v1="7" v2="6"/>
</cells>
</mesh>
</dolfin>

Any hints?


Screen Shot 2017-04-06 at 5.16.04pm.png

Jan Blechta

unread,
Apr 6, 2017, 1:28:19 PM4/6/17
to Franco Milicchio, fenics-support
You can use functions get/set_coordinates, ALE::move to manipulate
mesh geometries as Functions.

Note that DOLFIN does not support having two meshes with different
geometries and shared topologies, and in turn shared dofmaps. So I'd
recommend avoiding a use of more mesh objects resulting in duplicating
heavy data like mesh topologies and dofmaps, and preferred using a
single mesh and using above manipulations.

Jan

Franco Milicchio

unread,
Apr 7, 2017, 6:13:21 AM4/7/17
to fenics-support


On Thursday, April 6, 2017 at 7:28:19 PM UTC+2, Jan Blechta wrote:
You can use functions get/set_coordinates, ALE::move to manipulate
mesh geometries as Functions.

Note that DOLFIN does not support having two meshes with different
geometries and shared topologies, and in turn shared dofmaps. So I'd
recommend avoiding a use of more mesh objects resulting in duplicating
heavy data like mesh topologies and dofmaps, and preferred using a
single mesh and using above manipulations.

Thanks, Jan.

Ok, I can preprocess the meshes and computing just the nodal displacement. The above code was just a very simple example.

 However, even with this I am probably missing something: the displacement field seems to me wrong.

What could be happening here? Does the mesh need to be in a particular order? Or is the code wrong?

Thanks!
    Franco

Franco Milicchio

unread,
Apr 7, 2017, 11:31:16 AM4/7/17
to fenics-support
Apparently, I cannot even rely on the order of vertices.

I cannot see how I could construct a displacement field from nodal values, or better, from point values. The documentation I find isn't applicable to the current Fenics version, for instance the following code that I found on Q&A does not execute:

vertex_to_dof_map = V.dofmap().vertex_to_dof_map(mesh0)
dof_to_vertex_map = V.dofmap().dof_to_vertex_map(mesh0)
dofs_at_vertices = u.vector()[dof_to_vertex_map]

I found two functions as in the following lines (the corresponding functions of the above calls, probably), but I cannot understand how I could use this, I thought the second one would be composed only of vertex indices, but apparently not (for a 9-nodes example as in this mesh, I have values equal to [16 17 10 11 14 15  4  5  8  9 12 13  2  3  6  7  0  1] which has DOF index span).

vd0 = dolfin.cpp.fem.vertex_to_dof_map(V)
dv0 = dolfin.cpp.fem.dof_to_vertex_map(V) 

It could be extremely useful to get the DOFs associated to a particular in a mesh, but I sincerely cannot find any function for this, but maybe I overlooked something.

Any hints would be extremely appreciated...
    Franco

Kristian

unread,
Apr 7, 2017, 1:03:12 PM4/7/17
to Franco Milicchio, fenics-support

try

dof2vtx = vertex_to_dof_map(V)

--
You received this message because you are subscribed to the Google Groups "fenics-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fenics-suppor...@googlegroups.com.
To post to this group, send email to fenics-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fenics-support/70dea19c-c972-43ab-9e25-67ad9d47b571%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Franco Milicchio

unread,
Apr 7, 2017, 3:12:58 PM4/7/17
to fenics-support


On Friday, April 7, 2017 at 7:03:12 PM UTC+2, Kristian Jensen wrote:

try

dof2vtx = vertex_to_dof_map(V)




Thanks, Kristian. How should I interpret these results? The resulting array is this

[ 0  9  1 10  2 11  3 12  4 13  5 14  6 15  7 16  8 17]

Is it to be interpreted as an ordered list of dofs associated with each vertex, in order? Something like

[ dof_x(v0) dof_y(v0) dof_x(v1) dof_y(v1) ... dof_x(vn) dof_y(vn) ]

Is this the correct interpretation? The docs do not help me very much: "std::vector<dolfin::la_index> dolfin::vertex_to_dof_map(const FunctionSpace &space)
Return a map between vertex indices and dof indices Only works for FunctionSpace with dofs exclusively on vertices. For mixed FunctionSpaces dof index is offset with the number of dofs per vertex."

Thank you!
    Franco

Jan Blechta

unread,
Apr 10, 2017, 5:54:15 AM4/10/17
to Franco Milicchio, fenics-support
On Fri, 7 Apr 2017 12:12:58 -0700 (PDT)
Franco Milicchio <franco.m...@gmail.com> wrote:

> On Friday, April 7, 2017 at 7:03:12 PM UTC+2, Kristian Jensen wrote:
> >
> > try
> >
> > dof2vtx = vertex_to_dof_map(V)
> >
> >
>
> Thanks, Kristian. How should I interpret these results? The resulting
> array is this
>
> [ 0 9 1 10 2 11 3 12 4 13 5 14 6 15 7 16 8 17]
>
> Is it to be interpreted as an ordered list of dofs associated with
> each vertex, in order? Something like

Yes,

Jan

Franco Milicchio

unread,
Apr 10, 2017, 10:07:32 AM4/10/17
to fenics-support
Thanks, Jan, it works nicely.
Reply all
Reply to author
Forward
0 new messages