libMesh::TopologyMap Class Reference

Enables topology-based lookups of nodes. 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)
 
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, myhashmap_type
 

Private Attributes

map_type _map
 

Detailed Description

Enables topology-based lookups of nodes.

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

Definition at line 69 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, myhash> libMesh::TopologyMap::map_type
private

Definition at line 72 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 52 of file topology_map.C.

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

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

54 {
55  const dof_id_type mid_node_id = mid_node.id();
56 
57  libmesh_assert_not_equal_to(mid_node_id, DofObject::invalid_id);
58 
59  for (std::size_t i=0; i != bracketing_nodes.size(); ++i)
60  {
61  const dof_id_type id1 = bracketing_nodes[i].first;
62  const dof_id_type id2 = bracketing_nodes[i].second;
63  const dof_id_type lower_id = std::min(id1, id2);
64  const dof_id_type upper_id = std::max(id1, id2);
65 
66  // We should never be inserting inconsistent data
67 #ifndef NDEBUG
68  map_type::iterator it =
69  _map.find(std::make_pair(lower_id, upper_id));
70 
71  if (it != _map.end())
72  libmesh_assert_equal_to (it->second, mid_node_id);
73 #endif
74 
75  this->_map.insert(std::make_pair(std::make_pair(lower_id, upper_id),
76  mid_node_id));
77 
78  }
79 }
long double max(long double a, double b)
static const dof_id_type invalid_id
Definition: dof_object.h:347
long double min(long double a, double b)
uint8_t dof_id_type
Definition: id_types.h:64

◆ clear()

void libMesh::TopologyMap::clear ( )
inline

Definition at line 76 of file topology_map.h.

References _map.

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

76 { _map.clear(); }

◆ empty()

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

Definition at line 87 of file topology_map.h.

References _map.

87 { return _map.empty(); }

◆ fill()

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

Definition at line 139 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().

140 {
141  // Populate the nodes map
142  for (const auto & elem : mesh.element_ptr_range())
143  {
144  // We only need to add nodes which might be added during mesh
145  // refinement; this means they need to be child nodes.
146  if (!elem->has_children())
147  continue;
148 
149  for (unsigned int c = 0, nc = elem->n_children(); c != nc; ++c)
150  {
151  const Elem * child = elem->child_ptr(c);
152  if (child == remote_elem)
153  continue;
154 
155  for (unsigned int n = 0; n != elem->n_nodes_in_child(c); ++n)
156  {
157  const std::vector<std::pair<dof_id_type, dof_id_type>>
158  bracketing_nodes = elem->bracketing_nodes(c,n);
159 
160  this->add_node(child->node_ref(n), bracketing_nodes);
161  }
162  }
163  }
164 }
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
MeshBase & mesh
const RemoteElem * remote_elem
Definition: remote_elem.C:57

◆ find() [1/2]

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

Definition at line 118 of file topology_map.C.

References _map, libMesh::DofObject::invalid_id, std::max(), and std::min().

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

120 {
121  const dof_id_type lower_id = std::min(bracket_node1, bracket_node2);
122  const dof_id_type upper_id = std::max(bracket_node1, bracket_node2);
123 
124  map_type::const_iterator it =
125  _map.find(std::make_pair(lower_id, upper_id));
126 
127  if (it == _map.end())
128  return DofObject::invalid_id;
129 
130  libmesh_assert_not_equal_to (it->second, DofObject::invalid_id);
131 
132  return it->second;
133 }
long double max(long double a, double b)
static const dof_id_type invalid_id
Definition: dof_object.h:347
long double min(long double a, double b)
uint8_t dof_id_type
Definition: id_types.h:64

◆ 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 82 of file topology_map.C.

References find(), libMesh::DofObject::invalid_id, std::max(), and std::min().

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

◆ init()

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

Definition at line 35 of file topology_map.C.

References _map, fill(), and mesh.

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

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

Member Data Documentation

◆ _map

map_type libMesh::TopologyMap::_map
private

Definition at line 100 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: