This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Determine if point belongs to any cell in submesh

0 votes

I have a mesh that has been divided in two submeshes. For a given point, I need to determine which of the two submeshes the point belongs to. How can this be done in Fenics 1.3?

It appears that Mesh.h does not specify intersected_cell, which otherwise would have been useful. At least, the lines:

    Point p(0.0,0.0,0.0);
    int cid = cmesh.intersected_cell(p);

gave the compilation error:

main.cpp:592:25: error: ‘const class dolfin::Mesh’ has no member named ‘intersected_cell’
asked Aug 15, 2014 by BB FEniCS Novice (710 points)

1 Answer

+1 vote
 
Best answer

Hi, for collisions you should use BoundingBoxTree. To get cell index of a cell that contains given point consider

#include <dolfin.h>

int main()
{
  Point P_in(0.1, 0.9), P_out(2, 2);

  UnitSquareMesh mesh(2, 2);
  boost::shared_ptr<BoundingBoxTree> tree = mesh.bounding_box_tree();
  //std::shared_ptr for versions newer than 1.3.0

  // build tree for cell collisions
  tree->build(mesh, 2);

  // get the index, -1 if no collision
  info("cell id = %d", tree->compute_first_collision(P_in));
  info("cell id = %d", tree->compute_first_collision(P_out));

  return 0;
}
answered Aug 15, 2014 by MiroK FEniCS Expert (80,920 points)
selected Aug 15, 2014 by BB
...