I don’t know of any built-in functionality for this. I did think of a somewhat-involved workaround:
- Define a CG1 scalar space,
V = FunctionSpace(mesh,"CG",1). - Find the index of the closest cell to
xinmeshusing thecompute_first_entity_collisionmethod ofmesh.bounding_box_tree(). - Use some DoF maps for
VandV.element().evaluate_basisto evaluate all shape functions on that cell. The shape function that is negative is the one whose node is the vertex “opposite”x. - Get that shape function’s gradient with
V.element().evaluate_basis_derivatives. - Given
x, the shape function evaluation atx, and the shape function gradient, you can do some algebra to calculate the closest point toxon the cell (where the shape function goes to zero along a line throughxin the direction of the gradient).
For an example of how to use the basis function evaluation functions, you might take a look at this discussion.