libMesh
Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
libMesh::TopologyMap Class Reference

Data structures that enable topology-based lookups of nodes created by mesh refinement. More...

#include <topology_map.h>

Public Member Functions

void init (MeshBase &)
 
void clear ()
 
void add_node (const Node &mid_node, const std::vector< std::pair< dof_id_type, dof_id_type >> &bracketing_nodes)
 Add a node to the map, between each pair of specified bracketing nodes. More...
 
bool empty () const
 
dof_id_type find (dof_id_type bracket_node1, dof_id_type bracket_node2) const
 
dof_id_type find (const std::vector< std::pair< dof_id_type, dof_id_type >> &bracketing_nodes) const
 

Protected Member Functions

void fill (const MeshBase &)
 

Private Types

typedef std::unordered_map< std::pair< dof_id_type, dof_id_type >, dof_id_type, libMesh::hashmap_type
 

Private Attributes

map_type _map
 

Detailed Description

Data structures that enable topology-based lookups of nodes created by mesh refinement.

The key is a pair of node ids for two nodes bracketing the new node, sorted lowest id first.

A node created in the middle of a cell's quad face will be the value of two keys, one for each node pair bracketing it.

For efficiency we will use a hashed map if it is available, otherwise a regular map.

Author
Roy Stogner
Date
2015 Enables topology-based lookups of nodes.

Definition at line 57 of file topology_map.h.

Member Typedef Documentation

◆ map_type

typedef std::unordered_map<std::pair<dof_id_type, dof_id_type>, dof_id_type, libMesh::hash> libMesh::TopologyMap::map_type
private

Definition at line 60 of file topology_map.h.

Member Function Documentation

◆ add_node()

void libMesh::TopologyMap::add_node ( const Node mid_node,
const std::vector< std::pair< dof_id_type, dof_id_type >> &  bracketing_nodes 
)

Add a node to the map, between each pair of specified bracketing nodes.

Definition at line 53 of file topology_map.C.

References _map, libMesh::DofObject::id(), and libMesh::DofObject::invalid_id.

Referenced by libMesh::MeshRefinement::add_node(), and fill().

55 {
56  const dof_id_type mid_node_id = mid_node.id();
57 
58  libmesh_assert_not_equal_to(mid_node_id, DofObject::invalid_id);
59 
60  for (auto [id1, id2] : bracketing_nodes)
61  {
62  libmesh_assert_not_equal_to(id1, id2);
63 
64  const dof_id_type lower_id = std::min(id1, id2);
65  const dof_id_type upper_id = std::max(id1, id2);
66 
67  // We should never be inserting inconsistent data
68 #ifndef NDEBUG
69  map_type::iterator it =
70  _map.find(std::make_pair(lower_id, upper_id));
71 
72  if (it != _map.end())
73  libmesh_assert_equal_to (it->second, mid_node_id);
74 #endif
75 
76  this->_map.emplace(std::make_pair(lower_id, upper_id),
77  mid_node_id);
78 
79  }
80 }
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:477
uint8_t dof_id_type
Definition: id_types.h:67

◆ clear()

void libMesh::TopologyMap::clear ( )
inline

Definition at line 64 of file topology_map.h.

References _map.

Referenced by libMesh::MeshRefinement::clear().

64 { _map.clear(); }

◆ empty()

bool libMesh::TopologyMap::empty ( ) const
inline

Definition at line 75 of file topology_map.h.

References _map.

75 { return _map.empty(); }

◆ fill()

void libMesh::TopologyMap::fill ( const MeshBase mesh)
protected

Definition at line 138 of file topology_map.C.

References add_node(), libMesh::Elem::bracketing_nodes(), libMesh::Elem::child_ptr(), mesh, libMesh::Elem::node_ref(), and libMesh::remote_elem.

Referenced by init().

139 {
140  // Populate the nodes map
141  for (const auto & elem : mesh.element_ptr_range())
142  {
143  // We only need to add nodes which might be added during mesh
144  // refinement; this means they need to be child nodes.
145  if (!elem->has_children())
146  continue;
147 
148  for (unsigned int c = 0, nc = elem->n_children(); c != nc; ++c)
149  {
150  const Elem * child = elem->child_ptr(c);
151  if (child == remote_elem)
152  continue;
153 
154  for (unsigned int n = 0, nnic = elem->n_nodes_in_child(c); n != nnic; ++n)
155  {
156  const std::vector<std::pair<dof_id_type, dof_id_type>>
157  bracketing_nodes = elem->bracketing_nodes(c,n);
158 
159  this->add_node(child->node_ref(n), bracketing_nodes);
160  }
161  }
162  }
163 }
void add_node(const Node &mid_node, const std::vector< std::pair< dof_id_type, dof_id_type >> &bracketing_nodes)
Add a node to the map, between each pair of specified bracketing nodes.
Definition: topology_map.C:53
MeshBase & mesh
const RemoteElem * remote_elem
Definition: remote_elem.C:54

◆ find() [1/2]

dof_id_type libMesh::TopologyMap::find ( dof_id_type  bracket_node1,
dof_id_type  bracket_node2 
) const

Definition at line 117 of file topology_map.C.

References _map, and libMesh::DofObject::invalid_id.

Referenced by libMesh::MeshRefinement::add_node(), and find().

119 {
120  const dof_id_type lower_id = std::min(bracket_node1, bracket_node2);
121  const dof_id_type upper_id = std::max(bracket_node1, bracket_node2);
122 
123  map_type::const_iterator it =
124  _map.find(std::make_pair(lower_id, upper_id));
125 
126  if (it == _map.end())
127  return DofObject::invalid_id;
128 
129  libmesh_assert_not_equal_to (it->second, DofObject::invalid_id);
130 
131  return it->second;
132 }
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:477
uint8_t dof_id_type
Definition: id_types.h:67

◆ find() [2/2]

dof_id_type libMesh::TopologyMap::find ( const std::vector< std::pair< dof_id_type, dof_id_type >> &  bracketing_nodes) const

Definition at line 83 of file topology_map.C.

References find(), and libMesh::DofObject::invalid_id.

84 {
85  dof_id_type new_node_id = DofObject::invalid_id;
86 
87  for (auto pair : bracketing_nodes)
88  {
89  const dof_id_type lower_id = std::min(pair.first, pair.second);
90  const dof_id_type upper_id = std::max(pair.first, pair.second);
91 
92  const dof_id_type possible_new_node_id =
93  this->find(lower_id, upper_id);
94 
95  if (possible_new_node_id != DofObject::invalid_id)
96  {
97  // If we found a node already, but we're still here, it's to
98  // debug map consistency: we'd better always find the same
99  // node
100  if (new_node_id != DofObject::invalid_id)
101  libmesh_assert_equal_to (new_node_id, possible_new_node_id);
102 
103  new_node_id = possible_new_node_id;
104  }
105 
106  // If we're not debugging map consistency then we can quit as
107  // soon as we find a node
108 #ifdef NDEBUG
109  if (new_node_id != DofObject::invalid_id)
110  break;
111 #endif
112  }
113  return new_node_id;
114 }
dof_id_type find(dof_id_type bracket_node1, dof_id_type bracket_node2) const
Definition: topology_map.C:117
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:477
uint8_t dof_id_type
Definition: id_types.h:67

◆ init()

void libMesh::TopologyMap::init ( MeshBase mesh)

Definition at line 36 of file topology_map.C.

References _map, fill(), and mesh.

Referenced by libMesh::MeshRefinement::update_nodes_map().

37 {
38  // This function must be run on all processors at once
39  // for non-serial meshes
40  if (!mesh.is_serial())
41  libmesh_parallel_only(mesh.comm());
42 
43  LOG_SCOPE("init()", "TopologyMap");
44 
45  // Clear the old map
46  _map.clear();
47 
48  this->fill(mesh);
49 }
MeshBase & mesh
void fill(const MeshBase &)
Definition: topology_map.C:138

Member Data Documentation

◆ _map

map_type libMesh::TopologyMap::_map
private

Definition at line 88 of file topology_map.h.

Referenced by add_node(), clear(), empty(), find(), and init().


The documentation for this class was generated from the following files: