https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | List of all members
PointIndexedMap Struct Reference

An unordered map indexed by Point, eg 3 floating point numbers Because floating point rounding errors can affect the hashing, eg the binning of values, we may need to look near a Point/key for where the initial value was stored. More...

#include <PointIndexedMap.h>

Classes

struct  hash_point
 

Public Member Functions

 PointIndexedMap (const Point &mesh_max_coords)
 
Point getRoundedPoint (const Point &p) const
 Normalize, expand then round a point to create local bins.
 
Number & operator[] (Point p)
 
unsigned int hasKey (Point p)
 
std::unordered_map< Point, Number, hash_point >::const_iterator find (const Point &pt) const
 
bool attempt_find (const Point &p, Real dx, Real dy, Real dz, std::unordered_map< Point, Number, hash_point >::const_iterator &out) const
 
std::unordered_map< Point, Number, hash_point >::const_iterator end () const
 

Public Attributes

std::unordered_map< Point, Number, hash_pointbase_map
 The container indexed by points.
 
Point normalization
 Normalization factors used to scale points before insertions/comparisons.
 

Detailed Description

An unordered map indexed by Point, eg 3 floating point numbers Because floating point rounding errors can affect the hashing, eg the binning of values, we may need to look near a Point/key for where the initial value was stored.

Definition at line 19 of file PointIndexedMap.h.

Constructor & Destructor Documentation

◆ PointIndexedMap()

PointIndexedMap::PointIndexedMap ( const Point &  mesh_max_coords)
inline

Definition at line 21 of file PointIndexedMap.h.

22 {
23 for (auto i : make_range(Moose::dim))
24 normalization(i) =
25 MooseUtils::absoluteFuzzyEqual(mesh_max_coords(i), 0) ? 1 : mesh_max_coords(i);
26 }
unsigned int dim
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
IntRange< T > make_range(T beg, T end)
Point normalization
Normalization factors used to scale points before insertions/comparisons.

Member Function Documentation

◆ attempt_find()

bool PointIndexedMap::attempt_find ( const Point &  p,
Real  dx,
Real  dy,
Real  dz,
std::unordered_map< Point, Number, hash_point >::const_iterator &  out 
) const
inline

Definition at line 117 of file PointIndexedMap.h.

122 {
123 // Some epsilon to move the point by.
124 // There is no multiplicative epsilon that will reliably change the last decimal
125 const auto eps = 1e-13;
126 const auto shifted_rp = getRoundedPoint(p + Point(dx * eps * normalization(0),
127 dy * eps * normalization(1),
128 dz * eps * normalization(2)));
129 out = base_map.find(shifted_rp);
130 if (out != base_map.end())
131 return true;
132 return false;
133 }
int eps(unsigned int i, unsigned int j)
2D version
OStreamProxy out(std::cout)
std::unordered_map< Point, Number, hash_point > base_map
The container indexed by points.
Point getRoundedPoint(const Point &p) const
Normalize, expand then round a point to create local bins.

Referenced by find().

◆ end()

std::unordered_map< Point, Number, hash_point >::const_iterator PointIndexedMap::end ( ) const
inline

◆ find()

std::unordered_map< Point, Number, hash_point >::const_iterator PointIndexedMap::find ( const Point &  pt) const
inline

Definition at line 89 of file PointIndexedMap.h.

90 {
91 const auto rp = getRoundedPoint(pt);
92
93 auto it = base_map.find(rp);
94 if (it != base_map.end())
95 return it;
96 else
97 {
98 // Search the point with coordinates rounded down to origin
99 auto rounded = base_map.find(rp);
100 if (rounded != base_map.end())
101 return rounded;
102
103 // To store the output of tentative searches
104 std::unordered_map<Point, Number, hash_point>::const_iterator out;
105
106 // Search in all directions around
107 for (int i : make_range(2))
108 for (int j : make_range(2))
109 for (int k : make_range(2))
110 if (attempt_find(pt, 2 * i - 1, 2 * j - 1, 2 * k - 1, out))
111 return out;
112
113 return base_map.end();
114 }
115 }
for(PetscInt i=0;i< nvars;++i)
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
void ErrorVector unsigned int
bool attempt_find(const Point &p, Real dx, Real dy, Real dz, std::unordered_map< Point, Number, hash_point >::const_iterator &out) const

Referenced by GeneralFieldTransfer::CachedData< Output >::eval_at_node(), GeneralFieldTransfer::CachedData< Output >::eval_at_point(), hasKey(), and operator[]().

◆ getRoundedPoint()

Point PointIndexedMap::getRoundedPoint ( const Point &  p) const
inline

Normalize, expand then round a point to create local bins.

  • normalize the point by dividing by the meshes max (non-zero) absolute coordinates
  • multiply the result by 1e12 and round, which keeps a fixed number of digits

Definition at line 33 of file PointIndexedMap.h.

34 {
35 // We cant support coordinates too far from the normalization point
36 mooseAssert(p(0) / normalization(0) < 1 && p(1) / normalization(1) < 1 &&
37 p(2) / normalization(2) < 1,
38 "Point coordinates for indexing must be normalized below 1. "
39 "Point: "
40 << p << " normalization: " << normalization);
41
42 std::vector<Real> rounded_p{round(p(0) / normalization(0) * pow(10, 12)),
43 round(p(1) / normalization(1) * pow(10, 12)),
44 round(p(2) / normalization(2) * pow(10, 12))};
45 return Point(rounded_p[0], rounded_p[1], rounded_p[2]);
46 }
T round(T x)
Definition MathUtils.h:77
T pow(const T &x)

Referenced by attempt_find(), find(), and operator[]().

◆ hasKey()

unsigned int PointIndexedMap::hasKey ( Point  p)
inline

Definition at line 80 of file PointIndexedMap.h.

81 {
82 auto it = find(p);
83 if (it != end())
84 return true;
85 else
86 return false;
87 }
std::unordered_map< Point, Number, hash_point >::const_iterator end() const
std::unordered_map< Point, Number, hash_point >::const_iterator find(const Point &pt) const

Referenced by MultiAppGeneralFieldTransfer::cacheIncomingInterpVals().

◆ operator[]()

Number & PointIndexedMap::operator[] ( Point  p)
inline

Definition at line 68 of file PointIndexedMap.h.

69 {
70 auto it = find(p);
71 if (it != end())
72 return const_cast<Number &>(it->second);
73 else
74 {
75 const auto rp = getRoundedPoint(p);
76 return base_map[rp];
77 }
78 }
Real Number

Member Data Documentation

◆ base_map

std::unordered_map<Point, Number, hash_point> PointIndexedMap::base_map

The container indexed by points.

Definition at line 63 of file PointIndexedMap.h.

Referenced by attempt_find(), end(), find(), and operator[]().

◆ normalization

Point PointIndexedMap::normalization

Normalization factors used to scale points before insertions/comparisons.

Definition at line 66 of file PointIndexedMap.h.

Referenced by attempt_find(), getRoundedPoint(), and PointIndexedMap().


The documentation for this struct was generated from the following file: