From: Luca Heltai Date: Sat, 12 Aug 2017 21:52:49 +0000 (-0600) Subject: Get closest vertex to cell. X-Git-Tag: v9.0.0-rc1~1252^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb0dd9604bcc9f74833b8485aa11dccbf235d4be;p=dealii.git Get closest vertex to cell. --- diff --git a/include/deal.II/grid/grid_tools.h b/include/deal.II/grid/grid_tools.h index 1a2532d306..32d3bc5245 100644 --- a/include/deal.II/grid/grid_tools.h +++ b/include/deal.II/grid/grid_tools.h @@ -1023,6 +1023,20 @@ namespace GridTools std::vector::active_cell_iterator> > vertex_to_cell_map(const Triangulation &triangulation); + /** + + + /** + * Returns the local vertex index of cell @p cell that is closest to + * the given location @p position. + * + * @author Rene Gassmoeller, Luca Heltai, 2017. + */ + template + unsigned int + get_closest_vertex_of_cell(const typename Triangulation::active_cell_iterator &cell, + const Point &position); + /** * Compute a globally unique index for each vertex and hanging node * associated with a locally owned active cell. The vertices of a ghost cell diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 85a9194788..6c9e9d5a38 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -1460,6 +1460,28 @@ next_cell: + template + unsigned int + get_closest_vertex_of_cell(const typename Triangulation::active_cell_iterator &cell, + const Point &position) + { + double minimum_distance = std::numeric_limits::max(); + unsigned int closest_vertex = numbers::invalid_unsigned_int; + + for (unsigned int v=0; v::vertices_per_cell; ++v) + { + const double vertex_distance = position.distance(cell->vertex(v)); + if (vertex_distance < minimum_distance) + { + closest_vertex = v; + minimum_distance = vertex_distance; + } + } + return closest_vertex; + } + + + template std::pair::active_cell_iterator, Point > find_active_cell_around_point (const hp::MappingCollection &mapping,