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 LIBMESH_BEST_UNORDERED_MAP< std::pair< dof_id_type, dof_id_type >, dof_id_type MYHASH > map_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

typedef LIBMESH_BEST_UNORDERED_MAP<std::pair<dof_id_type, dof_id_type>, dof_id_type MYHASH> libMesh::TopologyMap::map_type
private

Definition at line 82 of file topology_map.h.

Member Function Documentation

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 51 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().

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

Definition at line 86 of file topology_map.h.

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

86 { _map.clear(); }
bool libMesh::TopologyMap::empty ( ) const
inline

Definition at line 97 of file topology_map.h.

97 { return _map.empty(); }
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(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), end, libMesh::Elem::has_children(), libMesh::Elem::is_remote(), libMesh::Elem::n_children(), libMesh::Elem::n_nodes_in_child(), and libMesh::Elem::node_ref().

Referenced by init().

139 {
140  // Populate the nodes map
141  MeshBase::const_element_iterator
142  it = mesh.elements_begin(),
143  end = mesh.elements_end();
144  for (; it != end; ++it)
145  {
146  const Elem * elem = *it;
147 
148  // We only need to add nodes which might be added during mesh
149  // refinement; this means they need to be child nodes.
150  if (!elem->has_children())
151  continue;
152 
153  for (unsigned int c = 0; c != elem->n_children(); ++c)
154  {
155  if (elem->child_ptr(c)->is_remote())
156  continue;
157 
158  for (unsigned int n = 0; n != elem->n_nodes_in_child(c); ++n)
159  {
160  const std::vector<std::pair<dof_id_type, dof_id_type> >
161  bracketing_nodes = elem->bracketing_nodes(c,n);
162 
163  this->add_node(elem->child_ptr(c)->node_ref(n),
164  bracketing_nodes);
165  }
166  }
167  }
168 }
MeshBase & mesh
IterBase * end
void add_node(const Node &mid_node, const std::vector< std::pair< dof_id_type, dof_id_type > > &bracketing_nodes)
Definition: topology_map.C:51
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, libMesh::DofObject::invalid_id, std::max(), and std::min().

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 }
long double max(long double a, double b)
static const dof_id_type invalid_id
Definition: dof_object.h:335
long double min(long double a, double b)
uint8_t dof_id_type
Definition: id_types.h:64
dof_id_type libMesh::TopologyMap::find ( const std::vector< std::pair< dof_id_type, dof_id_type > > &  bracketing_nodes) const

Definition at line 81 of file topology_map.C.

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

82 {
83  dof_id_type new_node_id = DofObject::invalid_id;
84 
85  for (std::size_t i = 0; i != bracketing_nodes.size(); ++i)
86  {
87  const dof_id_type lower_id = std::min(bracketing_nodes[i].first,
88  bracketing_nodes[i].second);
89  const dof_id_type upper_id = std::max(bracketing_nodes[i].first,
90  bracketing_nodes[i].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
long double max(long double a, double b)
static const dof_id_type invalid_id
Definition: dof_object.h:335
long double min(long double a, double b)
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::TopologyMap::init ( MeshBase mesh)

Definition at line 34 of file topology_map.C.

References _map, libMesh::ParallelObject::comm(), fill(), and libMesh::MeshBase::is_serial().

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

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

Member Data Documentation

map_type libMesh::TopologyMap::_map
private

Definition at line 110 of file topology_map.h.

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


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