deal.II version GIT relicensing-2287-g6548a49e0a 2024-12-20 18:30:00+00:00
|
#include <deal.II/grid/grid_tools_cache.h>
Public Member Functions | |
Cache (const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping) | |
Cache (const Triangulation< dim, spacedim > &tria) | |
~Cache () override | |
void | mark_for_update (const CacheUpdateFlags &flags=update_all) |
const std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > & | get_vertex_to_cell_map () const |
const std::vector< std::vector< Tensor< 1, spacedim > > > & | get_vertex_to_cell_centers_directions () const |
const std::map< unsigned int, Point< spacedim > > & | get_used_vertices () const |
const RTree< std::pair< Point< spacedim >, unsigned int > > & | get_used_vertices_rtree () const |
const RTree< std::pair< BoundingBox< spacedim >, typename Triangulation< dim, spacedim >::active_cell_iterator > > & | get_cell_bounding_boxes_rtree () const |
const RTree< std::pair< BoundingBox< spacedim >, typename Triangulation< dim, spacedim >::active_cell_iterator > > & | get_locally_owned_cell_bounding_boxes_rtree () const |
const std::vector< std::set< unsigned int > > & | get_vertex_to_neighbor_subdomain () const |
const std::map< unsigned int, std::set< types::subdomain_id > > & | get_vertices_with_ghost_neighbors () const |
const Triangulation< dim, spacedim > & | get_triangulation () const |
const Mapping< dim, spacedim > & | get_mapping () const |
const RTree< std::pair< BoundingBox< spacedim >, unsigned int > > & | get_covering_rtree (const unsigned int level=0) const |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
EnableObserverPointer functionality | |
Classes derived from EnableObserverPointer provide a facility to subscribe to this object. This is mostly used by the ObserverPointer class. | |
void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
unsigned int | n_subscriptions () const |
template<typename StreamType > | |
void | list_subscribers (StreamType &stream) const |
void | list_subscribers () const |
Static Public Member Functions | |
static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
Private Types | |
using | map_value_type = decltype(counter_map)::value_type |
using | map_iterator = decltype(counter_map)::iterator |
Private Member Functions | |
void | check_no_subscribers () const noexcept |
Private Attributes | |
std::atomic< std::underlying_type_t< CacheUpdateFlags > > | update_flags |
ObserverPointer< const Triangulation< dim, spacedim >, Cache< dim, spacedim > > | tria |
ObserverPointer< const Mapping< dim, spacedim >, Cache< dim, spacedim > > | mapping |
std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > | vertex_to_cells |
std::mutex | vertex_to_cells_mutex |
std::vector< std::vector< Tensor< 1, spacedim > > > | vertex_to_cell_centers |
std::mutex | vertex_to_cell_centers_mutex |
std::map< unsigned int, RTree< std::pair< BoundingBox< spacedim >, unsigned int > > > | covering_rtree |
std::mutex | covering_rtree_mutex |
std::map< unsigned int, Point< spacedim > > | used_vertices |
std::mutex | used_vertices_mutex |
RTree< std::pair< Point< spacedim >, unsigned int > > | used_vertices_rtree |
std::mutex | used_vertices_rtree_mutex |
RTree< std::pair< BoundingBox< spacedim >, typename Triangulation< dim, spacedim >::active_cell_iterator > > | cell_bounding_boxes_rtree |
std::mutex | cell_bounding_boxes_rtree_mutex |
RTree< std::pair< BoundingBox< spacedim >, typename Triangulation< dim, spacedim >::active_cell_iterator > > | locally_owned_cell_bounding_boxes_rtree |
std::mutex | locally_owned_cell_bounding_boxes_rtree_mutex |
std::vector< std::set< unsigned int > > | vertex_to_neighbor_subdomain |
std::mutex | vertex_to_neighbor_subdomain_mutex |
std::map< unsigned int, std::set<::types::subdomain_id > > | vertices_with_ghost_neighbors |
std::mutex | vertices_with_ghost_neighbors_mutex |
boost::signals2::connection | tria_change_signal |
boost::signals2::connection | tria_create_signal |
std::atomic< unsigned int > | counter |
std::map< std::string, unsigned int > | counter_map |
std::vector< std::atomic< bool > * > | validity_pointers |
const std::type_info * | object_info |
Static Private Attributes | |
static std::mutex | mutex |
A class that caches computationally intensive information about a Triangulation.
This class attaches a signal to the Triangulation passed at construction time to keep track about refinement changes, and allows the user to query some of the data structures constructed using functions in the GridTools namespace which are computed only once, and then cached inside this class for faster access whenever the triangulation has not changed.
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 for other reasons, for example because you use it in conjunction with a MappingQEulerian object that sees the vertices through its own transformation, or because you manually change some vertex locations, then some of the structures in this class become obsolete, and you will have to mark them as outdated, by calling the method mark_for_update() manually.
Definition at line 66 of file grid_tools_cache.h.
|
privateinherited |
The data type used in counter_map.
Definition at line 238 of file enable_observer_pointer.h.
|
privateinherited |
The iterator type used in counter_map.
Definition at line 243 of file enable_observer_pointer.h.
GridTools::Cache< dim, spacedim >::Cache | ( | const Triangulation< dim, spacedim > & | tria, |
const Mapping< dim, spacedim > & | mapping | ||
) |
Constructor.
If you provide the optional mapping
argument, then this is used whenever a mapping is required.
tria | The triangulation for which to store information. |
mapping | The Mapping to use when computing cached objects. |
Definition at line 27 of file grid_tools_cache.cc.
GridTools::Cache< dim, spacedim >::Cache | ( | const Triangulation< dim, spacedim > & | tria | ) |
Constructor. Uses the default linear or multilinear mapping for the underlying ReferenceCell of tria
.
tria | The triangulation for which to store information. |
Definition at line 40 of file grid_tools_cache.cc.
|
override |
Destructor.
Definition at line 68 of file grid_tools_cache.cc.
void GridTools::Cache< dim, spacedim >::mark_for_update | ( | const CacheUpdateFlags & | flags = update_all | ) |
Make sure that the objects marked for update are recomputed during subsequent calls to the get_*
functions defined in this class.
Notice that no work is performed when you call this function. The actual data structures are computed the next time you call the corresponding get_*
method.
flags | What to mark for update |
Definition at line 80 of file grid_tools_cache.cc.
const std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > & GridTools::Cache< dim, spacedim >::get_vertex_to_cell_map | ( | ) | const |
Return the cached vertex_to_cell_map as computed by GridTools::vertex_to_cell_map().
Definition at line 90 of file grid_tools_cache.cc.
const std::vector< std::vector< Tensor< 1, spacedim > > > & GridTools::Cache< dim, spacedim >::get_vertex_to_cell_centers_directions | ( | ) | const |
Return the cached vertex_to_cell_centers_directions as computed by GridTools::vertex_to_cell_centers_directions().
Definition at line 114 of file grid_tools_cache.cc.
const std::map< unsigned int, Point< spacedim > > & GridTools::Cache< dim, spacedim >::get_used_vertices | ( | ) | const |
Return the cached map of used vertices, as computed by GridTools::extract_used_vertices().
Definition at line 139 of file grid_tools_cache.cc.
const RTree< std::pair< Point< spacedim >, unsigned int > > & GridTools::Cache< dim, spacedim >::get_used_vertices_rtree | ( | ) | const |
Return the cached RTree object for the vertices, constructed using the used vertices of the triangulation.
Definition at line 163 of file grid_tools_cache.cc.
const RTree< std::pair< BoundingBox< spacedim >, typename Triangulation< dim, spacedim >::active_cell_iterator > > & GridTools::Cache< dim, spacedim >::get_cell_bounding_boxes_rtree | ( | ) | const |
Return the cached RTree object of the cell bounding boxes, constructed using the active cell iterators of the stored triangulation. For parallel::distributed::Triangulation objects, this function will return also the bounding boxes of ghost and artificial cells.
Definition at line 195 of file grid_tools_cache.cc.
const RTree< std::pair< BoundingBox< spacedim >, typename Triangulation< dim, spacedim >::active_cell_iterator > > & GridTools::Cache< dim, spacedim >::get_locally_owned_cell_bounding_boxes_rtree | ( | ) | const |
Return the cached RTree object of bounding boxes containing locally owned active cells, constructed using the active cell iterators of the stored triangulation.
In contrast to the previous function, this function builds the RTree using only the locally owned cells, i.e., not including ghost or artificial cells. The two functions return the same result in serial computations.
Definition at line 229 of file grid_tools_cache.cc.
const std::vector< std::set< unsigned int > > & GridTools::Cache< dim, spacedim >::get_vertex_to_neighbor_subdomain | ( | ) | const |
Returns the vector of set of integer containing the subdomain id to which each vertex is connected to. This feature is used extensively in the particle_handler to detect on which processors ghost particles must be built.
Definition at line 309 of file grid_tools_cache.cc.
const std::map< unsigned int, std::set< types::subdomain_id > > & GridTools::Cache< dim, spacedim >::get_vertices_with_ghost_neighbors | ( | ) | const |
Return a map that, for each vertex, lists all the processes whose subdomains are adjacent to that vertex.
Definition at line 340 of file grid_tools_cache.cc.
|
inline |
Return a reference to the stored triangulation.
Definition at line 347 of file grid_tools_cache.h.
|
inline |
Return a reference to the stored mapping.
Definition at line 356 of file grid_tools_cache.h.
const RTree< std::pair< BoundingBox< spacedim >, unsigned int > > & GridTools::Cache< dim, spacedim >::get_covering_rtree | ( | const unsigned int | level = 0 | ) | const |
This function returns an object that allows identifying which process(es) in a parallel computation may own the cell that surrounds a given point. The elements of this object – an Rtree – are pairs of bounding boxes denoting areas that cover all or parts of the local portion of a parallel triangulation, and an unsigned int representing the process or subdomain that owns the cells falling within the given bounding box.
Given a point on a parallel::TriangulationBase, this tree allows to identify one, or few candidate processes, for which the point lies on a locally owned cell.
Constructing or updating the rtree requires a call to GridTools::build_global_description_tree(), which exchanges bounding boxes between all processes using Utilities::MPI::all_gather(), a collective operation. Therefore this function must be called by all processes at the same time.
The local bounding boxes are constructed by extracting the specified level
from the rtree object returned by the get_locally_owned_cell_bounding_boxes_rtree(). Notice that level
in this context does not refer to the level of the triangulation, but refer to the level of the RTree object (see, e.g., https://en.wikipedia.org/wiki/R-tree).
Definition at line 268 of file grid_tools_cache.cc.
|
inherited |
Subscribes a user of the object by storing the pointer validity
. The subscriber may be identified by text supplied as identifier
.
Definition at line 131 of file enable_observer_pointer.cc.
|
inherited |
Unsubscribes a user from the object.
identifier
and the validity
pointer must be the same as the one supplied to subscribe(). Definition at line 151 of file enable_observer_pointer.cc.
|
inlineinherited |
Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.
Definition at line 322 of file enable_observer_pointer.h.
|
inlineinherited |
List the subscribers to the input stream
.
Definition at line 339 of file enable_observer_pointer.h.
|
inherited |
List the subscribers to deallog
.
Definition at line 199 of file enable_observer_pointer.cc.
|
inlineinherited |
Read or write the data of this object to or from a stream for the purpose of serialization using the BOOST serialization library.
This function does not actually serialize any of the member variables of this class. The reason is that what this class stores is only who subscribes to this object, but who does so at the time of storing the contents of this object does not necessarily have anything to do with who subscribes to the object when it is restored. Consequently, we do not want to overwrite the subscribers at the time of restoring, and then there is no reason to write the subscribers out in the first place.
Definition at line 331 of file enable_observer_pointer.h.
|
privatenoexceptinherited |
Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.
Definition at line 53 of file enable_observer_pointer.cc.
|
mutableprivate |
Keep track of what needs to be updated every time the triangulation is changed. Each of the get_*() functions above checks whether a data structure still needs to be updated before returning a reference to it; if it needs to be updated, it does so and resets the corresponding flag. The constructor as well as the signal slot that is called whenever the triangulation changes the re-sets this flag to update_all
again.
The various get_() member functions may be reading and updating this variable from different threads, but are only ever reading or writing individual bits. We can make that thread-safe by using std::atomic with the correct integer type for the enum
type of CacheUpdateFlags
.
Definition at line 239 of file grid_tools_cache.h.
|
private |
A pointer to the Triangulation.
Definition at line 245 of file grid_tools_cache.h.
|
private |
Mapping to use when computing on the Triangulation.
Definition at line 250 of file grid_tools_cache.h.
|
mutableprivate |
Store vertex to cell map information, as generated by GridTools::vertex_to_cell_map()
Definition at line 259 of file grid_tools_cache.h.
|
mutableprivate |
Definition at line 260 of file grid_tools_cache.h.
|
mutableprivate |
Store vertex to cell center directions, as generated by GridTools::vertex_to_cell_centers_directions().
Definition at line 267 of file grid_tools_cache.h.
|
mutableprivate |
Definition at line 268 of file grid_tools_cache.h.
|
mutableprivate |
A collection of rtree objects covering the whole mesh.
Each entry of the map is constructed from the function extract_rtree_level() applied to the rtree returned by the function get_locally_owned_cell_bounding_boxes_rtree(), with the specified level in input.
Definition at line 280 of file grid_tools_cache.h.
|
mutableprivate |
Definition at line 281 of file grid_tools_cache.h.
|
mutableprivate |
Store the used vertices of the Triangulation, as generated by GridTools::extract_used_vertices().
Definition at line 287 of file grid_tools_cache.h.
|
mutableprivate |
Definition at line 288 of file grid_tools_cache.h.
|
mutableprivate |
Store an RTree object, containing the used vertices of the triangulation.
Definition at line 293 of file grid_tools_cache.h.
|
mutableprivate |
Definition at line 294 of file grid_tools_cache.h.
|
mutableprivate |
Store an RTree object, containing the bounding boxes of the cells of the triangulation.
Definition at line 303 of file grid_tools_cache.h.
|
mutableprivate |
Definition at line 304 of file grid_tools_cache.h.
|
mutableprivate |
Store an RTree object, containing the bounding boxes of the locally owned cells of the triangulation.
Definition at line 313 of file grid_tools_cache.h.
|
mutableprivate |
Definition at line 314 of file grid_tools_cache.h.
|
mutableprivate |
Store an std::vector of std::set of integer containing the id of all subdomain to which a vertex is connected to.
Definition at line 320 of file grid_tools_cache.h.
|
mutableprivate |
Definition at line 321 of file grid_tools_cache.h.
|
mutableprivate |
Store an std::map of unsigned integer containing the set of subdomains connected to each vertex.
Definition at line 328 of file grid_tools_cache.h.
|
mutableprivate |
Definition at line 329 of file grid_tools_cache.h.
|
private |
Storage for the status of the triangulation change signal.
Definition at line 334 of file grid_tools_cache.h.
|
private |
Storage for the status of the triangulation creation signal.
Definition at line 339 of file grid_tools_cache.h.
|
mutableprivateinherited |
Store the number of objects which subscribed to this object. Initially, this number is zero, and upon destruction it shall be zero again (i.e. all objects which subscribed should have unsubscribed again).
The creator (and owner) of an object is counted in the map below if HE manages to supply identification.
We use the mutable
keyword in order to allow subscription to constant objects also.
This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic
class template.
Definition at line 227 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this map, we count subscriptions for each different identification string supplied to subscribe().
Definition at line 233 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this vector, we store pointers to the validity bool in the ObserverPointer objects that subscribe to this class.
Definition at line 249 of file enable_observer_pointer.h.
|
mutableprivateinherited |
Pointer to the typeinfo object of this object, from which we can later deduce the class name. Since this information on the derived class is neither available in the destructor, nor in the constructor, we obtain it in between and store it here.
Definition at line 257 of file enable_observer_pointer.h.
|
staticprivateinherited |
A mutex used to ensure data consistency when accessing the mutable
members of this class. This lock is used in the subscribe() and unsubscribe() functions, as well as in list_subscribers()
.
Definition at line 280 of file enable_observer_pointer.h.