libMesh::LocationMap< T > Class Template Reference

#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 >

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.

Definition at line 49 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 51 of file location_maps.h.

Member Function Documentation

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

Definition at line 55 of file location_maps.h.

55 { _map.clear(); }
template<typename T>
bool libMesh::LocationMap< T >::empty ( ) const
inline
template<typename T>
void libMesh::LocationMap< T >::fill ( MeshBase )
protected
template<>
void libMesh::LocationMap< Node >::fill ( MeshBase mesh)
protected

Definition at line 215 of file location_maps.C.

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

216 {
217  // Populate the nodes map
218  MeshBase::node_iterator it = mesh.nodes_begin(),
219  end = mesh.nodes_end();
220  for (; it != end; ++it)
221  this->insert(**it);
222 }
template<>
void libMesh::LocationMap< Elem >::fill ( MeshBase mesh)
protected

Definition at line 227 of file location_maps.C.

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

228 {
229  // Populate the elem map
230  MeshBase::element_iterator it = mesh.active_elements_begin(),
231  end = mesh.active_elements_end();
232  for (; it != end; ++it)
233  this->insert(**it);
234 }
template<typename T >
T * libMesh::LocationMap< T >::find ( const Point p,
const Real  tol = TOLERANCE 
)

Definition at line 124 of file location_maps.C.

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

Referenced by libMesh::Parallel::sync_dofobject_data_by_xyz().

126 {
127  START_LOG("find()","LocationMap");
128 
129  // Look for a likely key in the multimap
130  unsigned int pointkey = this->key(p);
131 
132  // Look for the exact key first
133  std::pair<typename map_type::iterator,
134  typename map_type::iterator>
135  pos = _map.equal_range(pointkey);
136 
137  while (pos.first != pos.second)
138  if (p.absolute_fuzzy_equals
139  (this->point_of(*(pos.first->second)), tol))
140  {
141  STOP_LOG("find()","LocationMap");
142  return pos.first->second;
143  }
144  else
145  ++pos.first;
146 
147  // Look for neighboring bins' keys next
148  for (int xoffset = -1; xoffset != 2; ++xoffset)
149  {
150  for (int yoffset = -1; yoffset != 2; ++yoffset)
151  {
152  for (int zoffset = -1; zoffset != 2; ++zoffset)
153  {
154  std::pair<typename map_type::iterator,
155  typename map_type::iterator>
156  key_pos = _map.equal_range(pointkey +
157  xoffset*chunkmax*chunkmax +
158  yoffset*chunkmax +
159  zoffset);
160  while (key_pos.first != key_pos.second)
161  if (p.absolute_fuzzy_equals
162  (this->point_of(*(key_pos.first->second)), tol))
163  {
164  STOP_LOG("find()","LocationMap");
165  return key_pos.first->second;
166  }
167  else
168  ++key_pos.first;
169  }
170  }
171  }
172 
173  STOP_LOG("find()","LocationMap");
174  return NULL;
175 }
template<typename T >
void libMesh::LocationMap< T >::init ( MeshBase mesh)

Definition at line 50 of file location_maps.C.

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

Referenced by libMesh::MeshCommunication::make_nodes_parallel_consistent().

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

Definition at line 100 of file location_maps.C.

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

Definition at line 180 of file location_maps.C.

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

181 {
182  Real xscaled = 0., yscaled = 0., zscaled = 0.;
183 
184  Real deltax = _upper_bound[0] - _lower_bound[0];
185 
186  if (std::abs(deltax) > TOLERANCE)
187  xscaled = (p(0) - _lower_bound[0])/deltax;
188 
189  // Only check y-coords if libmesh is compiled with LIBMESH_DIM>1
190 #if LIBMESH_DIM > 1
191  Real deltay = _upper_bound[1] - _lower_bound[1];
192 
193  if (std::abs(deltay) > TOLERANCE)
194  yscaled = (p(1) - _lower_bound[1])/deltay;
195 #endif
196 
197  // Only check z-coords if libmesh is compiled with LIBMESH_DIM>2
198 #if LIBMESH_DIM > 2
199  Real deltaz = _upper_bound[2] - _lower_bound[2];
200 
201  if (std::abs(deltaz) > TOLERANCE)
202  zscaled = (p(2) - _lower_bound[2])/deltaz;
203 #endif
204 
205  unsigned int n0 = static_cast<unsigned int> (chunkfloat * xscaled),
206  n1 = static_cast<unsigned int> (chunkfloat * yscaled),
207  n2 = static_cast<unsigned int> (chunkfloat * zscaled);
208 
209  return chunkmax*chunkmax*n0 + chunkmax*n1 + n2;
210 }
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 108 of file location_maps.C.

109 {
110  return node;
111 }
template<>
Point libMesh::LocationMap< Elem >::point_of ( const Elem elem) const

Definition at line 116 of file location_maps.C.

References libMesh::Elem::centroid().

117 {
118  return elem.centroid();
119 }

Member Data Documentation

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

Definition at line 73 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 74 of file location_maps.h.


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

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:26 UTC

Hosted By:
SourceForge.net Logo