Evaluate function at point - geometry.compute_first_entity_collision doesn't exist

Hi!

Following this post, I’m trying to evaluate a function I found solving a non-linear problem with dolfinx. However, when I do

tree = geometry.BoundingBoxTree(domain, 2)
cells = geometry.compute_first_entity_collision(tree, domain, x0)
m.eval(x0, cells)

I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [27], in <cell line: 3>()
      1 x0 = [0,np.pi]
      2 tree = geometry.BoundingBoxTree(domain, 2)
----> 3 cells = geometry.compute_first_entity_collision(tree, domain, x0)
      4 m.eval(x0, cells)

AttributeError: module 'dolfinx.geometry' has no attribute 'compute_first_entity_collision'

Indeed, geometry.compute_first_entity_collision doesn’t seem to exist. Any suggestions?
Thanks!

There is a c++ function for this, namely: compute_first_colliding_cell (dolfinx/utils.cpp at c56d30b23f2c2ce99e8c145d3aeb43aff5d6d229 · FEniCS/dolfinx · GitHub)
You could expose that to the python layer, or go along the route shown in the tutorial:
Implementation — FEniCSx tutorial

1 Like

Hi @dokken, thanks for your reply. I’ve tried implementing the recipe of the tutorial but I only get an empty list. Could you please help me identify the problem?

points = np.array([[0.1, np.pi*1.7], [0.2, np.pi*1.2], [0.03, np.pi]])
m_values = []

tree = geometry.BoundingBoxTree(domain, domain.topology.dim)

cells = []
points_on_proc = []
cell_candidates = geometry.compute_collisions(tree, points.T) # Find cells whose bounding-box collide with the the points
colliding_cells = geometry.compute_colliding_cells(domain, cell_candidates, points.T) # Choose one of the cells that contains the point
for i, point in enumerate(points.T):
    if len(colliding_cells.links(i))>0:
        points_on_proc.append(point)
        cells.append(colliding_cells.links(i)[0])

points_on_proc = np.array(points_on_proc, dtype=np.float64)
m_values = m.eval(points_on_proc, cells)
print(m_values)

I already found the problem – in the way I’m defining the points, I don’t need to transpose the array.