]> https://gitweb.dealii.org/ - dealii.git/commitdiff
KDTree support.
authorLuca Heltai <luca.heltai@sissa.it>
Thu, 14 Sep 2017 17:54:25 +0000 (19:54 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Thu, 14 Sep 2017 17:54:25 +0000 (19:54 +0200)
include/deal.II/grid/tria_info_cache.h
include/deal.II/grid/tria_info_cache_flags.h
source/grid/tria_info_cache.cc

index 5ef199d1f8dec73f1b0a317c506410dbc24a0602..56c0fac18587340aae5fce540cbb63262274ee53 100644 (file)
@@ -28,6 +28,8 @@
 #include <deal.II/grid/tria_info_cache_flags.h>
 #include <deal.II/fe/mapping_q1.h>
 
+#include <deal.II/numerics/kdtree.h>
+
 #include <cmath>
 
 DEAL_II_NAMESPACE_OPEN
@@ -103,6 +105,14 @@ public:
   const std::vector<std::vector<Tensor<1,spacedim>>>
   &get_vertex_to_cell_centers_directions() const;
 
+#ifdef DEAL_II_WITH_NANOFLANN
+  /**
+   * Return the cached vertex_kdtree object, constructed with the vertices of
+   * the stored triangulation.
+   */
+  const KDTree<spacedim> &get_vertex_kdtree() const;
+#endif
+
   /**
    * Exception for uninitialized cache fields.
    */
@@ -117,7 +127,7 @@ private:
   /**
    * A pointer to the Triangulation.
    */
-  SmartPointer<Triangulation<dim,spacedim>,
+  SmartPointer<const Triangulation<dim,spacedim>,
                TriangulationInfoCache<dim,spacedim>> tria;
 
   /**
@@ -128,7 +138,7 @@ private:
   /**
    * Mapping to use when computing on the Triangulation.
    */
-  SmartPointer<Mapping<dim,spacedim>,
+  SmartPointer<const Mapping<dim,spacedim>,
                TriangulationInfoCache<dim,spacedim>> mapping;
 
 
@@ -143,6 +153,13 @@ private:
    * GridTools::vertex_to_cell_centers_directions.
    */
   std::vector<std::vector<Tensor<1,spacedim>>> vertex_to_cell_centers;
+
+#ifdef DEAL_II_WITH_NANOFLANN
+  /**
+   * A KDTree object constructed with the vertices of the triangulation.
+   */
+  KDTree<spacedim> vertex_kdtree;
+#endif
 };
 
 DEAL_II_NAMESPACE_CLOSE
index 165d735c68794e9cacb0d64272b7f84049a73422..0c8a4202e0776e0f98bcc3ad66d696ec0ac8eefc 100644 (file)
@@ -47,6 +47,13 @@ enum TriangulationInfoCacheFlags
    * GridTools::vertex_to_cell_centers_directions()
    */
   cache_vertex_to_cell_centers_directions = cache_vertex_to_cell_map | 0x0002,
+
+#ifdef DEAL_II_WITH_NANOFLANN
+  /**
+   * Cache a KDTree object, initialized with the vertices of the Triangulation.
+   */
+  cache_vertex_kdtree = 0x0004,
+#endif
 };
 
 
@@ -62,6 +69,9 @@ StreamType &operator << (StreamType &s, TriangulationInfoCacheFlags u)
   s << " TriangulationInfoCacheFlags";
   if (u & cache_vertex_to_cell_map)                 s << "|vertex_to_cell_map";
   if (u & cache_vertex_to_cell_centers_directions)  s << "|vertex_to_cells_centers_directions";
+#ifdef DEAL_II_WITH_NANOFLANN
+  if (u & cache_vertex_kdtree)                      s << "|vertex_kdtree";
+#endif
   return s;
 }
 
index dc975f59af63be4a7ae12dcf4ce13f40c5349034..b68aab102f8ae435478b6434ab3040b71b4aa265 100644 (file)
@@ -45,6 +45,11 @@ void TriangulationInfoCache<dim,spacedim>::update(bool topology_is_unchanged)
     {
       if (cache_vertex_to_cell_map & flags)
         vertex_to_cells = GridTools::vertex_to_cell_map(*tria);
+
+#ifdef DEAL_II_WITH_NANOFLANN
+      if (cache_vertex_kdtree & flags)
+        vertex_kdtree.set_points(tria->get_vertices());
+#endif
     }
 
   if (cache_vertex_to_cell_centers_directions & flags)
@@ -74,4 +79,19 @@ TriangulationInfoCache<dim,spacedim>::get_vertex_to_cell_centers_directions() co
   return vertex_to_cell_centers;
 }
 
+
+
+#ifdef DEAL_II_WITH_NANOFLANN
+template<int dim, int spacedim>
+const KDTree<spacedim> &TriangulationInfoCache<dim,spacedim>::get_vertex_kdtree() const
+{
+  Assert(flags & cache_vertex_kdtree,
+         ExcAccessToInvalidCacheObject(cache_vertex_kdtree, flags));
+  return vertex_kdtree;
+}
+#endif
+
+#include "tria_info_cache.inst"
+
 DEAL_II_NAMESPACE_CLOSE
+

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.