From d8b075a5dd7ef5c29dd504d6f0692172ce3eca27 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Thu, 14 Sep 2017 19:55:18 +0200 Subject: [PATCH] Fixed compilation issue and test. --- doc/news/changes/major/20170914LucaHeltai | 6 ++ include/deal.II/grid/tria_info_cache.h | 11 ++- source/grid/tria_info_cache.cc | 21 ++++- tests/grid/tria_info_cache_01.cc | 59 ++++++++++++ tests/grid/tria_info_cache_01.output | 110 ++++++++++++++++++++++ 5 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 doc/news/changes/major/20170914LucaHeltai create mode 100644 tests/grid/tria_info_cache_01.cc create mode 100644 tests/grid/tria_info_cache_01.output diff --git a/doc/news/changes/major/20170914LucaHeltai b/doc/news/changes/major/20170914LucaHeltai new file mode 100644 index 0000000000..21f9823320 --- /dev/null +++ b/doc/news/changes/major/20170914LucaHeltai @@ -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. +
+(Luca Heltai, 2017/09/14) diff --git a/include/deal.II/grid/tria_info_cache.h b/include/deal.II/grid/tria_info_cache.h index 56c0fac185..26ddfcbd94 100644 --- a/include/deal.II/grid/tria_info_cache.h +++ b/include/deal.II/grid/tria_info_cache.h @@ -30,6 +30,8 @@ #include +#include + #include DEAL_II_NAMESPACE_OPEN @@ -55,7 +57,7 @@ DEAL_II_NAMESPACE_OPEN * * @author Luca Heltai, 2017. */ -template +template class TriangulationInfoCache : public Subscriptor { public: @@ -74,6 +76,8 @@ public: const TriangulationInfoCacheFlags &flags = cache_nothing, const Mapping &mapping=StaticMappingQ1::mapping); + ~TriangulationInfoCache(); + /** * Loop over all TriangulationInfoCacheFlags and rebuilds the specific data * structure. @@ -160,6 +164,11 @@ private: */ KDTree vertex_kdtree; #endif + + /** + * Storage for the status of the triangulation signal. + */ + boost::signals2::connection tria_signal; }; DEAL_II_NAMESPACE_CLOSE diff --git a/source/grid/tria_info_cache.cc b/source/grid/tria_info_cache.cc index b68aab102f..8a150a861a 100644 --- a/source/grid/tria_info_cache.cc +++ b/source/grid/tria_info_cache.cc @@ -27,7 +27,7 @@ TriangulationInfoCache::TriangulationInfoCache( flags(flags), mapping(&mapping) { - tria->signals.any_change.connect([&]() + tria_signal = tria.signals.any_change.connect([&]() { update(); }); @@ -36,11 +36,29 @@ TriangulationInfoCache::TriangulationInfoCache( update(); } +template +TriangulationInfoCache::~TriangulationInfoCache() +{ + // Make sure that the signals that was attached to the triangulation + // is removed here. + if (tria_signal.connected()) + tria_signal.disconnect(); +} + template void TriangulationInfoCache::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::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 index 0000000000..78d5e2dbf4 --- /dev/null +++ b/tests/grid/tria_info_cache_01.cc @@ -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 +#include +#include + + +template +void test () +{ + deallog << "dim = " << dim + << ", spacedim = " << spacedim << std::endl; + + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(1); + + TriangulationInfoCache 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 index 0000000000..560deb18a4 --- /dev/null +++ b/tests/grid/tria_info_cache_01.output @@ -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 -- 2.39.5