topology_map.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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 
27 // C++ Includes
28 #include <unordered_map>
29 #include <functional> // std::hash
30 #include <vector>
31 
32 namespace libMesh
33 {
34 
35 // Forward Declarations
36 class Elem;
37 class MeshBase;
38 class Node;
39 
40 // Fix for STL laziness
41 struct myhash {
42 public:
43  template <typename T1, typename T2>
44  std::size_t operator()(const std::pair<T1, T2> & x) const
45  {
46  // recommendation from
47  // http://stackoverflow.com/questions/5889238/why-is-xor-the-default-way-to-combine-hashes
48  return 3 * std::hash<T1>()(x.first) + std::hash<T2>()(x.second);
49  }
50 };
51 
70 {
71  // We need to supply our own hash function.
72  typedef std::unordered_map<std::pair<dof_id_type, dof_id_type>, dof_id_type, myhash> map_type;
73 public:
74  void init(MeshBase &);
75 
76  void clear() { _map.clear(); }
77 
82  void add_node(const Node & mid_node,
83  const std::vector<
84  std::pair<dof_id_type, dof_id_type>> &
85  bracketing_nodes);
86 
87  bool empty() const { return _map.empty(); }
88 
89  dof_id_type find(dof_id_type bracket_node1,
90  dof_id_type bracket_node2) const;
91 
92  dof_id_type find(const std::vector<
93  std::pair<dof_id_type, dof_id_type>> &
94  bracketing_nodes) const;
95 
96 protected:
97  void fill(const MeshBase &);
98 
99 private:
101 };
102 
103 } // namespace libMesh
104 
105 
106 #endif // LIBMESH_TOPOLOGY_MAP_H
Enables topology-based lookups of nodes.
Definition: topology_map.h:69
std::unordered_map< std::pair< dof_id_type, dof_id_type >, dof_id_type, myhash > map_type
Definition: topology_map.h:72
A geometric point in (x,y,z) space associated with a DOF.
Definition: node.h:52
dof_id_type find(dof_id_type bracket_node1, dof_id_type bracket_node2) const
Definition: topology_map.C:118
void add_node(const Node &mid_node, const std::vector< std::pair< dof_id_type, dof_id_type >> &bracketing_nodes)
Definition: topology_map.C:52
void init(MeshBase &)
Definition: topology_map.C:35
void fill(const MeshBase &)
Definition: topology_map.C:139
Base class for Mesh.
Definition: mesh_base.h:77
bool empty() const
Definition: topology_map.h:87
std::size_t operator()(const std::pair< T1, T2 > &x) const
Definition: topology_map.h:44
uint8_t dof_id_type
Definition: id_types.h:64