libMesh
Loading...
Searching...
No Matches
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
 
Point point_of (const Node &node) const
 
Point point_of (const Elem &elem) const
 

Protected Member Functions

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

Private Types

typedef std::unordered_multimap< unsigned int, T * > map_type
 

Private Attributes

map_type _map
 
BoundingBox _bbox
 

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

◆ map_type

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

◆ clear()

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

Definition at line 59 of file location_maps.h.

59{ _map.clear(); }

References libMesh::LocationMap< T >::_map.

◆ empty()

template<typename T >
bool libMesh::LocationMap< T >::empty ( ) const
inline

Definition at line 63 of file location_maps.h.

63{ return _map.empty(); }

References libMesh::LocationMap< T >::_map.

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

◆ fill() [1/3]

template<typename T >
void libMesh::LocationMap< T >::fill ( MeshBase &  )
protected

◆ fill() [2/3]

void libMesh::LocationMap< Node >::fill ( MeshBase &  mesh)
protected

Definition at line 165 of file location_maps.C.

166{
167 // Populate the nodes map
168 for (auto & node : mesh.node_ptr_range())
169 this->insert(*node);
170}
MeshBase & mesh

References mesh.

◆ fill() [3/3]

void libMesh::LocationMap< Elem >::fill ( MeshBase &  mesh)
protected

Definition at line 175 of file location_maps.C.

176{
177 // Populate the elem map
178 for (auto & elem : mesh.active_element_ptr_range())
179 this->insert(*elem);
180}

References mesh.

◆ find()

template<typename T >
T * libMesh::LocationMap< T >::find ( const Point &  p,
const Real  tol = TOLERANCE 
)

Definition at line 93 of file location_maps.C.

95{
96 LOG_SCOPE("find()", "LocationMap");
97
98 // Look for a likely key in the multimap
99 unsigned int pointkey = this->key(p);
100
101 // Look for the exact key first
102 for (const auto & pr : as_range(_map.equal_range(pointkey)))
103 if (p.absolute_fuzzy_equals(this->point_of(*(pr.second)), tol))
104 return pr.second;
105
106 // Look for neighboring bins' keys next
107 for (int xoffset = -1; xoffset != 2; ++xoffset)
108 {
109 for (int yoffset = -1; yoffset != 2; ++yoffset)
110 {
111 for (int zoffset = -1; zoffset != 2; ++zoffset)
112 {
113 auto key_pos = _map.equal_range(pointkey +
114 xoffset*chunkmax*chunkmax +
115 yoffset*chunkmax +
116 zoffset);
117 for (const auto & pr : as_range(key_pos))
118 if (p.absolute_fuzzy_equals(this->point_of(*(pr.second)), tol))
119 return pr.second;
120 }
121 }
122 }
123
124 return nullptr;
125}
Point point_of(const T &) const
unsigned int key(const Point &)
bool absolute_fuzzy_equals(const T &var1, const T2 &var2, const Real tol=TOLERANCE *TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.

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

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

◆ init()

template<typename T >
void libMesh::LocationMap< T >::init ( MeshBase &  mesh)

Definition at line 48 of file location_maps.C.

49{
50 // This function must be run on all processors at once
51 // for non-serial meshes
52 if (!mesh.is_serial())
53 libmesh_parallel_only(mesh.comm());
54
55 LOG_SCOPE("init()", "LocationMap");
56
57 // Clear the old map
58 _map.clear();
59
60 // Cache a bounding box
62
63 this->fill(mesh);
64}
void fill(MeshBase &)
libMesh::BoundingBox create_nodal_bounding_box(const MeshBase &mesh)
Definition mesh_tools.C:655

References libMesh::ParallelObject::comm(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshBase::is_serial(), and mesh.

Referenced by ParallelGhostSyncTest::testByXYZ().

◆ insert()

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

Definition at line 69 of file location_maps.C.

70{
71 this->_map.emplace(this->key(this->point_of(t)), &t);
72}

◆ key()

template<typename T >
unsigned int libMesh::LocationMap< T >::key ( const Point &  p)
protected

Definition at line 130 of file location_maps.C.

131{
132 Real xscaled = 0., yscaled = 0., zscaled = 0.;
133
134 const Real deltax = _bbox.max()(0) - _bbox.min()(0);
135
136 if (std::abs(deltax) > TOLERANCE)
137 xscaled = (p(0) - _bbox.min()(0))/deltax;
138
139 // Only check y-coords if libmesh is compiled with LIBMESH_DIM>1
140#if LIBMESH_DIM > 1
141 const Real deltay = _bbox.max()(1) - _bbox.min()(1);
142
143 if (std::abs(deltay) > TOLERANCE)
144 yscaled = (p(1) - _bbox.min()(1))/deltay;
145#endif
146
147 // Only check z-coords if libmesh is compiled with LIBMESH_DIM>2
148#if LIBMESH_DIM > 2
149 const Real deltaz = _bbox.max()(2) - _bbox.min()(2);
150
151 if (std::abs(deltaz) > TOLERANCE)
152 zscaled = (p(2) - _bbox.min()(2))/deltaz;
153#endif
154
155 unsigned int n0 = static_cast<unsigned int> (chunkfloat * xscaled),
156 n1 = static_cast<unsigned int> (chunkfloat * yscaled),
157 n2 = static_cast<unsigned int> (chunkfloat * zscaled);
158
159 return chunkmax*chunkmax*n0 + chunkmax*n1 + n2;
160}
const Point & max() const
const Point & min() const
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::Real, and libMesh::TOLERANCE.

◆ point_of() [1/3]

Point libMesh::LocationMap< Elem >::point_of ( const Elem &  elem) const

Definition at line 85 of file location_maps.C.

86{
87 return elem.vertex_average();
88}

References libMesh::Elem::vertex_average().

◆ point_of() [2/3]

Point libMesh::LocationMap< Node >::point_of ( const Node &  node) const

Definition at line 77 of file location_maps.C.

78{
79 return node;
80}

◆ point_of() [3/3]

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

Member Data Documentation

◆ _bbox

template<typename T >
BoundingBox libMesh::LocationMap< T >::_bbox
private

Definition at line 77 of file location_maps.h.

◆ _map

template<typename T >
map_type libMesh::LocationMap< T >::_map
private

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