Define a function based on the distance of the mesh points to the boundary

Hi,

I need to define a function in 2D as follows:

f(x) = \begin{cases} 1 \qquad if \qquad dist(x,boundary) \leq 0.5 \\ 0 \qquad if \qquad dist(x,boundary)>0.5\end{cases}

Is there an elegant way to do this, besides calculating the distance of x to all the boundary points and minimizing it for checking the conditions?

Consider approximating the solution of the Eikonal equation in your geometry. Using this you have a FE function indicating the signed distance to the boundary \forall \vec{x} in your domain.

1 Like

Thank you this really helped.