Given an coordinate of point p, how to define which cell it is in?

One way that comes to my mind is to iterate through cells, and use vertices coordinates to compute if the given coordinate of p, but the implementation is different for different cell types, and will need the correct continuous order of vertices of a cell. Is there any more convenient way? It surely will be necessary if I want to decide which element to do integration when applying boundary forces.

There are functions such as compute_closest_entity that uses bounding box trees for fast searching. This works even if the point is not in any cell.

There are other collision detection algorithms in DOLFIN/DOLFINx as well, but as you haven’t specified what version you are using I won’t go into details

Oh, sorry, I am using Dolfin. What function could I use if I want precise judgement of whether a point is inside an element?

See; How to determine whether a point belongs to a mesh cell - #2 by dokken

1 Like