Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : 19 : 20 : #ifndef LIBMESH_TOPOLOGY_MAP_H 21 : #define LIBMESH_TOPOLOGY_MAP_H 22 : 23 : // Local Includes 24 : #include "libmesh/libmesh_config.h" 25 : #include "libmesh/libmesh_common.h" 26 : #include "libmesh/hashing.h" 27 : 28 : // C++ Includes 29 : #include <unordered_map> 30 : #include <vector> 31 : 32 : namespace libMesh 33 : { 34 : 35 : // Forward Declarations 36 : class Elem; 37 : class MeshBase; 38 : class Node; 39 : 40 : /** 41 : * Data structures that enable topology-based lookups of nodes created 42 : * by mesh refinement. 43 : * 44 : * The key is a pair of node ids for two nodes bracketing the new 45 : * node, sorted lowest id first. 46 : * 47 : * A node created in the middle of a cell's quad face will be the 48 : * value of two keys, one for each node pair bracketing it. 49 : * 50 : * For efficiency we will use a hashed map if it is available, 51 : * otherwise a regular map. 52 : * 53 : * \author Roy Stogner 54 : * \date 2015 55 : * \brief Enables topology-based lookups of nodes. 56 : */ 57 : class TopologyMap 58 : { 59 : // We need to supply our own hash function. 60 : typedef std::unordered_map<std::pair<dof_id_type, dof_id_type>, dof_id_type, libMesh::hash> map_type; 61 : public: 62 : void init(MeshBase &); 63 : 64 1858 : void clear() { _map.clear(); } 65 : 66 : /** 67 : * Add a node to the map, between each pair of specified bracketing 68 : * nodes. 69 : */ 70 : void add_node(const Node & mid_node, 71 : const std::vector< 72 : std::pair<dof_id_type, dof_id_type>> & 73 : bracketing_nodes); 74 : 75 : bool empty() const { return _map.empty(); } 76 : 77 : dof_id_type find(dof_id_type bracket_node1, 78 : dof_id_type bracket_node2) const; 79 : 80 : dof_id_type find(const std::vector< 81 : std::pair<dof_id_type, dof_id_type>> & 82 : bracketing_nodes) const; 83 : 84 : protected: 85 : void fill(const MeshBase &); 86 : 87 : private: 88 : map_type _map; 89 : }; 90 : 91 : } // namespace libMesh 92 : 93 : 94 : #endif // LIBMESH_TOPOLOGY_MAP_H