From: Luca Heltai Date: Sat, 16 Sep 2017 05:05:59 +0000 (+0200) Subject: TriangulationInfoCache -> GridTools::Cache X-Git-Tag: v9.0.0-rc1~1052^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b788a1f37f046b4ce2c4d3edcd0cf00b23087a58;p=dealii.git TriangulationInfoCache -> GridTools::Cache --- diff --git a/doc/news/changes/major/20170914LucaHeltai b/doc/news/changes/major/20170914LucaHeltai index 21f9823320..b9acc89891 100644 --- a/doc/news/changes/major/20170914LucaHeltai +++ b/doc/news/changes/major/20170914LucaHeltai @@ -1,4 +1,4 @@ -New: A new TriangulationInfoCache class +New: A new GridTools::Cache class allows caching of some expensive data of the Triangulation class, computed generally using functions in GridTools. diff --git a/include/deal.II/grid/grid_tools_cache.h b/include/deal.II/grid/grid_tools_cache.h new file mode 100644 index 0000000000..398486e845 --- /dev/null +++ b/include/deal.II/grid/grid_tools_cache.h @@ -0,0 +1,181 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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. +// +// --------------------------------------------------------------------- + +#ifndef dealii_grid_grid_tools_cache_h +#define dealii_grid_grid_tools_cache_h + + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include + +DEAL_II_NAMESPACE_OPEN + +namespace GridTools +{ + + /** + * A class that caches computationally intensive information about a + * Triangulation. + * + * This class attaches a signal to the Triangulation passed at construction + * time, and rebuilds all the structures specified in the list of specified + * TriangulationInfoCacheFlags, whenever the Triangulation is changed. + * + * If you try to access one of the objects that has not been cached (due to a + * missing TriangulationInfoCacheFlags flag), an Assertion is thrown. + * + * Notice that this class only notices if the underlying Triangulation has + * changed due to a Triangulation::Signals::any_change() signal being triggered. + * + * If the triangulation changes due to a MappingQEulerian being passed to this + * class, or because you manually change some vertex locations, then some of + * the structures in this class become obsolete, and you will have to call the + * method update() manually. + * + * @author Luca Heltai, 2017. + */ + template + class Cache : public Subscriptor + { + public: + /** + * Constructor. + * + * You can specify what to cache by passing appropriate + * TriangulationInfoCacheFlags. If you provide the optional `mapping` + * argument, then this is used whenever a mapping is required. + * + * @param tria The triangulation for which to store information + * @param flags TriangulationInfoCacheFlags that specify what to cache + * @param mapping The mapping to use when computing cached objects + */ + Cache (const Triangulation &tria, + const TriangulationInfoCacheFlags &flags = cache_nothing, + const Mapping &mapping=StaticMappingQ1::mapping); + + ~Cache(); + + /** + * Loop over all TriangulationInfoCacheFlags and rebuilds the specific data + * structure. + * + * The optional parameter can be set to true to update only data that is + * dependent on the position of the vertices. This may happen, for example, + * if you have a MappingQEulerian class associated to the triangulation. In + * this case, even if the Triangulation has not changed, the vector that + * specifies the position of the vertices may actually change *independently* + * of the triangulation, requiring you to recompute vertex dependent things. + * In this case, the topological information is not changed, and does not + * need to be updated. + * + * @param topology_is_unchanged + */ + void update(bool topology_is_unchanged=false); + + + /** + * Return the cached vertex_to_cell_map as computed by GridTools::vertex_to_cell_map(). + */ + const std::vector< std::set::active_cell_iterator> > + &get_vertex_to_cell_map() const; + + /** + * Return the cached vertex_to_cell_centers_directions as computed by + * GridTools::vertex_to_cell_centers_directions(). + */ + const std::vector>> + &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 &get_vertex_kdtree() const; +#endif + + /** + * Exception for uninitialized cache fields. + */ + DeclException2(ExcAccessToInvalidCacheObject, + TriangulationInfoCacheFlags &, + TriangulationInfoCacheFlags &, + << "You tried to access a cache object that has not " + << "been constructed by this class. You specified " + << arg2 << " at construction time, but you need also " + << arg1 << " to access the field you are requesting now."); + private: + /** + * A pointer to the Triangulation. + */ + SmartPointer, + Cache> tria; + + /** + * Specifies what to cache. + */ + const TriangulationInfoCacheFlags flags; + + /** + * Mapping to use when computing on the Triangulation. + */ + SmartPointer, + Cache> mapping; + + + /** + * Store vertex to cell map information, as generated by + * GridTools::vertex_to_cell_map() + */ + std::vector< std::set::active_cell_iterator> > vertex_to_cells; + + /** + * Store vertex to cell center directions, as generated by + * GridTools::vertex_to_cell_centers_directions. + */ + std::vector>> vertex_to_cell_centers; + +#ifdef DEAL_II_WITH_NANOFLANN + /** + * A KDTree object constructed with the vertices of the triangulation. + */ + KDTree vertex_kdtree; +#endif + + /** + * Storage for the status of the triangulation signal. + */ + boost::signals2::connection tria_signal; + }; + +} + +DEAL_II_NAMESPACE_CLOSE + +#endif diff --git a/include/deal.II/grid/grid_tools_cache_flags.h b/include/deal.II/grid/grid_tools_cache_flags.h new file mode 100644 index 0000000000..5071efc04f --- /dev/null +++ b/include/deal.II/grid/grid_tools_cache_flags.h @@ -0,0 +1,154 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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. +// +// --------------------------------------------------------------------- + +#ifndef dealii_grid_tria_info_cache_flags_h +#define dealii_grid_tria_info_cache_flags_h + + +#include + +DEAL_II_NAMESPACE_OPEN + +namespace GridTools +{ + + /** + * The enum type given to the Cache class to select what + * information to cache. + * + * You can select more than one flag by concatenation using the bitwise or + * operator|(TriangulationInfoCacheFlags,TriangulationInfoCacheFlags). + * + * @author Luca Heltai, 2017. + */ + enum TriangulationInfoCacheFlags + { + /** + * Cache Nothing. + */ + cache_nothing = 0, + + /** + * Cache vertex_to_cell_map, as returned by GridTools::vertex_to_cell_map(). + */ + cache_vertex_to_cell_map = 0x0001, + + /** + * Cache vertex_to_cell_centers_directions, as returned by + * 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 + }; + + + /** + * Output operator which outputs assemble flags as a set of or'd text values. + * + * @ref TriangulationInfoCacheFlags + */ + template + inline + 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; + } + + + /** + * Global operator which returns an object in which all bits are set which are + * either set in the first or the second argument. This operator exists since + * if it did not then the result of the bit-or operator | would be an + * integer which would in turn trigger a compiler warning when we tried to + * assign it to an object of type TriangulationInfoCacheFlags. + * + * @ref TriangulationInfoCacheFlags + */ + inline + TriangulationInfoCacheFlags + operator | (TriangulationInfoCacheFlags f1, TriangulationInfoCacheFlags f2) + { + return static_cast ( + static_cast (f1) | + static_cast (f2)); + } + + + + + /** + * Global operator which sets the bits from the second argument also in the + * first one. + * + * @ref TriangulationInfoCacheFlags + */ + inline + TriangulationInfoCacheFlags & + operator |= (TriangulationInfoCacheFlags &f1, TriangulationInfoCacheFlags f2) + { + f1 = f1 | f2; + return f1; + } + + + /** + * Global operator which returns an object in which all bits are set which are + * set in the first as well as the second argument. This operator exists since + * if it did not then the result of the bit-and operator & would be + * an integer which would in turn trigger a compiler warning when we tried to + * assign it to an object of type TriangulationInfoCacheFlags. + * + * @ref TriangulationInfoCacheFlags + */ + inline + TriangulationInfoCacheFlags + operator & (TriangulationInfoCacheFlags f1, TriangulationInfoCacheFlags f2) + { + return static_cast ( + static_cast (f1) & + static_cast (f2)); + } + + + /** + * Global operator which clears all the bits in the first argument if they are + * not also set in the second argument. + * + * @ref TriangulationInfoCacheFlags + */ + inline + TriangulationInfoCacheFlags & + operator &= (TriangulationInfoCacheFlags &f1, TriangulationInfoCacheFlags f2) + { + f1 = f1 & f2; + return f1; + } + +} +DEAL_II_NAMESPACE_CLOSE + +#endif diff --git a/include/deal.II/grid/tria_info_cache.h b/include/deal.II/grid/tria_info_cache.h deleted file mode 100644 index 26ddfcbd94..0000000000 --- a/include/deal.II/grid/tria_info_cache.h +++ /dev/null @@ -1,176 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 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. -// -// --------------------------------------------------------------------- - -#ifndef dealii_grid_tria_info_cache_h -#define dealii_grid_tria_info_cache_h - - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include - -#include - -DEAL_II_NAMESPACE_OPEN - -/** - * A class that caches computationally intensive information about a - * Triangulation. - * - * This class attaches a signal to the Triangulation passed at construction - * time, and rebuilds all the structures specified in the list of specified - * TriangulationInfoCacheFlags, whenever the Triangulation is changed. - * - * If you try to access one of the objects that has not been cached (due to a - * missing TriangulationInfoCacheFlags flag), an Assertion is thrown. - * - * Notice that this class only notices if the underlying Triangulation has - * changed due to a Triangulation::Signals::any_change() signal being triggered. - * - * If the triangulation changes due to a MappingQEulerian being passed to this - * class, or because you manually change some vertex locations, then some of - * the structures in this class become obsolete, and you will have to call the - * method update() manually. - * - * @author Luca Heltai, 2017. - */ -template -class TriangulationInfoCache : public Subscriptor -{ -public: - /** - * Constructor. - * - * You can specify what to cache by passing appropriate - * TriangulationInfoCacheFlags. If you provide the optional `mapping` - * argument, then this is used whenever a mapping is required. - * - * @param tria The triangulation for which to store information - * @param flags TriangulationInfoCacheFlags that specify what to cache - * @param mapping The mapping to use when computing cached objects - */ - TriangulationInfoCache (const Triangulation &tria, - const TriangulationInfoCacheFlags &flags = cache_nothing, - const Mapping &mapping=StaticMappingQ1::mapping); - - ~TriangulationInfoCache(); - - /** - * Loop over all TriangulationInfoCacheFlags and rebuilds the specific data - * structure. - * - * The optional parameter can be set to true to update only data that is - * dependent on the position of the vertices. This may happen, for example, - * if you have a MappingQEulerian class associated to the triangulation. In - * this case, even if the Triangulation has not changed, the vector that - * specifies the position of the vertices may actually change *independently* - * of the triangulation, requiring you to recompute vertex dependent things. - * In this case, the topological information is not changed, and does not - * need to be updated. - * - * @param topology_is_unchanged - */ - void update(bool topology_is_unchanged=false); - - - /** - * Return the cached vertex_to_cell_map as computed by GridTools::vertex_to_cell_map(). - */ - const std::vector< std::set::active_cell_iterator> > - &get_vertex_to_cell_map() const; - - /** - * Return the cached vertex_to_cell_centers_directions as computed by - * GridTools::vertex_to_cell_centers_directions(). - */ - const std::vector>> - &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 &get_vertex_kdtree() const; -#endif - - /** - * Exception for uninitialized cache fields. - */ - DeclException2(ExcAccessToInvalidCacheObject, - TriangulationInfoCacheFlags &, - TriangulationInfoCacheFlags &, - << "You tried to access a cache object that has not " - << "been constructed by this class. You specified " - << arg2 << " at construction time, but you need also " - << arg1 << " to access the field you are requesting now."); -private: - /** - * A pointer to the Triangulation. - */ - SmartPointer, - TriangulationInfoCache> tria; - - /** - * Specifies what to cache. - */ - const TriangulationInfoCacheFlags flags; - - /** - * Mapping to use when computing on the Triangulation. - */ - SmartPointer, - TriangulationInfoCache> mapping; - - - /** - * Store vertex to cell map information, as generated by - * GridTools::vertex_to_cell_map() - */ - std::vector< std::set::active_cell_iterator> > vertex_to_cells; - - /** - * Store vertex to cell center directions, as generated by - * GridTools::vertex_to_cell_centers_directions. - */ - std::vector>> vertex_to_cell_centers; - -#ifdef DEAL_II_WITH_NANOFLANN - /** - * A KDTree object constructed with the vertices of the triangulation. - */ - KDTree vertex_kdtree; -#endif - - /** - * Storage for the status of the triangulation signal. - */ - boost::signals2::connection tria_signal; -}; - -DEAL_II_NAMESPACE_CLOSE - -#endif diff --git a/include/deal.II/grid/tria_info_cache_flags.h b/include/deal.II/grid/tria_info_cache_flags.h deleted file mode 100644 index 0c8a4202e0..0000000000 --- a/include/deal.II/grid/tria_info_cache_flags.h +++ /dev/null @@ -1,150 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 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. -// -// --------------------------------------------------------------------- - -#ifndef dealii_grid_tria_info_cache_flags_h -#define dealii_grid_tria_info_cache_flags_h - - -#include - -DEAL_II_NAMESPACE_OPEN - -/** - * The enum type given to the TriangulationInfoCache class to select what - * information to cache. - * - * You can select more than one flag by concatenation using the bitwise or - * operator|(TriangulationInfoCacheFlags,TriangulationInfoCacheFlags). - * - * @author Luca Heltai, 2017. - */ -enum TriangulationInfoCacheFlags -{ - /** - * Cache Nothing. - */ - cache_nothing = 0, - - /** - * Cache vertex_to_cell_map, as returned by GridTools::vertex_to_cell_map(). - */ - cache_vertex_to_cell_map = 0x0001, - - /** - * Cache vertex_to_cell_centers_directions, as returned by - * 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 -}; - - -/** - * Output operator which outputs assemble flags as a set of or'd text values. - * - * @ref TriangulationInfoCacheFlags - */ -template -inline -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; -} - - -/** - * Global operator which returns an object in which all bits are set which are - * either set in the first or the second argument. This operator exists since - * if it did not then the result of the bit-or operator | would be an - * integer which would in turn trigger a compiler warning when we tried to - * assign it to an object of type TriangulationInfoCacheFlags. - * - * @ref TriangulationInfoCacheFlags - */ -inline -TriangulationInfoCacheFlags -operator | (TriangulationInfoCacheFlags f1, TriangulationInfoCacheFlags f2) -{ - return static_cast ( - static_cast (f1) | - static_cast (f2)); -} - - - - -/** - * Global operator which sets the bits from the second argument also in the - * first one. - * - * @ref TriangulationInfoCacheFlags - */ -inline -TriangulationInfoCacheFlags & -operator |= (TriangulationInfoCacheFlags &f1, TriangulationInfoCacheFlags f2) -{ - f1 = f1 | f2; - return f1; -} - - -/** - * Global operator which returns an object in which all bits are set which are - * set in the first as well as the second argument. This operator exists since - * if it did not then the result of the bit-and operator & would be - * an integer which would in turn trigger a compiler warning when we tried to - * assign it to an object of type TriangulationInfoCacheFlags. - * - * @ref TriangulationInfoCacheFlags - */ -inline -TriangulationInfoCacheFlags -operator & (TriangulationInfoCacheFlags f1, TriangulationInfoCacheFlags f2) -{ - return static_cast ( - static_cast (f1) & - static_cast (f2)); -} - - -/** - * Global operator which clears all the bits in the first argument if they are - * not also set in the second argument. - * - * @ref TriangulationInfoCacheFlags - */ -inline -TriangulationInfoCacheFlags & -operator &= (TriangulationInfoCacheFlags &f1, TriangulationInfoCacheFlags f2) -{ - f1 = f1 & f2; - return f1; -} - -DEAL_II_NAMESPACE_CLOSE - -#endif diff --git a/source/grid/CMakeLists.txt b/source/grid/CMakeLists.txt index 2e26d5f41c..d68c7735d4 100644 --- a/source/grid/CMakeLists.txt +++ b/source/grid/CMakeLists.txt @@ -21,6 +21,7 @@ SET(_unity_include_src grid_in.cc grid_out.cc grid_refinement.cc + grid_tools_cache.cc intergrid_map.cc manifold.cc manifold_lib.cc @@ -28,7 +29,6 @@ SET(_unity_include_src tria_accessor.cc tria_boundary.cc tria_boundary_lib.cc - tria_info_cache.cc tria_faces.cc tria_levels.cc tria_objects.cc @@ -56,13 +56,13 @@ SET(_inst grid_out.inst.in grid_refinement.inst.in grid_tools.inst.in + grid_tools_cache.inst.in intergrid_map.inst.in manifold.inst.in manifold_lib.inst.in tria_accessor.inst.in tria_boundary.inst.in tria_boundary_lib.inst.in - tria_info_cache.inst.in tria.inst.in tria_objects.inst.in ) diff --git a/source/grid/grid_tools_cache.cc b/source/grid/grid_tools_cache.cc new file mode 100644 index 0000000000..673dae6fd0 --- /dev/null +++ b/source/grid/grid_tools_cache.cc @@ -0,0 +1,123 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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. +// +// --------------------------------------------------------------------- + +#include +#include + +DEAL_II_NAMESPACE_OPEN + +namespace GridTools +{ + + template + Cache::Cache( + const Triangulation &tria, + const TriangulationInfoCacheFlags &flags, + const Mapping &mapping) : + tria(&tria), + flags(flags), + mapping(&mapping) + { + tria_signal = tria.signals.any_change.connect([&]() + { + update(); + }); + + if (tria.n_active_cells()>0) + update(); + } + + template + Cache::~Cache() + { + // Make sure that the signals that was attached to the triangulation + // is removed here. + if (tria_signal.connected()) + tria_signal.disconnect(); + } + + + + template + void Cache::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(); +#ifdef DEAL_II_WITH_NANOFLANN + vertex_kdtree.set_points(tria->get_vertices()); +#endif + return; + } + + if (topology_is_unchanged == false) + { + 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) + vertex_to_cell_centers = + GridTools::vertex_to_cell_centers_directions(*tria, vertex_to_cells); + + } + + + + template + const std::vector::active_cell_iterator> > & + Cache::get_vertex_to_cell_map() const + { + Assert(flags & cache_vertex_to_cell_map, + ExcAccessToInvalidCacheObject(cache_vertex_to_cell_map, flags)); + return vertex_to_cells; + } + + + + template + const std::vector>> & + Cache::get_vertex_to_cell_centers_directions() const + { + Assert(flags & cache_vertex_to_cell_centers_directions, + ExcAccessToInvalidCacheObject(cache_vertex_to_cell_centers_directions, flags)); + return vertex_to_cell_centers; + } + + + +#ifdef DEAL_II_WITH_NANOFLANN + template + const KDTree &Cache::get_vertex_kdtree() const + { + Assert(flags & cache_vertex_kdtree, + ExcAccessToInvalidCacheObject(cache_vertex_kdtree, flags)); + return vertex_kdtree; + } +#endif + +#include "grid_tools_cache.inst" + +} // GridTools + +DEAL_II_NAMESPACE_CLOSE + diff --git a/source/grid/tria_info_cache.inst.in b/source/grid/grid_tools_cache.inst.in similarity index 90% rename from source/grid/tria_info_cache.inst.in rename to source/grid/grid_tools_cache.inst.in index 7f03011ace..b50399a44e 100644 --- a/source/grid/tria_info_cache.inst.in +++ b/source/grid/grid_tools_cache.inst.in @@ -18,6 +18,6 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) { #if deal_II_dimension <= deal_II_space_dimension - template class TriangulationInfoCache; + template class Cache; #endif } diff --git a/source/grid/tria_info_cache.cc b/source/grid/tria_info_cache.cc deleted file mode 100644 index e9c89139f0..0000000000 --- a/source/grid/tria_info_cache.cc +++ /dev/null @@ -1,118 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 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. -// -// --------------------------------------------------------------------- - -#include -#include - -DEAL_II_NAMESPACE_OPEN - -template -TriangulationInfoCache::TriangulationInfoCache( - const Triangulation &tria, - const TriangulationInfoCacheFlags &flags, - const Mapping &mapping) : - tria(&tria), - flags(flags), - mapping(&mapping) -{ - tria_signal = tria.signals.any_change.connect([&]() - { - update(); - }); - - if (tria.n_active_cells()>0) - 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(); -#ifdef DEAL_II_WITH_NANOFLANN - vertex_kdtree.set_points(tria->get_vertices()); -#endif - return; - } - - if (topology_is_unchanged == false) - { - 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) - vertex_to_cell_centers = - GridTools::vertex_to_cell_centers_directions(*tria, vertex_to_cells); - -} - - - -template -const std::vector::active_cell_iterator> > & -TriangulationInfoCache::get_vertex_to_cell_map() const -{ - Assert(flags & cache_vertex_to_cell_map, - ExcAccessToInvalidCacheObject(cache_vertex_to_cell_map, flags)); - return vertex_to_cells; -} - - - -template -const std::vector>> & -TriangulationInfoCache::get_vertex_to_cell_centers_directions() const -{ - Assert(flags & cache_vertex_to_cell_centers_directions, - ExcAccessToInvalidCacheObject(cache_vertex_to_cell_centers_directions, flags)); - return vertex_to_cell_centers; -} - - - -#ifdef DEAL_II_WITH_NANOFLANN -template -const KDTree &TriangulationInfoCache::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 - diff --git a/tests/grid/tria_info_cache_01.cc b/tests/grid/grid_tools_cache_01.cc similarity index 89% rename from tests/grid/tria_info_cache_01.cc rename to tests/grid/grid_tools_cache_01.cc index 78d5e2dbf4..a71313f1ef 100644 --- a/tests/grid/tria_info_cache_01.cc +++ b/tests/grid/grid_tools_cache_01.cc @@ -13,12 +13,12 @@ // // --------------------------------------------------------------------- -// Validate tria_info_cache +// Validate grid_tools_cache #include "../tests.h" #include #include -#include +#include template @@ -31,7 +31,7 @@ void test () GridGenerator::hyper_cube(tria); tria.refine_global(1); - TriangulationInfoCache cache(tria, cache_vertex_to_cell_map); + GridTools::Cache cache(tria, GridTools::cache_vertex_to_cell_map); auto m = cache.get_vertex_to_cell_map(); diff --git a/tests/grid/tria_info_cache_01.output b/tests/grid/grid_tools_cache_01.output similarity index 100% rename from tests/grid/tria_info_cache_01.output rename to tests/grid/grid_tools_cache_01.output diff --git a/tests/grid/tria_info_cache_02.cc b/tests/grid/grid_tools_cache_02.cc similarity index 88% rename from tests/grid/tria_info_cache_02.cc rename to tests/grid/grid_tools_cache_02.cc index 4280b6c8e3..3dc0a063c0 100644 --- a/tests/grid/tria_info_cache_02.cc +++ b/tests/grid/grid_tools_cache_02.cc @@ -13,12 +13,12 @@ // // --------------------------------------------------------------------- -// Validate tria_info_cache. Different construction order. Check signal. +// Validate grid_tools_cache. Different construction order. Check signal. #include "../tests.h" #include #include -#include +#include template @@ -28,7 +28,7 @@ void test () << ", spacedim = " << spacedim << std::endl; Triangulation tria; - TriangulationInfoCache cache(tria, cache_vertex_to_cell_map); + GridTools::Cache cache(tria, GridTools::cache_vertex_to_cell_map); GridGenerator::hyper_cube(tria); diff --git a/tests/grid/tria_info_cache_02.output b/tests/grid/grid_tools_cache_02.output similarity index 100% rename from tests/grid/tria_info_cache_02.output rename to tests/grid/grid_tools_cache_02.output