Compute distance to surface for all mesh elements

Hi!

Is there some FEniCS function that enables to compute closest distance-to-surface for all elements (tetrahedrons in my case)?
The idea is to make some terms of the variational form depend on the distance-to-surface, for instance the forces.
e.g. with the Poisson equation:
a = dot(grad(u), grad(v))*dx
L = f(distance-to-surface)vdx

Many thanks,
Anne

How is your surface defined (parameteric? is it a plane surface?)?

If it can be defined as the convex hull of a set of points, you can use:

which is exposed to python as

Many thanks for your quick answer! I am using a sphere and an ellipsoid.

So the mesh is a sphere and the surface is made by an ellipsoid?

No, sorry, I meant either a sphere or an ellipsoid

You can get every dof-coordinate in your function space by calling
V.tabulate_dof_coordinates().
Then for each of these, you can use any library that accepts a numpy array of coordinates to compute the distance from your analytical shape.

You can then pass these in to a function v in V by calling v.vector()[:] = output_of_distance algorithm.

Consider also computing an appoximation of the Eikonal equation for use in your source function.

1 Like