Hi Corbin,

Just add such a hash function for Point.

In case you haven't yet done this, I've dug out an old snippet of code that implements a reliable hash function for the point class. I used this approach successfully when implementing some exotic constraints manager, so hopefully it would suit your purposes too.

template<intspacedim>
structPointHashFunc
{
std::size_t
operator()(constdealii::Point<spacedim>&p) const
{
std::size_th;
h =std::hash<double>()(p[0]);
if(spacedim >1)
{
std::size_th2 =std::hash<double>()(p[1]);
h =h ^(h2 <<1);
}
if(spacedim >2)
{
size_th3 =std::hash<double>()(p[2]);
h =h ^h3;
}
if(spacedim >3)
{
AssertThrow(false, ExcNotImplemented());
}
returnh;
}
};// struct PointHashFunc
template<intspacedim, typenameT>
usingPointMap=
std::unordered_map<dealii::Point<spacedim>, T, PointHashFunc<spacedim>>;

Best,
Jean-Paul

On 06.02.21 22:15, Wolfgang Bangerth wrote:
On 2/6/21 1:55 PM, Corbin Foucart wrote:

The compiler is rightly complaining that there isn't a hash method for the Point object, and it seems like this could indeed be dangerous, because of floating point comparison later between Point objects during lookup.

Just add such a hash function for Point. It's true that two nearby points will have different hash values, but that shouldn't stop you from using hashes if you query the same points over and over.

That said, I would suggest to do the indexing not on geometric locations but the logic position of a cell. You can either do that with a cell iterator itself, or if you want to make it work in a parallel context, the CellId of a cell.

Best
 W.



--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/910a7400-ecd9-4d9e-b76b-db83370fc0d6%40gmail.com.

Reply via email to