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

◆ 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 184 of file location_maps.C.

185{
186 // Populate the nodes map
187 for (auto & node : mesh.node_ptr_range())
188 this->insert(*node);
189}
MeshBase & mesh

References mesh.

◆ fill() [3/3]

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

Definition at line 194 of file location_maps.C.

195{
196 // Populate the elem map
197 for (auto & elem : mesh.active_element_ptr_range())
198 this->insert(*elem);
199}

References mesh.

◆ find()

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

Definition at line 112 of file location_maps.C.

114{
115 LOG_SCOPE("find()", "LocationMap");
116
117 // Look for a likely key in the multimap
118 unsigned int pointkey = this->key(p);
119
120 // Look for the exact key first
121 for (const auto & pr : as_range(_map.equal_range(pointkey)))
122 if (p.absolute_fuzzy_equals(this->point_of(*(pr.second)), tol))
123 return pr.second;
124
125 // Look for neighboring bins' keys next
126 for (int xoffset = -1; xoffset != 2; ++xoffset)
127 {
128 for (int yoffset = -1; yoffset != 2; ++yoffset)
129 {
130 for (int zoffset = -1; zoffset != 2; ++zoffset)
131 {
132 auto key_pos = _map.equal_range(pointkey +
133 xoffset*chunkmax*chunkmax +
134 yoffset*chunkmax +
135 zoffset);
136 for (const auto & pr : as_range(key_pos))
137 if (p.absolute_fuzzy_equals(this->point_of(*(pr.second)), tol))
138 return pr.second;
139 }
140 }
141 }
142
143 return nullptr;
144}
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 47 of file location_maps.C.

48{
49 // This function must be run on all processors at once
50 // for non-serial meshes
51 if (!mesh.is_serial())
52 libmesh_parallel_only(mesh.comm());
53
54 LOG_SCOPE("init()", "LocationMap");
55
56 // Clear the old map
57 _map.clear();
58
59 // Cache a bounding box
60 _lower_bound.clear();
61 _lower_bound.resize(LIBMESH_DIM, std::numeric_limits<Real>::max());
62 _upper_bound.clear();
63 _upper_bound.resize(LIBMESH_DIM, -std::numeric_limits<Real>::max());
64
65 for (auto & node : mesh.node_ptr_range())
66 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
67 {
68 // Expand the bounding box if necessary
69 _lower_bound[i] = std::min(_lower_bound[i],
70 (*node)(i));
71 _upper_bound[i] = std::max(_upper_bound[i],
72 (*node)(i));
73 }
74
75 // On a parallel mesh we might not yet have a full bounding box
76 if (!mesh.is_serial())
77 {
78 mesh.comm().min(_lower_bound);
79 mesh.comm().max(_upper_bound);
80 }
81
82 this->fill(mesh);
83}
void ErrorVector unsigned int
std::vector< Real > _upper_bound
std::vector< Real > _lower_bound
void fill(MeshBase &)

References libMesh::ParallelObject::comm(), libMesh::MeshBase::is_serial(), libMesh::Parallel::Communicator::max(), mesh, and libMesh::Parallel::Communicator::min().

Referenced by ParallelGhostSyncTest::testByXYZ().

◆ insert()

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

Definition at line 88 of file location_maps.C.

89{
90 this->_map.emplace(this->key(this->point_of(t)), &t);
91}

◆ key()

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

Definition at line 149 of file location_maps.C.

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

105{
106 return elem.vertex_average();
107}

References libMesh::Elem::vertex_average().

◆ point_of() [2/3]

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

Definition at line 96 of file location_maps.C.

97{
98 return node;
99}

◆ point_of() [3/3]

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

Member Data Documentation

◆ _lower_bound

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

Definition at line 77 of file location_maps.h.

◆ _map

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

◆ _upper_bound

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: