libMesh
Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
libMesh::LocationMap< T > Class Template Reference

Data structures that enable location-based lookups The key is a hash of the Point location. 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 std::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 >

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 std::map-like data structure using hashed Points for keys.

Definition at line 53 of file location_maps.h.

Member Typedef Documentation

template<typename T>
typedef std::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 ( )

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>
bool libMesh::LocationMap< T >::empty ( ) const
template<typename T>
void libMesh::LocationMap< T >::fill ( MeshBase )
protected
template<>
void libMesh::LocationMap< Node >::fill ( MeshBase mesh)
protected

Definition at line 185 of file location_maps.C.

References libMesh::MeshBase::node_ptr_range().

186 {
187  // Populate the nodes map
188  for (auto & node : mesh.node_ptr_range())
189  this->insert(*node);
190 }
MeshBase & mesh
template<>
void libMesh::LocationMap< Elem >::fill ( MeshBase mesh)
protected

Definition at line 195 of file location_maps.C.

References libMesh::MeshBase::active_element_ptr_range().

196 {
197  // Populate the elem map
198  for (auto & elem : mesh.active_element_ptr_range())
199  this->insert(*elem);
200 }
MeshBase & mesh
template<typename T >
T * libMesh::LocationMap< T >::find ( const Point p,
const Real  tol = TOLERANCE 
)

Definition at line 111 of file location_maps.C.

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

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

113 {
114  LOG_SCOPE("find()", "LocationMap");
115 
116  // Look for a likely key in the multimap
117  unsigned int pointkey = this->key(p);
118 
119  // Look for the exact key first
120  for (const auto & pr : as_range(_map.equal_range(pointkey)))
121  if (p.absolute_fuzzy_equals(this->point_of(*(pr.second)), tol))
122  return pr.second;
123 
124  // Look for neighboring bins' keys next
125  for (int xoffset = -1; xoffset != 2; ++xoffset)
126  {
127  for (int yoffset = -1; yoffset != 2; ++yoffset)
128  {
129  for (int zoffset = -1; zoffset != 2; ++zoffset)
130  {
131  std::pair<typename map_type::iterator,
132  typename map_type::iterator>
133  key_pos = _map.equal_range(pointkey +
134  xoffset*chunkmax*chunkmax +
135  yoffset*chunkmax +
136  zoffset);
137  for (const auto & pr : as_range(key_pos))
138  if (p.absolute_fuzzy_equals(this->point_of(*(pr.second)), tol))
139  return pr.second;
140  }
141  }
142  }
143 
144  return libmesh_nullptr;
145 }
const class libmesh_nullptr_t libmesh_nullptr
SimpleRange< I > as_range(const std::pair< I, I > &p)
Helper function that allows us to treat a homogenous pair as a range.
Definition: simple_range.h:57
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(), libMesh::MeshBase::is_serial(), std::max(), libMesh::Parallel::Communicator::max(), std::min(), libMesh::Parallel::Communicator::min(), and libMesh::MeshBase::node_ptr_range().

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  for (auto & node : mesh.node_ptr_range())
65  for (unsigned int i=0; i != LIBMESH_DIM; ++i)
66  {
67  // Expand the bounding box if necessary
69  (*node)(i));
71  (*node)(i));
72  }
73 
74  // On a parallel mesh we might not yet have a full bounding box
75  if (!mesh.is_serial())
76  {
77  mesh.comm().min(_lower_bound);
78  mesh.comm().max(_upper_bound);
79  }
80 
81  this->fill(mesh);
82 }
MeshBase & mesh
std::vector< Real > _upper_bound
Definition: location_maps.h:78
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 87 of file location_maps.C.

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

88 {
89  this->_map.insert(std::make_pair(this->key(this->point_of(t)), &t));
90 }
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 150 of file location_maps.C.

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

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

151 {
152  Real xscaled = 0., yscaled = 0., zscaled = 0.;
153 
154  Real deltax = _upper_bound[0] - _lower_bound[0];
155 
156  if (std::abs(deltax) > TOLERANCE)
157  xscaled = (p(0) - _lower_bound[0])/deltax;
158 
159  // Only check y-coords if libmesh is compiled with LIBMESH_DIM>1
160 #if LIBMESH_DIM > 1
161  Real deltay = _upper_bound[1] - _lower_bound[1];
162 
163  if (std::abs(deltay) > TOLERANCE)
164  yscaled = (p(1) - _lower_bound[1])/deltay;
165 #endif
166 
167  // Only check z-coords if libmesh is compiled with LIBMESH_DIM>2
168 #if LIBMESH_DIM > 2
169  Real deltaz = _upper_bound[2] - _lower_bound[2];
170 
171  if (std::abs(deltaz) > TOLERANCE)
172  zscaled = (p(2) - _lower_bound[2])/deltaz;
173 #endif
174 
175  unsigned int n0 = static_cast<unsigned int> (chunkfloat * xscaled),
176  n1 = static_cast<unsigned int> (chunkfloat * yscaled),
177  n2 = static_cast<unsigned int> (chunkfloat * zscaled);
178 
179  return chunkmax*chunkmax*n0 + chunkmax*n1 + n2;
180 }
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 95 of file location_maps.C.

96 {
97  return node;
98 }
template<>
Point libMesh::LocationMap< Elem >::point_of ( const Elem elem) const

Definition at line 103 of file location_maps.C.

References libMesh::Elem::centroid().

104 {
105  return elem.centroid();
106 }

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: