libMesh::LocationMap< T > Class Template Reference

std::map-like data structure using hashed Points for keys. More...

#include <location_maps.h>

Public Member Functions

void init (MeshBase &)
 
void clear ()
 
void insert (T &)
 
bool empty () const
 
T * find (const Point &, const Real tol=TOLERANCE)
 
Point point_of (const T &) const
 
template<>
Point point_of (const Node &node) const
 
template<>
Point point_of (const Elem &elem) const
 

Protected Member Functions

unsigned int key (const Point &)
 
void fill (MeshBase &)
 
template<>
void fill (MeshBase &mesh)
 
template<>
void fill (MeshBase &mesh)
 

Private Types

typedef LIBMESH_BEST_UNORDERED_MULTIMAP< unsigned int, T * > map_type
 

Private Attributes

map_type _map
 
std::vector< Real_lower_bound
 
std::vector< Real_upper_bound
 

Detailed Description

template<typename T>
class libMesh::LocationMap< T >

std::map-like data structure using hashed Points for keys.

Data structures that enable location-based lookups The key is a hash of the Point location. For efficiency we will use a hashed multimap if it is available, otherwise a regular multimap.

Author
Roy Stogner
Date
2008

Definition at line 53 of file location_maps.h.

Member Typedef Documentation

template<typename T>
typedef LIBMESH_BEST_UNORDERED_MULTIMAP<unsigned int, T *> libMesh::LocationMap< T >::map_type
private

Definition at line 55 of file location_maps.h.

Member Function Documentation

template<typename T>
void libMesh::LocationMap< T >::clear ( )
inline

Definition at line 59 of file location_maps.h.

References libMesh::LocationMap< T >::_map, and libMesh::LocationMap< T >::insert().

59 { _map.clear(); }
template<typename T>
void libMesh::LocationMap< T >::fill ( MeshBase )
protected
template<>
void libMesh::LocationMap< Node >::fill ( MeshBase mesh)
protected

Definition at line 200 of file location_maps.C.

References end, libMesh::MeshBase::nodes_begin(), and libMesh::MeshBase::nodes_end().

201 {
202  // Populate the nodes map
203  MeshBase::node_iterator it = mesh.nodes_begin(),
204  end = mesh.nodes_end();
205  for (; it != end; ++it)
206  this->insert(**it);
207 }
MeshBase & mesh
IterBase * end
template<>
void libMesh::LocationMap< Elem >::fill ( MeshBase mesh)
protected

Definition at line 212 of file location_maps.C.

References libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), and end.

213 {
214  // Populate the elem map
215  MeshBase::element_iterator it = mesh.active_elements_begin(),
216  end = mesh.active_elements_end();
217  for (; it != end; ++it)
218  this->insert(**it);
219 }
MeshBase & mesh
IterBase * end
template<typename T >
T * libMesh::LocationMap< T >::find ( const Point p,
const Real  tol = TOLERANCE 
)

Definition at line 118 of file location_maps.C.

References libMesh::TypeVector< T >::absolute_fuzzy_equals(), and libmesh_nullptr.

Referenced by libMesh::LocationMap< T >::empty(), and libMesh::Parallel::sync_dofobject_data_by_xyz().

120 {
121  LOG_SCOPE("find()", "LocationMap");
122 
123  // Look for a likely key in the multimap
124  unsigned int pointkey = this->key(p);
125 
126  // Look for the exact key first
127  std::pair<typename map_type::iterator,
128  typename map_type::iterator>
129  pos = _map.equal_range(pointkey);
130 
131  while (pos.first != pos.second)
132  if (p.absolute_fuzzy_equals(this->point_of(*(pos.first->second)), tol))
133  return pos.first->second;
134  else
135  ++pos.first;
136 
137  // Look for neighboring bins' keys next
138  for (int xoffset = -1; xoffset != 2; ++xoffset)
139  {
140  for (int yoffset = -1; yoffset != 2; ++yoffset)
141  {
142  for (int zoffset = -1; zoffset != 2; ++zoffset)
143  {
144  std::pair<typename map_type::iterator,
145  typename map_type::iterator>
146  key_pos = _map.equal_range(pointkey +
147  xoffset*chunkmax*chunkmax +
148  yoffset*chunkmax +
149  zoffset);
150  while (key_pos.first != key_pos.second)
151  if (p.absolute_fuzzy_equals(this->point_of(*(key_pos.first->second)), tol))
152  return key_pos.first->second;
153  else
154  ++key_pos.first;
155  }
156  }
157  }
158 
159  return libmesh_nullptr;
160 }
const class libmesh_nullptr_t libmesh_nullptr
unsigned int key(const Point &)
template<typename T >
void libMesh::LocationMap< T >::init ( MeshBase mesh)

Definition at line 46 of file location_maps.C.

References libMesh::ParallelObject::comm(), end, libMesh::MeshBase::is_serial(), std::max(), libMesh::Parallel::Communicator::max(), std::min(), libMesh::Parallel::Communicator::min(), libMesh::MeshBase::nodes_begin(), and libMesh::MeshBase::nodes_end().

47 {
48  // This function must be run on all processors at once
49  // for non-serial meshes
50  if (!mesh.is_serial())
51  libmesh_parallel_only(mesh.comm());
52 
53  LOG_SCOPE("init()", "LocationMap");
54 
55  // Clear the old map
56  _map.clear();
57 
58  // Cache a bounding box
59  _lower_bound.clear();
60  _lower_bound.resize(LIBMESH_DIM, std::numeric_limits<Real>::max());
61  _upper_bound.clear();
62  _upper_bound.resize(LIBMESH_DIM, -std::numeric_limits<Real>::max());
63 
64  MeshBase::node_iterator it = mesh.nodes_begin();
65  const MeshBase::node_iterator end = mesh.nodes_end();
66 
67  for (; it != end; ++it)
68  {
69  Node * node = *it;
70 
71  for (unsigned int i=0; i != LIBMESH_DIM; ++i)
72  {
73  // Expand the bounding box if necessary
75  (*node)(i));
77  (*node)(i));
78  }
79  }
80 
81  // On a parallel mesh we might not yet have a full bounding box
82  if (!mesh.is_serial())
83  {
84  mesh.comm().min(_lower_bound);
85  mesh.comm().max(_upper_bound);
86  }
87 
88  this->fill(mesh);
89 }
MeshBase & mesh
std::vector< Real > _upper_bound
Definition: location_maps.h:78
IterBase * end
long double max(long double a, double b)
void fill(MeshBase &)
std::vector< Real > _lower_bound
Definition: location_maps.h:77
long double min(long double a, double b)
template<typename T >
void libMesh::LocationMap< T >::insert ( T &  t)

Definition at line 94 of file location_maps.C.

Referenced by libMesh::LocationMap< T >::clear().

95 {
96  this->_map.insert(std::make_pair(this->key(this->point_of(t)), &t));
97 }
Point point_of(const T &) const
unsigned int key(const Point &)
template<typename T >
unsigned int libMesh::LocationMap< T >::key ( const Point p)
protected

Definition at line 165 of file location_maps.C.

References std::abs(), libMesh::Real, and libMesh::TOLERANCE.

Referenced by libMesh::LocationMap< T >::empty().

166 {
167  Real xscaled = 0., yscaled = 0., zscaled = 0.;
168 
169  Real deltax = _upper_bound[0] - _lower_bound[0];
170 
171  if (std::abs(deltax) > TOLERANCE)
172  xscaled = (p(0) - _lower_bound[0])/deltax;
173 
174  // Only check y-coords if libmesh is compiled with LIBMESH_DIM>1
175 #if LIBMESH_DIM > 1
176  Real deltay = _upper_bound[1] - _lower_bound[1];
177 
178  if (std::abs(deltay) > TOLERANCE)
179  yscaled = (p(1) - _lower_bound[1])/deltay;
180 #endif
181 
182  // Only check z-coords if libmesh is compiled with LIBMESH_DIM>2
183 #if LIBMESH_DIM > 2
184  Real deltaz = _upper_bound[2] - _lower_bound[2];
185 
186  if (std::abs(deltaz) > TOLERANCE)
187  zscaled = (p(2) - _lower_bound[2])/deltaz;
188 #endif
189 
190  unsigned int n0 = static_cast<unsigned int> (chunkfloat * xscaled),
191  n1 = static_cast<unsigned int> (chunkfloat * yscaled),
192  n2 = static_cast<unsigned int> (chunkfloat * zscaled);
193 
194  return chunkmax*chunkmax*n0 + chunkmax*n1 + n2;
195 }
double abs(double a)
std::vector< Real > _upper_bound
Definition: location_maps.h:78
static const Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > _lower_bound
Definition: location_maps.h:77
template<typename T>
Point libMesh::LocationMap< T >::point_of ( const T &  ) const
template<>
Point libMesh::LocationMap< Node >::point_of ( const Node node) const

Definition at line 102 of file location_maps.C.

103 {
104  return node;
105 }
template<>
Point libMesh::LocationMap< Elem >::point_of ( const Elem elem) const

Definition at line 110 of file location_maps.C.

References libMesh::Elem::centroid().

111 {
112  return elem.centroid();
113 }

Member Data Documentation

template<typename T>
std::vector<Real> libMesh::LocationMap< T >::_lower_bound
private

Definition at line 77 of file location_maps.h.

template<typename T>
map_type libMesh::LocationMap< T >::_map
private
template<typename T>
std::vector<Real> libMesh::LocationMap< T >::_upper_bound
private

Definition at line 78 of file location_maps.h.


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