mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: prefer emplace_back() to append() + last()
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -47,7 +47,7 @@ Description
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "cellSet.H"
|
||||
#include "SortableList.H"
|
||||
#include "SortList.H"
|
||||
#include "labelIOList.H"
|
||||
#include "fvMesh.H"
|
||||
#include "volFields.H"
|
||||
@ -128,71 +128,54 @@ int main(int argc, char *argv[])
|
||||
|
||||
const scalarField& vols = mesh.cellVolumes();
|
||||
|
||||
SortableList<scalar> sortedVols(vols);
|
||||
SortList<scalar> sortedVols(vols);
|
||||
|
||||
// All cell labels, sorted per bin.
|
||||
DynamicList<DynamicList<label>> bins;
|
||||
|
||||
// Lower/upper limits
|
||||
DynamicList<scalar> lowerLimits;
|
||||
DynamicList<scalar> upperLimits;
|
||||
DynamicList<scalarMinMax> limits;
|
||||
|
||||
// Create bin0. Have upperlimit as factor times lowerlimit.
|
||||
bins.append(DynamicList<label>());
|
||||
lowerLimits.append(sortedVols[0]);
|
||||
upperLimits.append(1.1 * lowerLimits.last());
|
||||
bins.emplace_back();
|
||||
limits.emplace_back(sortedVols[0], 1.1*sortedVols[0]);
|
||||
|
||||
forAll(sortedVols, i)
|
||||
{
|
||||
if (sortedVols[i] > upperLimits.last())
|
||||
if (sortedVols[i] > limits.back().max())
|
||||
{
|
||||
// New value outside of current bin
|
||||
|
||||
// Shrink old bin.
|
||||
DynamicList<label>& bin = bins.last();
|
||||
|
||||
bin.shrink();
|
||||
|
||||
Info<< "Collected " << bin.size() << " elements in bin "
|
||||
<< lowerLimits.last() << " .. "
|
||||
<< upperLimits.last() << endl;
|
||||
Info<< "Collected " << bins.back() << " elements in bin "
|
||||
<< limits.back().min() << " .. "
|
||||
<< limits.back().max() << endl;
|
||||
|
||||
// Create new bin.
|
||||
bins.append(DynamicList<label>());
|
||||
lowerLimits.append(sortedVols[i]);
|
||||
upperLimits.append(1.1 * lowerLimits.last());
|
||||
bins.emplace_back();
|
||||
limits.emplace_back(sortedVols[i], 1.1 * sortedVols[i]);
|
||||
|
||||
Info<< "Creating new bin " << lowerLimits.last()
|
||||
<< " .. " << upperLimits.last()
|
||||
<< endl;
|
||||
Info<< "Creating new bin "
|
||||
<< limits.back().min() << " .. "
|
||||
<< limits.back().max() << endl;
|
||||
}
|
||||
|
||||
// Append to current bin.
|
||||
DynamicList<label>& bin = bins.last();
|
||||
|
||||
bin.append(sortedVols.indices()[i]);
|
||||
// Add to current bin.
|
||||
bins.back().push_back(sortedVols.indices()[i]);
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
bins.last().shrink();
|
||||
bins.shrink();
|
||||
lowerLimits.shrink();
|
||||
upperLimits.shrink();
|
||||
|
||||
|
||||
//
|
||||
// Write to cellSets.
|
||||
//
|
||||
|
||||
Info<< "Volume bins:" << nl;
|
||||
forAll(bins, binI)
|
||||
forAll(bins, bini)
|
||||
{
|
||||
const DynamicList<label>& bin = bins[binI];
|
||||
const auto& bin = bins[bini];
|
||||
|
||||
cellSet cells(mesh, "vol" + name(binI), bin.size());
|
||||
cellSet cells(mesh, "vol" + Foam::name(bini), bin.size());
|
||||
cells.insert(bin);
|
||||
|
||||
Info<< " " << lowerLimits[binI] << " .. " << upperLimits[binI]
|
||||
Info<< " " << limits[bini].min() << " .. " << limits[bini].max()
|
||||
<< " : writing " << bin.size() << " cells to cellSet "
|
||||
<< cells.name() << endl;
|
||||
|
||||
@ -294,13 +277,13 @@ int main(int argc, char *argv[])
|
||||
);
|
||||
|
||||
// Set cell values
|
||||
forAll(bins, binI)
|
||||
forAll(bins, bini)
|
||||
{
|
||||
const DynamicList<label>& bin = bins[binI];
|
||||
const auto& bin = bins[bini];
|
||||
|
||||
forAll(bin, i)
|
||||
{
|
||||
refLevel[bin[i]] = bins.size() - binI - 1;
|
||||
refLevel[bin[i]] = bins.size() - bini - 1;
|
||||
postRefLevel[bin[i]] = refLevel[bin[i]];
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,21 +148,15 @@ void matchPatchFaces
|
||||
// Mesh 0
|
||||
//~~~~~~~
|
||||
|
||||
interfaceMesh0.append(labelList());
|
||||
auto& intMesh0 = interfaceMesh0.last();
|
||||
intMesh0.setSize(nSourcei, -1);
|
||||
auto& intMesh0 = interfaceMesh0.emplace_back(nSourcei, -1);
|
||||
intMesh0[sourcei] = meshi;
|
||||
|
||||
interfaceSource0.append(sourcei);
|
||||
interfaceSource0.push_back(sourcei);
|
||||
|
||||
interfacePatch0.append(labelList());
|
||||
auto& intPatch0 = interfacePatch0.last();
|
||||
intPatch0.setSize(nSourcei, -1);
|
||||
auto& intPatch0 = interfacePatch0.emplace_back(nSourcei, -1);
|
||||
intPatch0[sourcei] = ppi.index();
|
||||
|
||||
interfaceNames0.append(wordList());
|
||||
auto& intNames0 = interfaceNames0.last();
|
||||
intNames0.setSize(nSourcei);
|
||||
auto& intNames0 = interfaceNames0.emplace_back(nSourcei);
|
||||
intNames0[sourcei] =
|
||||
patchName(entryName, meshes[meshi], meshes[meshj]);
|
||||
|
||||
@ -170,33 +164,23 @@ void matchPatchFaces
|
||||
// Mesh 1
|
||||
//~~~~~~~
|
||||
|
||||
interfaceMesh1.append(labelList());
|
||||
auto& intMesh1 = interfaceMesh1.last();
|
||||
intMesh1.setSize(nSourcej, -1);
|
||||
auto& intMesh1 = interfaceMesh1.emplace_back(nSourcej, -1);
|
||||
intMesh1[sourcej] = meshj;
|
||||
|
||||
interfaceSource1.append(sourcej);
|
||||
interfaceSource1.push_back(sourcej);
|
||||
|
||||
interfacePatch1.append(labelList());
|
||||
auto& intPatch1 = interfacePatch1.last();
|
||||
intPatch1.setSize(nSourcej, -1);
|
||||
auto& intPatch1 = interfacePatch1.emplace_back(nSourcej, -1);
|
||||
intPatch1[sourcej] = ppj.index();
|
||||
|
||||
interfaceNames1.append(wordList());
|
||||
auto& intNames1 = interfaceNames1.last();
|
||||
intNames1.setSize(nSourcej);
|
||||
auto& intNames1 = interfaceNames1.emplace_back(nSourcej);
|
||||
intNames1[sourcej] =
|
||||
patchName(entryName, meshes[meshj], meshes[meshi]);
|
||||
|
||||
interfaceFaces0.append(List<DynamicList<label>>());
|
||||
auto& intFaces0 = interfaceFaces0.last();
|
||||
intFaces0.setSize(nSourcei);
|
||||
auto& intFaces0 = interfaceFaces0.emplace_back(nSourcei);
|
||||
DynamicList<label>& faces0 = intFaces0[sourcei];
|
||||
faces0.setCapacity(ppi.size());
|
||||
|
||||
interfaceFaces1.append(List<DynamicList<label>>());
|
||||
auto& intFaces1 = interfaceFaces1.last();
|
||||
intFaces1.setSize(nSourcej);
|
||||
auto& intFaces1 = interfaceFaces1.emplace_back(nSourcej);
|
||||
DynamicList<label>& faces1 = intFaces1[sourcej];
|
||||
faces1.setCapacity(ppj.size());
|
||||
|
||||
@ -249,7 +233,7 @@ void matchPatchFaces
|
||||
{
|
||||
if (weights[facei] > 0.5 || sourceMask[facei] > SMALL)
|
||||
{
|
||||
faces0.append(ppi.start()+facei);
|
||||
faces0.push_back(ppi.start()+facei);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -259,7 +243,7 @@ void matchPatchFaces
|
||||
{
|
||||
if (weights[facei] > 0.5 || targetMask[facei] > SMALL)
|
||||
{
|
||||
faces1.append(ppj.start()+facei);
|
||||
faces1.push_back(ppj.start()+facei);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -825,7 +809,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (pDict.get<word>("constructFrom") == "autoPatch")
|
||||
{
|
||||
interRegionSources[meshi].append(sourcei);
|
||||
interRegionSources[meshi].push_back(sourcei);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -1810,9 +1810,7 @@ bool Foam::hexRef8::matchHexShape
|
||||
{
|
||||
reverse(verts);
|
||||
}
|
||||
quads.append(face(0));
|
||||
labelList& quadVerts = quads.last();
|
||||
quadVerts.transfer(verts);
|
||||
quads.emplace_back(verts);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1891,9 +1889,7 @@ bool Foam::hexRef8::matchHexShape
|
||||
|
||||
if (verts.size() == 4)
|
||||
{
|
||||
quads.append(face(0));
|
||||
labelList& quadVerts = quads.last();
|
||||
quadVerts.transfer(verts);
|
||||
quads.emplace_back(verts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2372,6 +2368,8 @@ Foam::labelList Foam::hexRef8::consistentSlowRefinement
|
||||
|
||||
const refinementData& ownData = allCellInfo[faceOwner[facei]];
|
||||
|
||||
label maxDataCount = ownData.count();
|
||||
|
||||
if (mesh_.isInternalFace(facei))
|
||||
{
|
||||
// Seed face if neighbouring cell (after possible refinement)
|
||||
@ -2379,46 +2377,18 @@ Foam::labelList Foam::hexRef8::consistentSlowRefinement
|
||||
|
||||
const refinementData& neiData = allCellInfo[faceNeighbour[facei]];
|
||||
|
||||
label faceCount;
|
||||
label faceRefineCount;
|
||||
if (neiData.count() > ownData.count())
|
||||
if (maxDataCount < neiData.count())
|
||||
{
|
||||
faceCount = neiData.count() + maxFaceDiff;
|
||||
faceRefineCount = faceCount + maxFaceDiff;
|
||||
maxDataCount = neiData.count();
|
||||
}
|
||||
else
|
||||
{
|
||||
faceCount = ownData.count() + maxFaceDiff;
|
||||
faceRefineCount = faceCount + maxFaceDiff;
|
||||
}
|
||||
|
||||
seedFaces.append(facei);
|
||||
seedFacesInfo.append
|
||||
(
|
||||
refinementData
|
||||
(
|
||||
faceRefineCount,
|
||||
faceCount
|
||||
)
|
||||
);
|
||||
allFaceInfo[facei] = seedFacesInfo.last();
|
||||
}
|
||||
else
|
||||
{
|
||||
label faceCount = ownData.count() + maxFaceDiff;
|
||||
label faceRefineCount = faceCount + maxFaceDiff;
|
||||
|
||||
seedFaces.append(facei);
|
||||
seedFacesInfo.append
|
||||
(
|
||||
refinementData
|
||||
(
|
||||
faceRefineCount,
|
||||
faceCount
|
||||
)
|
||||
);
|
||||
allFaceInfo[facei] = seedFacesInfo.last();
|
||||
}
|
||||
label faceCount = maxDataCount + maxFaceDiff;
|
||||
label faceRefineCount = faceCount + maxFaceDiff;
|
||||
|
||||
seedFaces.push_back(facei);
|
||||
allFaceInfo[facei] =
|
||||
seedFacesInfo.emplace_back(faceRefineCount, faceCount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -32,11 +32,11 @@ License
|
||||
template<class Type>
|
||||
Type& Foam::glTF::List<Type>::create(const word& name)
|
||||
{
|
||||
Type obj(name);
|
||||
obj.id() = data_.size();
|
||||
data_.append(obj);
|
||||
const label id = data_.size();
|
||||
Type& obj = data_.emplace_back(name);
|
||||
obj.id() = id;
|
||||
|
||||
return data_.last();
|
||||
return data_.back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -250,12 +250,7 @@ Foam::CollisionRecordList<PairType, WallType>::matchPairRecord
|
||||
// member of the list. Setting the status of the record to be accessed
|
||||
// on construction.
|
||||
|
||||
pairRecords_.append
|
||||
(
|
||||
PairCollisionRecord<PairType>(true, origProcOfOther, origIdOfOther)
|
||||
);
|
||||
|
||||
return pairRecords_.last();
|
||||
return pairRecords_.emplace_back(true, origProcOfOther, origIdOfOther);
|
||||
}
|
||||
|
||||
|
||||
@ -307,9 +302,7 @@ Foam::CollisionRecordList<PairType, WallType>::matchWallRecord
|
||||
// member of the list. Setting the status of the record to be accessed
|
||||
// on construction.
|
||||
|
||||
wallRecords_.append(WallCollisionRecord<WallType>(true, pRel));
|
||||
|
||||
return wallRecords_.last();
|
||||
return wallRecords_.emplace_back(true, pRel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -245,9 +245,9 @@ public:
|
||||
autoPtr<sampledSet> operator()(Istream& is) const
|
||||
{
|
||||
word name(is);
|
||||
capture_.append(dictionary(is));
|
||||
dictionary& dict = capture_.emplace_back(is);
|
||||
|
||||
return sampledSet::New(name, mesh_, search_, capture_.last());
|
||||
return sampledSet::New(name, mesh_, search_, dict);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -225,9 +225,9 @@ public:
|
||||
autoPtr<sampledSurface> operator()(Istream& is) const
|
||||
{
|
||||
word name(is);
|
||||
capture_.append(dictionary(is));
|
||||
dictionary& dict = capture_.emplace_back(is);
|
||||
|
||||
return sampledSurface::New(name, mesh_, capture_.last());
|
||||
return sampledSurface::New(name, mesh_, dict);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -801,8 +801,7 @@ void Foam::isoSurfaceTopo::triangulateOutside
|
||||
{
|
||||
if (loop.size() > 2)
|
||||
{
|
||||
compactFaces.append(face(loop.size()));
|
||||
face& f = compactFaces.last();
|
||||
face& f = compactFaces.emplace_back(loop.size());
|
||||
|
||||
label fpi = 0;
|
||||
forAll(f, i)
|
||||
@ -1072,7 +1071,7 @@ Foam::isoSurfaceTopo::isoSurfaceTopo
|
||||
);
|
||||
}
|
||||
}
|
||||
startTri.last() = tetCutAddr.nFaces();
|
||||
startTri.back() = tetCutAddr.nFaces();
|
||||
|
||||
// Information not needed anymore:
|
||||
tetBasePtIs.clear();
|
||||
@ -1080,7 +1079,7 @@ Foam::isoSurfaceTopo::isoSurfaceTopo
|
||||
|
||||
|
||||
// From list of vertices -> triangular faces
|
||||
faceList allTriFaces(startTri.last());
|
||||
faceList allTriFaces(startTri.back());
|
||||
{
|
||||
auto& verts = tetCutAddr.cutPoints();
|
||||
|
||||
@ -1097,7 +1096,7 @@ Foam::isoSurfaceTopo::isoSurfaceTopo
|
||||
|
||||
|
||||
// The cells cut by the triangular faces
|
||||
meshCells_.resize(startTri.last());
|
||||
meshCells_.resize(startTri.back());
|
||||
for (label celli = 0; celli < startTri.size()-1; ++celli)
|
||||
{
|
||||
// All triangles for the current cell
|
||||
|
||||
Reference in New Issue
Block a user