libMesh
sides_to_elem_map.h
Go to the documentation of this file.
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 #ifndef LIBMESH_SIDES_TO_ELEM_MAP_H
19 #define LIBMESH_SIDES_TO_ELEM_MAP_H
20 
21 // libMesh includes
22 #include "libmesh/id_types.h" // dof_id_type
23 #include "libmesh/hashword.h" // Utility::hashword()
24 
25 // C++ includes
26 #include <unordered_map>
27 #include <vector>
28 
29 namespace libMesh
30 {
31 
32 // Forward declarations
33 class MeshBase;
34 class Elem;
35 
36 namespace MeshTools
37 {
38 
54 {
55 public:
61 
67  static SidesToElemMap build(const MeshBase & mesh);
68 
73  typedef std::vector<const Elem *>::const_iterator ElemIter;
74 
82  std::pair<ElemIter, ElemIter>
83  get_connected_elems(const Elem * elem, unsigned int side) const;
84 
85 private:
86 
90  typedef std::vector<dof_id_type> Key;
91  typedef std::vector<const Elem *> Value;
92 
93  struct HashFunction
94  {
95  public:
104  inline
105  std::size_t operator()(const Key & vertex_ids) const
106  {
107  return cast_int<std::size_t>(Utility::hashword(vertex_ids));
108  }
109 
113  inline
114  bool operator()(const Key & lhs, const Key & rhs) const
115  {
116  return lhs == rhs;
117  }
118  };
119 
125  std::unordered_map<Key, Value, /*Hash*/HashFunction, /*KeyEqual*/HashFunction> _sides_to_elem_map;
126 
134  const Elem * elem,
135  unsigned int side,
136  std::vector<dof_id_type> & sorted_vertex_ids) const;
137 };
138 
139 } // namespace MeshTools
140 
141 } // namespace libMesh
142 
143 #endif // LIBMESH_SIDES_TO_ELEM_MAP_H
bool operator()(const Key &lhs, const Key &rhs) const
The "KeyEqual" template argument.
std::size_t operator()(const Key &vertex_ids) const
The "Hash" template argument.
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
MeshBase & mesh
std::pair< ElemIter, ElemIter > get_connected_elems(const Elem *elem, unsigned int side) const
Return an iterator pair defining the range of Elems connected to "side" of "elem".
std::unordered_map< Key, Value, HashFunction, HashFunction > _sides_to_elem_map
Map from (sorted list of side vertex ids) -> (Elems touching that side) A "side" is uniquely defined ...
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:75
std::vector< const Elem * >::const_iterator ElemIter
Typedef for the iterator type returned by the SidesToeElemMap::get_connected_elems() function...
uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval=0)
The hashword function takes an array of uint32_t&#39;s of length &#39;length&#39; and computes a single key from ...
Definition: hashword.h:158
std::vector< dof_id_type > Key
Convenient typedefs for working with std::unordered_map.
static SidesToElemMap build(const MeshBase &mesh)
Static build function.
std::vector< const Elem * > Value
SidesToElemMap()
Default constructor/destructor.
This class implements a generalization of the MeshTools::build_nodes_to_elem_map() function...
void get_sorted_vertex_ids(const Elem *elem, unsigned int side, std::vector< dof_id_type > &sorted_vertex_ids) const
Construct a sorted list of vertex ids for the input (elem, side) pair.