STYLE: simplify ensightMeshReader with emplace_back/push_back

STYLE: emplace for mesh zones
This commit is contained in:
Mark Olesen 2023-02-06 21:23:38 +01:00
parent 1ab9dca2ab
commit 2db3e2b64f
7 changed files with 57 additions and 73 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd.
Copyright (C) 2022-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -79,11 +79,11 @@ void Foam::fileFormats::ensightMeshReader::readVerts
is.read(verti);
//if (nodeIdToPoints.size())
//{
// verts.append(nodeIdToPoints[verti]);
// verts.push_back(nodeIdToPoints[verti]);
//}
//else
{
verts.append(verti-1);
verts.push_back(verti-1);
}
}
}
@ -672,29 +672,16 @@ bool Foam::fileFormats::ensightMeshReader::readGeometry
bool finished = false;
do
{
label partIndex;
is.read(partIndex);
partIDs.append(partIndex);
// Make space
partNames.setSize(partIDs.size());
partPoints.append(new pointField(0));
partNodeIDs.append(new labelList(0));
partPointIDs.append(new Map<label>());
partIDs.emplace_back();
is.read(partIDs.back());
partCells.append(new faceListList(0));
partCellIDs.append(new labelList(0));
partCellElemIDs.append(new Map<label>());
partFaces.append(new faceList(0));
partFaceIDs.append(new labelList(0));
partFaceElemIDs.append(new Map<label>());
is.read(partNames.last());
partNames.emplace_back();
is.read(partNames.back());
Pout<< indent
<< "Reading part " << partIndex
<< " name " << partNames.last()
<< "Reading part " << partIDs.back()
<< " name " << partNames.back()
<< " starting at line " << is.lineNumber()
<< " position " << is.stdStream().tellg() << endl;
@ -705,27 +692,27 @@ bool Foam::fileFormats::ensightMeshReader::readGeometry
read_node_ids,
read_elem_ids,
partPoints.last(),
partNodeIDs.last(),
partPointIDs.last(),
partPoints.emplace_back(),
partNodeIDs.emplace_back(),
partPointIDs.emplace_back(),
// Cells (cell-to-faces)
partCells.last(),
partCellIDs.last(),
partCellElemIDs.last(),
partCells.emplace_back(),
partCellIDs.emplace_back(),
partCellElemIDs.emplace_back(),
// Faces
partFaces.last(),
partFaceIDs.last(),
partFaceElemIDs.last()
partFaces.emplace_back(),
partFaceIDs.emplace_back(),
partFaceElemIDs.emplace_back()
);
partPoints.last() *= scaleFactor;
partPoints.back() *= scaleFactor;
Pout<< indent
<< "For part " << partIndex
<< " read cells " << partCells.last().size()
<< " faces " << partFaces.last().size()
<< "For part " << partIDs.back()
<< " read cells " << partCells.back().size()
<< " faces " << partFaces.back().size()
<< endl;
Pout<< decrIndent;
@ -952,7 +939,7 @@ bool Foam::fileFormats::ensightMeshReader::readGeometry
// - but instead pass in ordered faces (lowest numbered vertex first)
HashTable<cellFaceIdentifier, face, face::symmHasher> vertsToCell
(
2*cellOffsets.last()
2*cellOffsets.back()
);
// Insert cell's faces into hashtable
@ -1064,24 +1051,24 @@ bool Foam::fileFormats::ensightMeshReader::readGeometry
if (vertsToCell.size())
{
// Unused internal or boundary faces
boundaryIds_.append(List<cellFaceIdentifier>(0));
boundaryIds_.emplace_back(vertsToCell.size());
{
auto& cellAndFaces = boundaryIds_.last();
cellAndFaces.setSize(vertsToCell.size());
auto& cellAndFaces = boundaryIds_.back();
label i = 0;
for (const auto& e : vertsToCell)
forAllConstIters(vertsToCell, iter)
{
cellAndFaces[i++] = e;
cellAndFaces[i++] = iter.val();
}
}
patchTypes_.append("empty");
patchNames_.append("defaultFaces");
patchPhysicalTypes_.append("empty");
patchStarts_.append(0);
patchSizes_.append(0);
patchTypes_.push_back("empty");
patchNames_.push_back("defaultFaces");
patchPhysicalTypes_.push_back("empty");
patchStarts_.push_back(0);
patchSizes_.push_back(0);
Pout<< "Introducing default patch " << patchNames_.size()-1
<< " name " << patchNames_.last() << endl;
<< " name " << patchNames_.back() << endl;
}
return true;

View File

@ -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.
@ -133,7 +133,7 @@ void Foam::ZoneMesh<ZoneType, MeshType>::calcGroupIDs() const
for (const word& groupName : groups)
{
groupLookup(groupName).append(zonei);
groupLookup(groupName).push_back(zonei);
}
}
@ -537,11 +537,9 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID
// Used for -dry-run, for example
if (disallowGenericZones != 0)
{
auto& zm = const_cast<ZoneMesh<ZoneType, MeshType>&>(*this);
zoneId = zm.size();
Info<< "Creating dummy zone " << zoneName << endl;
zm.append(new ZoneType(zoneName, zoneId, zm));
auto& zm = const_cast<ZoneMesh<ZoneType, MeshType>&>(*this);
zm.emplace_back(zoneName, zm.size(), zm);
}
}
@ -575,10 +573,9 @@ const ZoneType* Foam::ZoneMesh<ZoneType, MeshType>::cfindZone
// Used for -dry-run, for example
if (disallowGenericZones != 0)
{
auto& zm = const_cast<ZoneMesh<ZoneType, MeshType>&>(*this);
Info<< "Creating dummy zone " << zoneName << endl;
zm.append(new ZoneType(zoneName, zm.size(), zm));
auto& zm = const_cast<ZoneMesh<ZoneType, MeshType>&>(*this);
zm.emplace_back(zoneName, zm.size(), zm);
}
return nullptr;
@ -678,7 +675,7 @@ void Foam::ZoneMesh<ZoneType, MeshType>::setGroup
// Add to specified zones
for (const label zonei : zoneIDs)
{
zones[zonei].inGroups().appendUniq(groupName);
zones[zonei].inGroups().push_uniq(groupName);
doneZone[zonei] = true;
}
@ -921,7 +918,7 @@ ZoneType& Foam::ZoneMesh<ZoneType, MeshType>::operator()
if (!ptr)
{
ptr = new ZoneType(zoneName, this->size(), *this);
this->append(ptr);
this->push_back(ptr);
}
if (verbose)

View File

@ -58,7 +58,7 @@ void Foam::MeshedSurface<Face>::checkZones(const bool verbose)
if (!zones.empty())
{
surfZone& zn = zones.last();
surfZone& zn = zones.back();
if ((zn.start() + zn.size()) < maxCount)
{

View File

@ -69,7 +69,7 @@ void Foam::polySurface::calculateZoneIds(const UList<surfZone>& zones)
WarningInFunction
<< "More faces " << size() << " than zones " << off << endl;
SubList<label>(zoneIds_, size()-off, off) = zones.last().index();
SubList<label>(zoneIds_, size()-off, off) = zones.back().index();
}
else if (size() < off)
{
@ -431,7 +431,7 @@ void Foam::polySurface::transfer
// << " ... extending final zone"
// << endl;
//
// surfZones_.last().size() += count - nFaces();
// surfZones_.back().size() += count - nFaces();
// }
// else if (size() < count)
// {

View File

@ -254,7 +254,7 @@ void Foam::ensightSurfaceReader::readCase(ISstream& is)
// model: data/directory/geometry
//
// - use the last entry
meshFileName_ = stringOps::splitSpace(buffer).last().str();
meshFileName_ = stringOps::splitSpace(buffer).back().str();
DebugInfo << "mesh file:" << meshFileName_ << endl;
@ -295,8 +295,8 @@ void Foam::ensightSurfaceReader::readCase(ISstream& is)
Info<< nl;
}
fieldNames.append(parsed[parsed.size()-2].str());
fieldFileNames.append(parsed.last().str());
fieldNames.push_back(parsed[parsed.size()-2].str());
fieldFileNames.push_back(parsed.back().str());
}
fieldNames_.transfer(fieldNames);
fieldFileNames_.transfer(fieldFileNames);
@ -471,7 +471,7 @@ Foam::meshedSurface Foam::ensightSurfaceReader::readGeometry
{
is.read(faceCount);
faceTypeInfo.append
faceTypeInfo.push_back
(
faceInfoTuple(ensightFaces::elemType::TRIA3, faceCount)
);
@ -501,7 +501,7 @@ Foam::meshedSurface Foam::ensightSurfaceReader::readGeometry
is.read(fp);
}
dynFaces.append(std::move(f));
dynFaces.push_back(std::move(f));
}
}
else if
@ -512,7 +512,7 @@ Foam::meshedSurface Foam::ensightSurfaceReader::readGeometry
{
is.read(faceCount);
faceTypeInfo.append
faceTypeInfo.push_back
(
faceInfoTuple(ensightFaces::elemType::QUAD4, faceCount)
);
@ -542,7 +542,7 @@ Foam::meshedSurface Foam::ensightSurfaceReader::readGeometry
is.read(fp);
}
dynFaces.append(std::move(f));
dynFaces.push_back(std::move(f));
}
}
else if
@ -553,7 +553,7 @@ Foam::meshedSurface Foam::ensightSurfaceReader::readGeometry
{
is.read(faceCount);
faceTypeInfo.append
faceTypeInfo.push_back
(
faceInfoTuple(ensightFaces::elemType::NSIDED, faceCount)
);
@ -588,7 +588,7 @@ Foam::meshedSurface Foam::ensightSurfaceReader::readGeometry
is.read(fp);
}
dynFaces.append(std::move(f));
dynFaces.push_back(std::move(f));
}
}
else

View File

@ -497,7 +497,7 @@ void Foam::surfMesh::checkZones(const bool verbose)
if (!zones.empty())
{
surfZone& zn = zones.last();
surfZone& zn = zones.back();
if ((zn.start() + zn.size()) < maxCount)
{

View File

@ -343,12 +343,12 @@ Foam::triSurface::calcPatches(labelList& faceMap) const
// Extend regions
label maxRegion = patches_.size()-1; // for non-compacted regions
if (faceMap.size())
if (!faceMap.empty())
{
maxRegion = max
(
maxRegion,
operator[](faceMap.last()).region()
operator[](faceMap.back()).region()
);
}