From: Luca Heltai Date: Fri, 13 Oct 2017 16:01:13 +0000 (+0200) Subject: Added get_used_vertices to GridTools::Cache X-Git-Tag: v9.0.0-rc1~943^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12055253a70f8494ff2453e5fbe15e59c2dffb63;p=dealii.git Added get_used_vertices to GridTools::Cache --- diff --git a/include/deal.II/grid/grid_tools_cache.h b/include/deal.II/grid/grid_tools_cache.h index 138d604320..c0e86ce790 100644 --- a/include/deal.II/grid/grid_tools_cache.h +++ b/include/deal.II/grid/grid_tools_cache.h @@ -109,15 +109,22 @@ namespace GridTools const std::vector>> &get_vertex_to_cell_centers_directions() const; + /** + * Return the cached map of used vertices, as computed by + * GridTools::extract_used_vertices(). + */ + const std::map > + &get_used_vertices() const; + /** * Return a reference to the stored triangulation. */ - const Triangulation & get_triangulation() const; + const Triangulation &get_triangulation() const; /** * Return a reference to the stored mapping. */ - const Mapping & get_mapping() const; + const Mapping &get_mapping() const; #ifdef DEAL_II_WITH_NANOFLANN /** @@ -155,7 +162,7 @@ namespace GridTools /** * Store vertex to cell center directions, as generated by - * GridTools::vertex_to_cell_centers_directions. + * GridTools::vertex_to_cell_centers_directions(). */ mutable std::vector>> vertex_to_cell_centers; @@ -166,6 +173,12 @@ namespace GridTools mutable KDTree vertex_kdtree; #endif + /** + * Store the used vertices of the Triangulation, as generated by + * GridTools::extract_used_vertices(). + */ + mutable std::map> used_vertices; + /** * Storage for the status of the triangulation signal. */ @@ -176,7 +189,8 @@ namespace GridTools // Inline functions template - inline const Triangulation& Cache::get_triangulation() const + inline const Triangulation & + Cache::get_triangulation() const { return *tria; } @@ -184,7 +198,8 @@ namespace GridTools template - inline const Mapping& Cache::get_mapping() const + inline const Mapping & + Cache::get_mapping() const { return *mapping; } diff --git a/include/deal.II/grid/grid_tools_cache_update_flags.h b/include/deal.II/grid/grid_tools_cache_update_flags.h index 39bfd67f79..dbac866d3c 100644 --- a/include/deal.II/grid/grid_tools_cache_update_flags.h +++ b/include/deal.II/grid/grid_tools_cache_update_flags.h @@ -56,6 +56,11 @@ namespace GridTools */ update_vertex_kdtree = 0x04, + /** + * Update a mapping of used vertices. + */ + update_used_vertices = 0x08, + /** * Update all objects. */ diff --git a/source/grid/grid_tools_cache.cc b/source/grid/grid_tools_cache.cc index 3aedd473ef..2e7623d7ee 100644 --- a/source/grid/grid_tools_cache.cc +++ b/source/grid/grid_tools_cache.cc @@ -83,6 +83,20 @@ namespace GridTools + template + const std::map > & + Cache::get_used_vertices() const + { + if (update_flags & update_used_vertices) + { + used_vertices = GridTools::extract_used_vertices(*tria, *mapping); + update_flags = update_flags & ~update_used_vertices; + } + return used_vertices; + } + + + #ifdef DEAL_II_WITH_NANOFLANN template const KDTree &Cache::get_vertex_kdtree() const diff --git a/tests/grid/grid_tools_cache_03.cc b/tests/grid/grid_tools_cache_03.cc new file mode 100644 index 0000000000..93108dcf38 --- /dev/null +++ b/tests/grid/grid_tools_cache_03.cc @@ -0,0 +1,65 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2001 - 2015 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. +// +// --------------------------------------------------------------------- + +// Check extract used_vertices and find_closest_vertex using a cache + +#include "../tests.h" +#include +#include +#include +#include +#include + + +template +void test (const Point &p) +{ + deallog << "dim: " << dim << ", spacedim: " + << spacedim << std::endl; + + Triangulation tria; + GridGenerator::hyper_cube(tria); + + tria.refine_global(1); + tria.begin_active()->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + + for (auto cell = tria.begin_active(2); cell != tria.end(2); ++cell) + cell->set_coarsen_flag(); + + tria.execute_coarsening_and_refinement(); + + GridTools::Cache cache(tria); + + auto m = cache.get_used_vertices(); + + for (auto &e: m) + deallog << "Vertex: " << e.first << ": " << e.second << std::endl; + + auto i = GridTools::find_closest_vertex(m,p); + deallog << "Closest vertex to " << p + << ", v["<< i << "] :" + << m[i] << std::endl; +}; + + +int main () +{ + initlog(); + test<2,2> (Point<2>(.2,.2)); + test<2,2> (Point<2>(.6,.9)); + return 0; +} + diff --git a/tests/grid/grid_tools_cache_03.output b/tests/grid/grid_tools_cache_03.output new file mode 100644 index 0000000000..de11874f0a --- /dev/null +++ b/tests/grid/grid_tools_cache_03.output @@ -0,0 +1,23 @@ + +DEAL::dim: 2, spacedim: 2 +DEAL::Vertex: 0: 0.00000 0.00000 +DEAL::Vertex: 1: 1.00000 0.00000 +DEAL::Vertex: 2: 0.00000 1.00000 +DEAL::Vertex: 3: 1.00000 1.00000 +DEAL::Vertex: 4: 0.500000 0.00000 +DEAL::Vertex: 5: 0.00000 0.500000 +DEAL::Vertex: 6: 1.00000 0.500000 +DEAL::Vertex: 7: 0.500000 1.00000 +DEAL::Vertex: 8: 0.500000 0.500000 +DEAL::Closest vertex to 0.200000 0.200000, v[0] :0.00000 0.00000 +DEAL::dim: 2, spacedim: 2 +DEAL::Vertex: 0: 0.00000 0.00000 +DEAL::Vertex: 1: 1.00000 0.00000 +DEAL::Vertex: 2: 0.00000 1.00000 +DEAL::Vertex: 3: 1.00000 1.00000 +DEAL::Vertex: 4: 0.500000 0.00000 +DEAL::Vertex: 5: 0.00000 0.500000 +DEAL::Vertex: 6: 1.00000 0.500000 +DEAL::Vertex: 7: 0.500000 1.00000 +DEAL::Vertex: 8: 0.500000 0.500000 +DEAL::Closest vertex to 0.600000 0.900000, v[7] :0.500000 1.00000