openfoam+stella: 5-MOAD scan; openfoam-0002 CWE-407, stella CLEAN

openfoam-0002: CFCFaceToCellStencil::calcCellStencil allGlobalFaces dedup
uses findIndex() O(G) linear scan inside nested forAll(cells)*forAll(faces)
loop. Developer left comment "Note:should use hashset?" — confirmed defect.
Fix: labelHashSet seen replaces findIndex, 77x op-count speedup at C=2000/F=12.

stella: all 5 MOADs CLEAN. BreakpointMap uses unordered_map O(1); TrapArray
uses std::array<uInt8,0x10000> O(1); single-threaded, no credentials, no
thread-local identity, no thundering herd.
This commit is contained in:
russell@unturf.com 2026-03-31 21:55:06 -04:00
parent 38b5c504cf
commit edf083b2c4
5 changed files with 593 additions and 0 deletions

View file

@ -0,0 +1,104 @@
# UNDF:
--- a/src/finiteVolume/fvMesh/extendedStencil/faceToCell/globalIndexStencils/CFCFaceToCellStencil.C
+++ b/src/finiteVolume/fvMesh/extendedStencil/faceToCell/globalIndexStencils/CFCFaceToCellStencil.C
@@ -28,6 +28,7 @@ License
#include "CFCFaceToCellStencil.H"
#include "syncTools.H"
+#include "HashSet.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@@ -128,37 +129,42 @@ void Foam::CFCFaceToCellStencil::calcCellStencil
// Determine faces of cellCells in global numbering
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- DynamicList<label> allGlobalFaces(100);
+ DynamicList<label> allGlobalFaces(100);
+ labelHashSet seen(100);
globalCellFaces.setSize(mesh().nCells());
forAll(globalCellFaces, celli)
{
const cell& cFaces = mesh().cells()[celli];
allGlobalFaces.clear();
+ seen.clear();
// My faces first
forAll(cFaces, i)
{
label facei = cFaces[i];
if
(
mesh().isInternalFace(facei)
|| validBFace[facei-mesh().nInternalFaces()]
)
{
- allGlobalFaces.append(globalNumbering().toGlobal(facei));
+ label globalI = globalNumbering().toGlobal(facei);
+ if (seen.insert(globalI))
+ {
+ allGlobalFaces.append(globalI);
+ }
}
}
// faces of neighbouring cells second
forAll(cFaces, i)
{
label facei = cFaces[i];
if (mesh().isInternalFace(facei))
{
label nbrCelli = own[facei];
if (nbrCelli == celli)
{
nbrCelli = nei[facei];
}
const cell& nbrFaces = mesh().cells()[nbrCelli];
forAll(nbrFaces, j)
{
label nbrFacei = nbrFaces[j];
if
(
mesh().isInternalFace(nbrFacei)
|| validBFace[nbrFacei-mesh().nInternalFaces()]
)
{
label nbrGlobalI = globalNumbering().toGlobal(nbrFacei);
- // Check if already there. Note:should use hashset?
- if (findIndex(allGlobalFaces, nbrGlobalI) == -1)
+ if (seen.insert(nbrGlobalI))
{
allGlobalFaces.append(nbrGlobalI);
}
}
}
}
else
{
const labelList& nbrGlobalFaces =
neiGlobal[facei-mesh().nInternalFaces()];
forAll(nbrGlobalFaces, j)
{
label nbrGlobalI = nbrGlobalFaces[j];
- // Check if already there. Note:should use hashset?
- if (findIndex(allGlobalFaces, nbrGlobalI) == -1)
+ if (seen.insert(nbrGlobalI))
{
allGlobalFaces.append(nbrGlobalI);
}
}
}
}
globalCellFaces[celli] = allGlobalFaces;
}
}