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
x
inmesh
using thecompute_first_entity_collision
method ofmesh.bounding_box_tree()
. - Use some DoF maps for
V
andV.element().evaluate_basis
to 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 tox
on the cell (where the shape function goes to zero along a line throughx
in 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.