mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve hashing overloads of string-types and HashTable/HashSet
- additional dummy template parameter to assist with supporting
derived classes. Currently just used for string types, but can be
extended.
- provide hash specialization for various integer types.
Removes the need for any forwarding.
- change default hasher for HashSet/HashTable from 'string::hash'
to `Hash<Key>`. This avoids questionable hashing calls and/or
avoids compiler resolution problems.
For example,
HashSet<label>::hasher and labelHashSet::hasher now both properly
map to Hash<label> whereas previously HashSet<label> would have
persistently mapped to string::hash, which was incorrect.
- standardize internal hashing functors.
Functor name is 'hasher', as per STL set/map and the OpenFOAM
HashSet/HashTable definitions.
Older code had a local templated name, which added unnecessary
clutter and the template parameter was always defaulted.
For example,
Old: `FixedList<label, 3>::Hash<>()`
New: `FixedList<label, 3>::hasher()`
Unchanged: `labelHashSet::hasher()`
Existing `Hash<>` functor namings are still supported,
but deprecated.
- define hasher and Hash specialization for bitSet and PackedList
- add symmetric hasher for 'face'.
Starts with lowest vertex value and walks in the direction
of the next lowest value. This ensures that the hash code is
independent of face orientation and face rotation.
NB:
- some of keys for multiphase handling (eg, phasePairKey)
still use yet another function naming: `hash` and `symmHash`.
This will be targeted for alignment in the future.
This commit is contained in:
committed by
Andrew Heather
parent
b060378dca
commit
95cd8ee75c
@ -850,35 +850,39 @@ int main(int argc, char *argv[])
|
||||
Map<label> faceToCell[2];
|
||||
|
||||
{
|
||||
HashTable<label, face, face::Hash<>> faceToFaceID(boundaryFaces.size());
|
||||
forAll(boundaryFaces, facei)
|
||||
// Can use face::symmHasher or use sorted indices instead
|
||||
// - choose the latter in case UNV has anything odd
|
||||
HashTable<label, face> faceToFaceID(2*boundaryFaces.size());
|
||||
|
||||
forAll(boundaryFaces, bfacei)
|
||||
{
|
||||
SortableList<label> sortedVerts(boundaryFaces[facei]);
|
||||
faceToFaceID.insert(face(sortedVerts), facei);
|
||||
face sortedVerts(boundaryFaces[bfacei]);
|
||||
Foam::sort(sortedVerts);
|
||||
faceToFaceID.insert(sortedVerts, bfacei);
|
||||
}
|
||||
|
||||
forAll(cellVerts, celli)
|
||||
{
|
||||
faceList faces = cellVerts[celli].faces();
|
||||
forAll(faces, i)
|
||||
const cellShape& shape = cellVerts[celli];
|
||||
|
||||
for (const face& f : shape.faces())
|
||||
{
|
||||
SortableList<label> sortedVerts(faces[i]);
|
||||
const auto fnd = faceToFaceID.find(face(sortedVerts));
|
||||
|
||||
if (fnd.found())
|
||||
face sortedVerts(f);
|
||||
Foam::sort(sortedVerts);
|
||||
const label bfacei = faceToFaceID.lookup(sortedVerts, -1);
|
||||
if (bfacei != -1)
|
||||
{
|
||||
label facei = *fnd;
|
||||
int stat = face::compare(faces[i], boundaryFaces[facei]);
|
||||
const int cmp = face::compare(f, boundaryFaces[bfacei]);
|
||||
|
||||
if (stat == 1)
|
||||
if (cmp == 1)
|
||||
{
|
||||
// Same orientation. Cell is owner.
|
||||
own[facei] = celli;
|
||||
own[bfacei] = celli;
|
||||
}
|
||||
else if (stat == -1)
|
||||
else if (cmp == -1)
|
||||
{
|
||||
// Opposite orientation. Cell is neighbour.
|
||||
nei[facei] = celli;
|
||||
nei[bfacei] = celli;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -958,15 +962,13 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
const cellShape& shape = cellVerts[celli];
|
||||
|
||||
const faceList shapeFaces(shape.faces());
|
||||
|
||||
forAll(shapeFaces, i)
|
||||
for (const face& f : shape.faces())
|
||||
{
|
||||
label patchi = findPatch(dofGroups, shapeFaces[i]);
|
||||
label patchi = findPatch(dofGroups, f);
|
||||
|
||||
if (patchi != -1)
|
||||
{
|
||||
dynPatchFaces[patchi].append(shapeFaces[i]);
|
||||
dynPatchFaces[patchi].append(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ int main(int argc, char *argv[])
|
||||
label maxPatch = 0;
|
||||
|
||||
// Boundary faces as three vertices
|
||||
HashTable<label, triFace, triFace::Hash<>> vertsToBoundary(nFaces);
|
||||
HashTable<label, triFace> vertsToBoundary(nFaces);
|
||||
|
||||
forAll(boundaryFaces, facei)
|
||||
{
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2013-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -55,15 +56,15 @@ namespace Foam
|
||||
template<class Triangulation>
|
||||
class pointPairs
|
||||
:
|
||||
public HashSet<labelPairPair, labelPairPair::Hash<>>
|
||||
public HashSet<labelPairPair>
|
||||
{
|
||||
// Private typedefs
|
||||
// Private Typedefs
|
||||
|
||||
typedef HashSet<labelPairPair, labelPairPair::Hash<>> StorageContainer;
|
||||
typedef HashSet<labelPairPair> StorageContainer;
|
||||
typedef typename Triangulation::Vertex_handle Vertex_handle;
|
||||
|
||||
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
const Triangulation& triangulation_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user