BoundingBoxTree.compute_closest_entity gives wrong distance in 2D

Issue #139 resolved
Tuomas Airaksinen created an issue

BoundingBoxTree.compute_closest_entity gives wrong distances in 2D. In 3D (at least for UnitCubeMesh) it seems to be OK.

Example:

from dolfin import *

mesh = UnitSquareMesh(4,4)
bmesh = BoundaryMesh(mesh, "exterior")

bbtree = BoundingBoxTree()
bbtree.build(bmesh)

vertex_distance_to_boundary = MeshFunction("double", mesh, 0)

for v_idx in xrange(mesh.num_vertices()):
    v = Vertex(mesh, v_idx)
    _, distance = bbtree.compute_closest_entity(v.point())
    vertex_distance_to_boundary[v_idx] = distance

plot(vertex_distance_to_boundary)
interactive()

In this example, distance to the boundary should be plotted.

see also http://fenicsproject.org/qa/1446/distance-to-boundary .

Comments (11)

  1. Prof Garth Wells

    Please modify your report to be explicit in what you expect the output to be, and what it actually is.

  2. Tuomas Airaksinen reporter

    I expect the value plotted to be distance to the boundary of the domain. I get the following:

  3. Tuomas Airaksinen reporter

    Ok, here.

    from dolfin import *
    
    mesh = UnitSquareMesh(4,4)
    bmesh = BoundaryMesh(mesh, "exterior")
    
    bbtree = BoundingBoxTree()
    bbtree.build(bmesh)
    
    vertex_distance_to_boundary = MeshFunction("double", mesh, 0)
    
    for v_idx in xrange(mesh.num_vertices()):
        v = Vertex(mesh, v_idx)
        p = [v.point()[i] for i in range(3)]
        _, distance = bbtree.compute_closest_entity(v.point())
        vertex_distance_to_boundary[v_idx] = distance
        print p, distance
    

    and result:

    [0.0, 0.0, 0.0] 0.0
    [0.25, 0.0, 0.0] 0.0
    [0.5, 0.0, 0.0] 0.0
    [0.75, 0.0, 0.0] 0.0
    [1.0, 0.0, 0.0] 0.0
    [0.0, 0.25, 0.0] 0.0
    [0.25, 0.25, 0.0] 0.0
    [0.5, 0.25, 0.0] 0.0
    [0.75, 0.25, 0.0] 0.0
    [1.0, 0.25, 0.0] 0.0
    [0.0, 0.5, 0.0] 0.0
    [0.25, 0.5, 0.0] 0.25
    [0.5, 0.5, 0.0] 0.0
    [0.75, 0.5, 0.0] 0.25
    [1.0, 0.5, 0.0] 0.0
    [0.0, 0.75, 0.0] 0.0
    [0.25, 0.75, 0.0] 0.0
    [0.5, 0.75, 0.0] 0.0
    [0.75, 0.75, 0.0] 0.0
    [1.0, 0.75, 0.0] 0.0
    [0.0, 1.0, 0.0] 0.0
    [0.25, 1.0, 0.0] 0.0
    [0.5, 1.0, 0.0] 0.0
    [0.75, 1.0, 0.0] 0.0
    [1.0, 1.0, 0.0] 0.0
    
  4. Anders Logg (Chalmers)

    Thanks. I'll look into this but let me just comment that this has not been tested at all (bounding box tree for surface embedded in higher dimensions), so it's not surprising that it breaks.

  5. Log in to comment