libMesh::LocationMap< T > Class Template Reference

#include <location_maps.h>

List of all members.

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
template<>
void fill (MeshBase &mesh)
template<>
void fill (MeshBase &mesh)

Protected Member Functions

unsigned int key (const Point &)
void fill (MeshBase &)

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.

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

00055 { _map.clear(); }

template<typename T>
bool libMesh::LocationMap< T >::empty (  )  const [inline]
template<>
void libMesh::LocationMap< Elem >::fill ( MeshBase mesh  )  [inline]

Definition at line 227 of file location_maps.C.

References libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), end, and libMesh::LocationMap< T >::insert().

00228 {
00229   // Populate the elem map
00230   MeshBase::element_iterator       it  = mesh.active_elements_begin(),
00231                                    end = mesh.active_elements_end();
00232   for (; it != end; ++it)
00233     this->insert(**it);
00234 }

template<>
void libMesh::LocationMap< Node >::fill ( MeshBase mesh  )  [inline]

Definition at line 215 of file location_maps.C.

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

00216 {
00217   // Populate the nodes map
00218   MeshBase::node_iterator  it = mesh.nodes_begin(),
00219                           end = mesh.nodes_end();
00220   for (; it != end; ++it)
00221     this->insert(**it);
00222 }

template<typename T>
void libMesh::LocationMap< T >::fill ( MeshBase  )  [protected]
template<typename T >
T * libMesh::LocationMap< T >::find ( const Point p,
const Real  tol = TOLERANCE 
) [inline]

Definition at line 124 of file location_maps.C.

References libMesh::LocationMap< T >::_map, libMesh::TypeVector< T >::absolute_fuzzy_equals(), and libMesh::LocationMap< T >::key().

Referenced by libMesh::MeshRefinement::add_point(), and libMesh::Parallel::sync_dofobject_data_by_xyz().

00126 {
00127   START_LOG("find()","LocationMap");
00128 
00129   // Look for a likely key in the multimap
00130   unsigned int pointkey = this->key(p);
00131 
00132   // Look for the exact key first
00133   std::pair<typename map_type::iterator,
00134             typename map_type::iterator>
00135     pos = _map.equal_range(pointkey);
00136 
00137   while (pos.first != pos.second)
00138     if (p.absolute_fuzzy_equals
00139          (this->point_of(*(pos.first->second)), tol))
00140       {
00141         STOP_LOG("find()","LocationMap");
00142         return pos.first->second;
00143       }
00144     else
00145       ++pos.first;
00146 
00147   // Look for neighboring bins' keys next
00148   for (int xoffset = -1; xoffset != 2; ++xoffset)
00149     {
00150       for (int yoffset = -1; yoffset != 2; ++yoffset)
00151         {
00152           for (int zoffset = -1; zoffset != 2; ++zoffset)
00153             {
00154               std::pair<typename map_type::iterator,
00155                         typename map_type::iterator>
00156                 key_pos = _map.equal_range(pointkey +
00157                                        xoffset*chunkmax*chunkmax +
00158                                        yoffset*chunkmax +
00159                                        zoffset);
00160               while (key_pos.first != key_pos.second)
00161                 if (p.absolute_fuzzy_equals
00162                      (this->point_of(*(key_pos.first->second)), tol))
00163                   {
00164                     STOP_LOG("find()","LocationMap");
00165                     return key_pos.first->second;
00166                   }
00167                 else
00168                   ++key_pos.first;
00169             }
00170         }
00171     }
00172 
00173   STOP_LOG("find()","LocationMap");
00174   return NULL;
00175 }

template<typename T >
void libMesh::LocationMap< T >::init ( MeshBase mesh  )  [inline]

Definition at line 50 of file location_maps.C.

References libMesh::LocationMap< T >::_lower_bound, libMesh::LocationMap< T >::_map, libMesh::LocationMap< T >::_upper_bound, libMesh::CommWorld, end, libMesh::LocationMap< T >::fill(), libMesh::MeshBase::is_serial(), libMesh::Parallel::Communicator::max(), std::max(), libMesh::Parallel::Communicator::min(), std::min(), libMesh::MeshBase::nodes_begin(), and libMesh::MeshBase::nodes_end().

Referenced by libMesh::MeshCommunication::make_nodes_parallel_consistent(), and libMesh::MeshRefinement::update_nodes_map().

00051 {
00052   // This function must be run on all processors at once
00053   // for non-serial meshes
00054   if (!mesh.is_serial())
00055     parallel_only();
00056 
00057   START_LOG("init()", "LocationMap");
00058 
00059   // Clear the old map
00060   _map.clear();
00061 
00062   // Cache a bounding box
00063   _lower_bound.clear();
00064   _lower_bound.resize(LIBMESH_DIM, std::numeric_limits<Real>::max());
00065   _upper_bound.clear();
00066   _upper_bound.resize(LIBMESH_DIM, -std::numeric_limits<Real>::max());
00067 
00068   MeshBase::node_iterator       it  = mesh.nodes_begin();
00069   const MeshBase::node_iterator end = mesh.nodes_end();
00070 
00071   for (; it != end; ++it)
00072     {
00073       Node* node = *it;
00074 
00075       for (unsigned int i=0; i != LIBMESH_DIM; ++i)
00076         {
00077           // Expand the bounding box if necessary
00078           _lower_bound[i] = std::min(_lower_bound[i],
00079                                      (*node)(i));
00080           _upper_bound[i] = std::max(_upper_bound[i],
00081                                      (*node)(i));
00082         }
00083     }
00084 
00085   // On a parallel mesh we might not yet have a full bounding box
00086   if (!mesh.is_serial())
00087     {
00088       CommWorld.min(_lower_bound);
00089       CommWorld.max(_upper_bound);
00090     }
00091 
00092   this->fill(mesh);
00093 
00094   STOP_LOG("init()", "LocationMap");
00095 }

template<typename T>
void libMesh::LocationMap< T >::insert ( T &  t  )  [inline]

Definition at line 100 of file location_maps.C.

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

Referenced by libMesh::MeshRefinement::add_point(), and libMesh::LocationMap< T >::fill().

00101 {
00102   this->_map.insert(std::make_pair(this->key(this->point_of(t)), &t));
00103 }

template<typename T >
unsigned int libMesh::LocationMap< T >::key ( const Point p  )  [inline, protected]

Definition at line 180 of file location_maps.C.

References libMesh::LocationMap< T >::_lower_bound, libMesh::LocationMap< T >::_upper_bound, std::abs(), libMesh::Real, and libMesh::TOLERANCE.

Referenced by libMesh::LocationMap< T >::find(), and libMesh::LocationMap< T >::insert().

00181 {
00182   Real xscaled = 0., yscaled = 0., zscaled = 0.;
00183 
00184   Real deltax = _upper_bound[0] - _lower_bound[0];
00185 
00186   if (std::abs(deltax) > TOLERANCE)
00187     xscaled = (p(0) - _lower_bound[0])/deltax;
00188 
00189   // Only check y-coords if libmesh is compiled with LIBMESH_DIM>1
00190 #if LIBMESH_DIM > 1
00191   Real deltay = _upper_bound[1] - _lower_bound[1];
00192 
00193   if (std::abs(deltay) > TOLERANCE)
00194     yscaled = (p(1) - _lower_bound[1])/deltay;
00195 #endif
00196 
00197   // Only check z-coords if libmesh is compiled with LIBMESH_DIM>2
00198 #if LIBMESH_DIM > 2
00199   Real deltaz = _upper_bound[2] - _lower_bound[2];
00200 
00201   if (std::abs(deltaz) > TOLERANCE)
00202     zscaled = (p(2) - _lower_bound[2])/deltaz;
00203 #endif
00204 
00205   unsigned int n0 = static_cast<unsigned int> (chunkfloat * xscaled),
00206                n1 = static_cast<unsigned int> (chunkfloat * yscaled),
00207                n2 = static_cast<unsigned int> (chunkfloat * zscaled);
00208 
00209   return chunkmax*chunkmax*n0 + chunkmax*n1 + n2;
00210 }

template<>
Point libMesh::LocationMap< Elem >::point_of ( const Elem elem  )  const [inline]

Definition at line 116 of file location_maps.C.

References libMesh::Elem::centroid().

00117 {
00118   return elem.centroid();
00119 }

template<>
Point libMesh::LocationMap< Node >::point_of ( const Node node  )  const [inline]

Definition at line 108 of file location_maps.C.

00109 {
00110   return node;
00111 }

template<typename T>
Point libMesh::LocationMap< T >::point_of ( const T &   )  const

Member Data Documentation

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

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

Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:28 UTC

Hosted By:
SourceForge.net Logo