Any function to determine if the point is in the mesh

Dear all,

I am working on a viscoelasticity problem currently so the mesh is deformed due to the mechanics. Thus, some points might not be in the deformed mesh anymore. Is there any function can be used to check if the point is still in the deformed mesh or not?

Thanks in advance!
Alice

1 Like

You want to look at the FEniCS BoundingBoxTree class. It contains many functions that can be used for verifying whether a point is contained within a cell, mesh, etc.

1 Like

Hi Rudy,

Thanks for the reply and I did check the BoundingBoxTree class. It seems mesh.bounding_box_tree().compute_collision(Point) or mesh.bounding_box_tree().compute_first_collision(Point) are what I look for. However, the second one gave me only one result and the first one gave me several. One point, which is not nodal point or on the line segment should be only in one cell, right? What are the other results from mesh.bounding_box_tree().compute_collision(Point)?

Thanks in advance and kind regards,
Alice

Alice,

Compute_collision will compute the collision of all the entities with a Point while compute_first_collision will always return its first entry. Especially if a point is on an element edge this can be tricky. You may also want to compare with the Cell.contains(Point) tool to verify your understanding is correct. Check out the following code:

from dolfin import *

n = 4
Px = 0.5
Py = 0.5
mesh = UnitSquareMesh(n, n)
bbt = mesh.bounding_box_tree()
collisions = bbt.compute_collisions(Point(Px, Py))
collisions1st = bbt.compute_first_entity_collision(Point(Px, Py))
print("collisions: ", collisions)
print("collisions1st: ", collisions1st)

for cell in cells(mesh):
    contains = cell.contains(Point(Px, Py))
    print("Cell %i contains P: %s" % (cell.index(), contains))

import matplotlib.pyplot as plt
plot(mesh)
plt.plot(Px, Py, marker='x', markersize=5, color="red")
plt.show()
1 Like

Hi Rudy,

Thanks a lot for your kind help. Cell(mesh, cell_index).contains(Point) works in my code so I think that’s what I want :slight_smile:

Kind regards,
Alice