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

Get field value at mesh vertex

+1 vote

Hi,

I compute a displacement field u (defined as a VectorFunction on a 2D mesh), and i need to export its value at a given vertex (= geometrical point ?) of the 2D mesh. I was thinking of using :
u.vector()[vertex_no]
But I wonder how I can get the vertex_no corresponding to a given geometry ?

Thank you in advance !

asked Feb 5, 2015 by Claire L FEniCS User (2,120 points)

2 Answers

+3 votes
 
Best answer

If you just want to get the value at certain points, you can just do:

print u(x, y)

e.g. for every vertex in the mesh, you could do:

for v in vertices(mesh):
    x = v.point().x()
    y = v.point().y()
    print x, y, u(x, y)

Alternatively, you can look at get_vertex_values() and/or vertex_to_dof_map()

answered Feb 5, 2015 by chris_richardson FEniCS Expert (31,740 points)
selected Mar 9, 2015 by Claire L

Is there no other way to get the field values at each mesh coordinate? The tutorial book Solving PDEs in Minutes on p. 126 (see the box "Cheap vs expensive function evaluation") says that this is the most expensive way to access values. But, is there no other option?

0 votes

This link also might be helpful:
Evaluation of function at mesh coordinates

answered Feb 5, 2015 by puffin FEniCS Novice (440 points)
...