]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fixed compilation issue and test.
authorLuca Heltai <luca.heltai@sissa.it>
Thu, 14 Sep 2017 17:55:18 +0000 (19:55 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Thu, 14 Sep 2017 17:55:18 +0000 (19:55 +0200)
doc/news/changes/major/20170914LucaHeltai [new file with mode: 0644]
include/deal.II/grid/tria_info_cache.h
source/grid/tria_info_cache.cc
tests/grid/tria_info_cache_01.cc [new file with mode: 0644]
tests/grid/tria_info_cache_01.output [new file with mode: 0644]

diff --git a/doc/news/changes/major/20170914LucaHeltai b/doc/news/changes/major/20170914LucaHeltai
new file mode 100644 (file)
index 0000000..21f9823
--- /dev/null
@@ -0,0 +1,6 @@
+New: A new TriangulationInfoCache class
+allows caching of some expensive data of the 
+Triangulation class, computed generally using 
+functions in GridTools.
+<br>
+(Luca Heltai, 2017/09/14)
index 56c0fac18587340aae5fce540cbb63262274ee53..26ddfcbd9459a4a6dab50876369747ee369780ef 100644 (file)
@@ -30,6 +30,8 @@
 
 #include <deal.II/numerics/kdtree.h>
 
+#include <boost/signals2.hpp>
+
 #include <cmath>
 
 DEAL_II_NAMESPACE_OPEN
@@ -55,7 +57,7 @@ DEAL_II_NAMESPACE_OPEN
  *
  * @author Luca Heltai, 2017.
  */
-template <int dim, int spacedim>
+template <int dim, int spacedim = dim>
 class TriangulationInfoCache : public Subscriptor
 {
 public:
@@ -74,6 +76,8 @@ public:
                           const TriangulationInfoCacheFlags &flags = cache_nothing,
                           const Mapping<dim,spacedim> &mapping=StaticMappingQ1<dim,spacedim>::mapping);
 
+  ~TriangulationInfoCache();
+
   /**
    * Loop over all TriangulationInfoCacheFlags and rebuilds the specific data
    * structure.
@@ -160,6 +164,11 @@ private:
    */
   KDTree<spacedim> vertex_kdtree;
 #endif
+
+  /**
+   * Storage for the status of the triangulation signal.
+   */
+  boost::signals2::connection tria_signal;
 };
 
 DEAL_II_NAMESPACE_CLOSE
index b68aab102f8ae435478b6434ab3040b71b4aa265..8a150a861ad11f1a5c857e9b90bf072111dd2962 100644 (file)
@@ -27,7 +27,7 @@ TriangulationInfoCache<dim,spacedim>::TriangulationInfoCache(
   flags(flags),
   mapping(&mapping)
 {
-  tria->signals.any_change.connect([&]()
+  tria_signal = tria.signals.any_change.connect([&]()
   {
     update();
   });
@@ -36,11 +36,29 @@ TriangulationInfoCache<dim,spacedim>::TriangulationInfoCache(
     update();
 }
 
+template<int dim, int spacedim>
+TriangulationInfoCache<dim,spacedim>::~TriangulationInfoCache()
+{
+  // Make sure that the signals that was attached to the triangulation
+  // is removed here.
+  if (tria_signal.connected())
+    tria_signal.disconnect();
+}
+
 
 
 template<int dim, int spacedim>
 void TriangulationInfoCache<dim,spacedim>::update(bool topology_is_unchanged)
 {
+  // If the triangulation is empty, just clear everything.
+  if (tria->n_active_cells() == 0)
+    {
+      vertex_to_cells.clear();
+      vertex_to_cell_centers.clear();
+      vertex_kdtree.set_points(tria->get_vertices());
+      return;
+    }
+
   if (topology_is_unchanged == false)
     {
       if (cache_vertex_to_cell_map & flags)
@@ -55,6 +73,7 @@ void TriangulationInfoCache<dim,spacedim>::update(bool topology_is_unchanged)
   if (cache_vertex_to_cell_centers_directions & flags)
     vertex_to_cell_centers =
       GridTools::vertex_to_cell_centers_directions(*tria, vertex_to_cells);
+
 }
 
 
diff --git a/tests/grid/tria_info_cache_01.cc b/tests/grid/tria_info_cache_01.cc
new file mode 100644 (file)
index 0000000..78d5e2d
--- /dev/null
@@ -0,0 +1,59 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2001 - 2017 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+// Validate tria_info_cache
+
+#include "../tests.h"
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria_info_cache.h>
+
+
+template <int dim, int spacedim>
+void test ()
+{
+  deallog << "dim = " << dim
+          << ", spacedim = " << spacedim << std::endl;
+
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria);
+  tria.refine_global(1);
+
+  TriangulationInfoCache<dim> cache(tria, cache_vertex_to_cell_map);
+
+  auto m = cache.get_vertex_to_cell_map();
+
+  unsigned int i=0;
+  for (auto &v : m)
+    {
+      for (auto &c : v)
+        deallog << "Vertex " << i << ", cell " << c << std::endl;
+      ++i;
+    }
+}
+
+
+int main ()
+{
+  initlog();
+
+  test<1,1> ();
+  test<1,2>();
+  test<2,2> ();
+  test<2,3> ();
+  test<3,3> ();
+
+  return 0;
+}
diff --git a/tests/grid/tria_info_cache_01.output b/tests/grid/tria_info_cache_01.output
new file mode 100644 (file)
index 0000000..560deb1
--- /dev/null
@@ -0,0 +1,110 @@
+
+DEAL::dim = 1, spacedim = 1
+DEAL::Vertex 0, cell 1.0
+DEAL::Vertex 1, cell 1.1
+DEAL::Vertex 2, cell 1.0
+DEAL::Vertex 2, cell 1.1
+DEAL::dim = 1, spacedim = 2
+DEAL::Vertex 0, cell 1.0
+DEAL::Vertex 1, cell 1.1
+DEAL::Vertex 2, cell 1.0
+DEAL::Vertex 2, cell 1.1
+DEAL::dim = 2, spacedim = 2
+DEAL::Vertex 0, cell 1.0
+DEAL::Vertex 1, cell 1.1
+DEAL::Vertex 2, cell 1.2
+DEAL::Vertex 3, cell 1.3
+DEAL::Vertex 4, cell 1.0
+DEAL::Vertex 4, cell 1.1
+DEAL::Vertex 5, cell 1.0
+DEAL::Vertex 5, cell 1.2
+DEAL::Vertex 6, cell 1.1
+DEAL::Vertex 6, cell 1.3
+DEAL::Vertex 7, cell 1.2
+DEAL::Vertex 7, cell 1.3
+DEAL::Vertex 8, cell 1.0
+DEAL::Vertex 8, cell 1.1
+DEAL::Vertex 8, cell 1.2
+DEAL::Vertex 8, cell 1.3
+DEAL::dim = 2, spacedim = 3
+DEAL::Vertex 0, cell 1.0
+DEAL::Vertex 1, cell 1.1
+DEAL::Vertex 2, cell 1.2
+DEAL::Vertex 3, cell 1.3
+DEAL::Vertex 4, cell 1.0
+DEAL::Vertex 4, cell 1.1
+DEAL::Vertex 5, cell 1.0
+DEAL::Vertex 5, cell 1.2
+DEAL::Vertex 6, cell 1.1
+DEAL::Vertex 6, cell 1.3
+DEAL::Vertex 7, cell 1.2
+DEAL::Vertex 7, cell 1.3
+DEAL::Vertex 8, cell 1.0
+DEAL::Vertex 8, cell 1.1
+DEAL::Vertex 8, cell 1.2
+DEAL::Vertex 8, cell 1.3
+DEAL::dim = 3, spacedim = 3
+DEAL::Vertex 0, cell 1.0
+DEAL::Vertex 1, cell 1.1
+DEAL::Vertex 2, cell 1.2
+DEAL::Vertex 3, cell 1.3
+DEAL::Vertex 4, cell 1.4
+DEAL::Vertex 5, cell 1.5
+DEAL::Vertex 6, cell 1.6
+DEAL::Vertex 7, cell 1.7
+DEAL::Vertex 8, cell 1.0
+DEAL::Vertex 8, cell 1.1
+DEAL::Vertex 9, cell 1.0
+DEAL::Vertex 9, cell 1.2
+DEAL::Vertex 10, cell 1.0
+DEAL::Vertex 10, cell 1.4
+DEAL::Vertex 11, cell 1.1
+DEAL::Vertex 11, cell 1.3
+DEAL::Vertex 12, cell 1.1
+DEAL::Vertex 12, cell 1.5
+DEAL::Vertex 13, cell 1.2
+DEAL::Vertex 13, cell 1.3
+DEAL::Vertex 14, cell 1.2
+DEAL::Vertex 14, cell 1.6
+DEAL::Vertex 15, cell 1.3
+DEAL::Vertex 15, cell 1.7
+DEAL::Vertex 16, cell 1.4
+DEAL::Vertex 16, cell 1.5
+DEAL::Vertex 17, cell 1.4
+DEAL::Vertex 17, cell 1.6
+DEAL::Vertex 18, cell 1.5
+DEAL::Vertex 18, cell 1.7
+DEAL::Vertex 19, cell 1.6
+DEAL::Vertex 19, cell 1.7
+DEAL::Vertex 20, cell 1.0
+DEAL::Vertex 20, cell 1.1
+DEAL::Vertex 20, cell 1.4
+DEAL::Vertex 20, cell 1.5
+DEAL::Vertex 21, cell 1.0
+DEAL::Vertex 21, cell 1.1
+DEAL::Vertex 21, cell 1.2
+DEAL::Vertex 21, cell 1.3
+DEAL::Vertex 22, cell 1.0
+DEAL::Vertex 22, cell 1.2
+DEAL::Vertex 22, cell 1.4
+DEAL::Vertex 22, cell 1.6
+DEAL::Vertex 23, cell 1.1
+DEAL::Vertex 23, cell 1.3
+DEAL::Vertex 23, cell 1.5
+DEAL::Vertex 23, cell 1.7
+DEAL::Vertex 24, cell 1.2
+DEAL::Vertex 24, cell 1.3
+DEAL::Vertex 24, cell 1.6
+DEAL::Vertex 24, cell 1.7
+DEAL::Vertex 25, cell 1.4
+DEAL::Vertex 25, cell 1.5
+DEAL::Vertex 25, cell 1.6
+DEAL::Vertex 25, cell 1.7
+DEAL::Vertex 26, cell 1.0
+DEAL::Vertex 26, cell 1.1
+DEAL::Vertex 26, cell 1.2
+DEAL::Vertex 26, cell 1.3
+DEAL::Vertex 26, cell 1.4
+DEAL::Vertex 26, cell 1.5
+DEAL::Vertex 26, cell 1.6
+DEAL::Vertex 26, cell 1.7

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.