mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: new bitSet class and improved PackedList class (closes #751)
- The bitSet class replaces the old PackedBoolList class.
The redesign provides better block-wise access and reduced method
calls. This helps both in cases where the bitSet may be relatively
sparse, and in cases where advantage of contiguous operations can be
made. This makes it easier to work with a bitSet as top-level object.
In addition to the previously available count() method to determine
if a bitSet is being used, now have simpler queries:
- all() - true if all bits in the addressable range are empty
- any() - true if any bits are set at all.
- none() - true if no bits are set.
These are faster than count() and allow early termination.
The new test() method tests the value of a single bit position and
returns a bool without any ambiguity caused by the return type
(like the get() method), nor the const/non-const access (like
operator[] has). The name corresponds to what std::bitset uses.
The new find_first(), find_last(), find_next() methods provide a faster
means of searching for bits that are set.
This can be especially useful when using a bitSet to control an
conditional:
OLD (with macro):
forAll(selected, celli)
{
if (selected[celli])
{
sumVol += mesh_.cellVolumes()[celli];
}
}
NEW (with const_iterator):
for (const label celli : selected)
{
sumVol += mesh_.cellVolumes()[celli];
}
or manually
for
(
label celli = selected.find_first();
celli != -1;
celli = selected.find_next()
)
{
sumVol += mesh_.cellVolumes()[celli];
}
- When marking up contiguous parts of a bitset, an interval can be
represented more efficiently as a labelRange of start/size.
For example,
OLD:
if (isA<processorPolyPatch>(pp))
{
forAll(pp, i)
{
ignoreFaces.set(i);
}
}
NEW:
if (isA<processorPolyPatch>(pp))
{
ignoreFaces.set(pp.range());
}
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -97,10 +97,10 @@ int main(int argc, char *argv[])
|
||||
label nPatchFaces = 0;
|
||||
label nPatchEdges = 0;
|
||||
|
||||
forAllConstIter(labelHashSet, patchSet, iter)
|
||||
for (const label patchi : patchSet)
|
||||
{
|
||||
nPatchFaces += mesh.boundaryMesh()[iter.key()].size();
|
||||
nPatchEdges += mesh.boundaryMesh()[iter.key()].nEdges();
|
||||
nPatchFaces += mesh.boundaryMesh()[patchi].size();
|
||||
nPatchEdges += mesh.boundaryMesh()[patchi].nEdges();
|
||||
}
|
||||
|
||||
// Construct from estimate for the number of cells to refine
|
||||
@ -111,15 +111,13 @@ int main(int argc, char *argv[])
|
||||
DynamicList<scalar> allCutEdgeWeights(nPatchEdges);
|
||||
|
||||
// Find cells to refine
|
||||
forAllConstIter(labelHashSet, patchSet, iter)
|
||||
for (const label patchi : patchSet)
|
||||
{
|
||||
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
|
||||
const polyPatch& pp = mesh.boundaryMesh()[patchi];
|
||||
const labelList& meshPoints = pp.meshPoints();
|
||||
|
||||
forAll(meshPoints, pointi)
|
||||
for (const label meshPointi : meshPoints)
|
||||
{
|
||||
label meshPointi = meshPoints[pointi];
|
||||
|
||||
const labelList& pCells = mesh.pointCells()[meshPointi];
|
||||
|
||||
cutCells.insertMany(pCells);
|
||||
@ -139,49 +137,43 @@ int main(int argc, char *argv[])
|
||||
<< cells.instance()/cells.local()/cells.name()
|
||||
<< nl << endl;
|
||||
|
||||
forAllConstIter(cellSet, cells, iter)
|
||||
for (const label celli : cells)
|
||||
{
|
||||
cutCells.erase(iter.key());
|
||||
cutCells.erase(celli);
|
||||
}
|
||||
Info<< "Removed from cells to cut all the ones not in set "
|
||||
<< setName << nl << endl;
|
||||
}
|
||||
|
||||
// Mark all mesh points on patch
|
||||
boolList vertOnPatch(mesh.nPoints(), false);
|
||||
bitSet vertOnPatch(mesh.nPoints());
|
||||
|
||||
forAllConstIter(labelHashSet, patchSet, iter)
|
||||
for (const label patchi : patchSet)
|
||||
{
|
||||
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
|
||||
const polyPatch& pp = mesh.boundaryMesh()[patchi];
|
||||
const labelList& meshPoints = pp.meshPoints();
|
||||
|
||||
forAll(meshPoints, pointi)
|
||||
{
|
||||
vertOnPatch[meshPoints[pointi]] = true;
|
||||
}
|
||||
vertOnPatch.setMany(meshPoints);
|
||||
}
|
||||
|
||||
forAllConstIter(labelHashSet, patchSet, iter)
|
||||
for (const label patchi : patchSet)
|
||||
{
|
||||
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
|
||||
const polyPatch& pp = mesh.boundaryMesh()[patchi];
|
||||
const labelList& meshPoints = pp.meshPoints();
|
||||
|
||||
forAll(meshPoints, pointi)
|
||||
for (const label meshPointi : meshPoints)
|
||||
{
|
||||
label meshPointi = meshPoints[pointi];
|
||||
|
||||
const labelList& pEdges = mesh.pointEdges()[meshPointi];
|
||||
|
||||
forAll(pEdges, pEdgeI)
|
||||
for (const label edgei : pEdges)
|
||||
{
|
||||
const label edgeI = pEdges[pEdgeI];
|
||||
const edge& e = mesh.edges()[edgeI];
|
||||
const edge& e = mesh.edges()[edgei];
|
||||
|
||||
label otherPointi = e.otherVertex(meshPointi);
|
||||
|
||||
if (!vertOnPatch[otherPointi])
|
||||
if (!vertOnPatch.test(otherPointi))
|
||||
{
|
||||
allCutEdges.append(edgeI);
|
||||
allCutEdges.append(edgei);
|
||||
|
||||
if (e.start() == meshPointi)
|
||||
{
|
||||
@ -214,7 +206,7 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
mesh,
|
||||
cutCells.toc(), // cells candidate for cutting
|
||||
labelList(0), // cut vertices
|
||||
labelList(), // cut vertices
|
||||
allCutEdges, // cut edges
|
||||
cutEdgeWeights // weight on cut edges
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user