]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Get closest vertex to cell.
authorLuca Heltai <luca.heltai@sissa.it>
Sat, 12 Aug 2017 21:52:49 +0000 (15:52 -0600)
committerLuca Heltai <luca.heltai@sissa.it>
Mon, 14 Aug 2017 19:09:00 +0000 (13:09 -0600)
include/deal.II/grid/grid_tools.h
source/grid/grid_tools.cc

index 1a2532d306da476aa6ea7a15a0af04abf0f1ead6..32d3bc5245192cfc87ae138f8ef479c23ebd3709 100644 (file)
@@ -1023,6 +1023,20 @@ namespace GridTools
   std::vector<std::set<typename Triangulation<dim,spacedim>::active_cell_iterator> >
   vertex_to_cell_map(const Triangulation<dim,spacedim> &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 <int dim, int spacedim>
+  unsigned int
+  get_closest_vertex_of_cell(const typename Triangulation<dim,spacedim>::active_cell_iterator &cell,
+                             const Point<spacedim> &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
index 85a9194788bcafc0a4e8c2bb16855efd4a209db6..6c9e9d5a387cfd93c19cd0c5c9e06a9fd242f6e6 100644 (file)
@@ -1460,6 +1460,28 @@ next_cell:
 
 
 
+  template <int dim, int spacedim>
+  unsigned int
+  get_closest_vertex_of_cell(const typename Triangulation<dim,spacedim>::active_cell_iterator &cell,
+                             const Point<spacedim> &position)
+  {
+    double minimum_distance = std::numeric_limits<double>::max();
+    unsigned int closest_vertex = numbers::invalid_unsigned_int;
+
+    for (unsigned int v=0; v<GeometryInfo<dim>::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 <int dim, int spacedim>
   std::pair<typename hp::DoFHandler<dim,spacedim>::active_cell_iterator, Point<dim> >
   find_active_cell_around_point (const hp::MappingCollection<dim,spacedim>   &mapping,

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.