This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

evaluation of function at mesh coordinates

+1 vote

In Section 1.6 of the FEniCS book, there is a comparison between the calculated value u and the exact solution u0. In particular u0(coor[i]) returns the value of u0 at vertex with global number i.

If

V = FunctionSpace(mesh, 'Lagrange', 1)
u = Function(V)

why is

u.vector().array()[i] != u(mesh.coordinates()[i])?

From running an example I see that the values are permuted.

And does

u0(mesh.coordinates()[i])

gives the correctly ordered result because u0 is an Expression?

Is this related to the ordering of the degrees of freedom as in http://fenicsproject.org/qa/207/how-to-interpolate-data-at-vertices-of-3d-cells
http://fenicsproject.org/qa/465/interpolate-function-given-matrix-on-finite-element-basis?

asked Jul 11, 2013 by michele.zaffalon FEniCS Novice (450 points)
edited Jul 11, 2013 by michele.zaffalon

As you have seen from the two linked questions you provide, the ordering of dofs no longer coincides with the vertices. This is the explanation for why you get different answers with DOLFIN version 1.1 and larger compared to DOLFIN 1.0, which the book example uses. Also could you please rephrase your question to a proper question? Right now it is an observation.

Do you mean that

u(mesh.coordinates()[i])

is the correct approach?

why is
u.vector().array()[i] != u(mesh.coordinates()[i])?

The left hand side picks the ith degree of freedom, and the right hand side evaluates the Function at coordinate i. These are not the same as the linked questions mentions.

Wouldn't it be best to mention this change between DOLFIN version >=1.1 and 1.0 in the tutorial?

Certainly it would. It is also missing in 1.1 release notes. You could file a bug to FEniCS web and possibly also FEniCS book as some manuals are generated by its source.

...