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

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -133,7 +133,7 @@ void Foam::ZoneMesh<ZoneType, MeshType>::calcGroupIDs() const
for (const word& groupName : groups) 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 // Used for -dry-run, for example
if (disallowGenericZones != 0) if (disallowGenericZones != 0)
{ {
auto& zm = const_cast<ZoneMesh<ZoneType, MeshType>&>(*this);
zoneId = zm.size();
Info<< "Creating dummy zone " << zoneName << endl; 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 // Used for -dry-run, for example
if (disallowGenericZones != 0) if (disallowGenericZones != 0)
{ {
auto& zm = const_cast<ZoneMesh<ZoneType, MeshType>&>(*this);
Info<< "Creating dummy zone " << zoneName << endl; 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; return nullptr;
@ -678,7 +675,7 @@ void Foam::ZoneMesh<ZoneType, MeshType>::setGroup
// Add to specified zones // Add to specified zones
for (const label zonei : zoneIDs) for (const label zonei : zoneIDs)
{ {
zones[zonei].inGroups().appendUniq(groupName); zones[zonei].inGroups().push_uniq(groupName);
doneZone[zonei] = true; doneZone[zonei] = true;
} }
@ -921,7 +918,7 @@ ZoneType& Foam::ZoneMesh<ZoneType, MeshType>::operator()
if (!ptr) if (!ptr)
{ {
ptr = new ZoneType(zoneName, this->size(), *this); ptr = new ZoneType(zoneName, this->size(), *this);
this->append(ptr); this->push_back(ptr);
} }
if (verbose) if (verbose)

View File

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

View File

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

View File

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

View File

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

View File

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