From eb8b51b4759456c83ef3fd52bb8128d0a79a4485 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 26 Jan 2023 12:36:53 +0100 Subject: [PATCH] ENH: use back(), pop_back() instead remove() - adjust looping to resemble LIFO pattern STYLE: adjust some string includes --- .../pimpleFoam/overPimpleDyMFoam/correctPhi.H | 2 +- .../interFoam/overInterDyMFoam/correctPhi.H | 2 +- applications/test/ListOps2/Test-ListOps2.C | 2 +- .../featurePointConformerSpecialisations.C | 14 ++----- .../MSwindows/fileMonitor/fileMonitor.C | 11 ++--- .../POSIX/fileMonitor/fileMonitor.C | 11 ++--- .../exprResult/exprResultStackTemplates.C | 10 ++--- src/OpenFOAM/global/clock/clock.C | 2 +- src/OpenFOAM/global/profiling/profiling.C | 24 ++++++----- .../global/profiling/profilingInformation.H | 4 +- .../global/profiling/profilingTrigger.H | 4 +- .../hexRef8/refinementHistory.C | 6 +-- src/fileFormats/fire/FIRECore.H | 1 - src/fileFormats/nastran/NASCore.H | 1 - src/fileFormats/vtk/file/foamVtmWriter.C | 11 +++-- src/fileFormats/vtk/format/foamVtkFormatter.C | 7 ++-- .../faceAreaWeightAMI/faceAreaWeightAMI.C | 13 +++--- src/randomProcesses/noise/noiseFFT/noiseFFT.C | 2 +- .../noise/noiseModels/noiseModel/noiseModel.C | 2 +- .../regionModel/regionModel1D/regionModel1D.C | 2 +- .../cellVolumeWeight/cellVolumeWeightMethod.C | 31 +++++++------- .../correctedCellVolumeWeightMethod.C | 33 +++++++-------- .../calcMethod/direct/directMethod.C | 15 +++---- .../calcMethod/mapNearest/mapNearestMethod.C | 41 +++++++++++-------- .../reaction/Reactions/Reaction/Reaction.C | 6 +-- 25 files changed, 125 insertions(+), 132 deletions(-) diff --git a/applications/solvers/incompressible/pimpleFoam/overPimpleDyMFoam/correctPhi.H b/applications/solvers/incompressible/pimpleFoam/overPimpleDyMFoam/correctPhi.H index e3dd30ecf7..ed9c1cf119 100644 --- a/applications/solvers/incompressible/pimpleFoam/overPimpleDyMFoam/correctPhi.H +++ b/applications/solvers/incompressible/pimpleFoam/overPimpleDyMFoam/correctPhi.H @@ -94,7 +94,7 @@ if (mesh.changing()) { if (refCells[zoneId] != -1) { - validCells.append(refCells[zoneId]); + validCells.push_back(refCells[zoneId]); } } diff --git a/applications/solvers/multiphase/interFoam/overInterDyMFoam/correctPhi.H b/applications/solvers/multiphase/interFoam/overInterDyMFoam/correctPhi.H index 1174979f41..658a8bcaf7 100644 --- a/applications/solvers/multiphase/interFoam/overInterDyMFoam/correctPhi.H +++ b/applications/solvers/multiphase/interFoam/overInterDyMFoam/correctPhi.H @@ -103,7 +103,7 @@ { if (refCells[zoneId] != -1) { - validCells.append(refCells[zoneId]); + validCells.push_back(refCells[zoneId]); } } diff --git a/applications/test/ListOps2/Test-ListOps2.C b/applications/test/ListOps2/Test-ListOps2.C index 09afd7946d..7b15ccf1ee 100644 --- a/applications/test/ListOps2/Test-ListOps2.C +++ b/applications/test/ListOps2/Test-ListOps2.C @@ -191,7 +191,7 @@ int main(int argc, char *argv[]) Info<< nl << "list: " << flatOutput(list) << nl << endl; - list.remove(); + list.pop_back(); Info<<"remove = " << flatOutput(list) << nl; { diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/featurePointConformer/featurePointConformerSpecialisations.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/featurePointConformer/featurePointConformerSpecialisations.C index 5c15a39c3f..bd274824f3 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/featurePointConformer/featurePointConformerSpecialisations.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/featurePointConformer/featurePointConformerSpecialisations.C @@ -266,11 +266,8 @@ bool Foam::featurePointConformer::createSpecialisedFeaturePoint << endl; // Remove points that have just been added before returning - for (label i = 0; i < 2; ++i) - { - pts.remove(); - nVert--; - } + pts.pop_back(2); + nVert -= 2; return false; } @@ -702,11 +699,8 @@ bool Foam::featurePointConformer::createSpecialisedFeaturePoint << endl; // Remove points that have just been added before returning - for (label i = 0; i < 2; ++i) - { - pts.remove(); - nVert--; - } + pts.pop_back(2); + nVert -= 2; return false; } diff --git a/src/OSspecific/MSwindows/fileMonitor/fileMonitor.C b/src/OSspecific/MSwindows/fileMonitor/fileMonitor.C index d6b9f0295c..224adaf476 100644 --- a/src/OSspecific/MSwindows/fileMonitor/fileMonitor.C +++ b/src/OSspecific/MSwindows/fileMonitor/fileMonitor.C @@ -456,15 +456,12 @@ Foam::label Foam::fileMonitor::addWatch(const fileName& fName) Pout<< "fileMonitor : adding watch on file " << fName << endl; } - label watchFd; + label watchFd = state_.size(); - if (freeWatchFds_.size()) + if (!freeWatchFds_.empty()) { - watchFd = freeWatchFds_.remove(); - } - else - { - watchFd = state_.size(); + watchFd = freeWatchFds_.back(); + freeWatchFds_.pop_back(); } watcher_->addWatch(watchFd, fName); diff --git a/src/OSspecific/POSIX/fileMonitor/fileMonitor.C b/src/OSspecific/POSIX/fileMonitor/fileMonitor.C index 5241a5b4ba..d3c687fb67 100644 --- a/src/OSspecific/POSIX/fileMonitor/fileMonitor.C +++ b/src/OSspecific/POSIX/fileMonitor/fileMonitor.C @@ -452,15 +452,12 @@ Foam::label Foam::fileMonitor::addWatch(const fileName& fName) Pout<< "fileMonitor : adding watch on file " << fName << endl; } - label watchFd; + label watchFd = state_.size(); - if (freeWatchFds_.size()) + if (!freeWatchFds_.empty()) { - watchFd = freeWatchFds_.remove(); - } - else - { - watchFd = state_.size(); + watchFd = freeWatchFds_.back(); + freeWatchFds_.pop_back(); } watcher_->addWatch(watchFd, fName); diff --git a/src/OpenFOAM/expressions/exprResult/exprResultStackTemplates.C b/src/OpenFOAM/expressions/exprResult/exprResultStackTemplates.C index e85d66c9fe..60093caf3f 100644 --- a/src/OpenFOAM/expressions/exprResult/exprResultStackTemplates.C +++ b/src/OpenFOAM/expressions/exprResult/exprResultStackTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2012-2018 Bernhard Gschaider + Copyright (C) 2012-2018 Bernhard Gschaider Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -44,10 +44,10 @@ bool Foam::expressions::exprResultStack::pushChecked if (!resultField.empty()) { - val = resultField.first(); + val = resultField.front(); } - this->ref().append(val); + this->ref().push_back(val); return true; } @@ -71,8 +71,8 @@ bool Foam::expressions::exprResultStack::popChecked if (!oldField.empty()) { - val = oldField.last(); - oldField.resize(oldField.size()-1); + val = oldField.back(); + oldField.pop_back(); } result.setSingleValue(val); diff --git a/src/OpenFOAM/global/clock/clock.C b/src/OpenFOAM/global/clock/clock.C index 3c10d4e642..26f204cd08 100644 --- a/src/OpenFOAM/global/clock/clock.C +++ b/src/OpenFOAM/global/clock/clock.C @@ -27,8 +27,8 @@ License \*---------------------------------------------------------------------------*/ #include "clock.H" -#include "string.H" +#include #include #include diff --git a/src/OpenFOAM/global/profiling/profiling.C b/src/OpenFOAM/global/profiling/profiling.C index b5e23c8251..74fb946cb9 100644 --- a/src/OpenFOAM/global/profiling/profiling.C +++ b/src/OpenFOAM/global/profiling/profiling.C @@ -51,9 +51,9 @@ Foam::profilingInformation* Foam::profiling::create() Information* info = new Information; - pool_.append(info); + pool_.push_back(info); children_.resize(pool_.size()); - children_.last().clear(); // safety + children_.back().clear(); // safety return info; } @@ -77,10 +77,10 @@ Foam::profilingInformation* Foam::profiling::create Information* info = new Information(parent, descr, pool_.size()); - pool_.append(info); + pool_.push_back(info); children_.resize(pool_.size()); - children_.last().clear(); // safety - children_[parentId].append(info); + children_.back().clear(); // safety + children_[parentId].push_back(info); return info; } @@ -88,16 +88,18 @@ Foam::profilingInformation* Foam::profiling::create void Foam::profiling::beginTimer(profilingInformation *info) { - stack_.append(info); - times_.append(clockValue::now()); + stack_.push_back(info); + times_.push_back(clockValue::now()); info->setActive(true); // Mark as on stack } Foam::profilingInformation* Foam::profiling::endTimer() { - Information *info = stack_.remove(); - clockValue clockval = times_.remove(); + Information *info = stack_.back(); + clockValue clockval = times_.back(); + stack_.pop_back(); + times_.pop_back(); info->update(clockval.elapsed()); // Update elapsed time info->setActive(false); // Mark as off stack @@ -184,7 +186,7 @@ Foam::profilingInformation* Foam::profiling::New(const string& descr) if (active()) { - Information *parent = singleton_->stack_.last(); + Information *parent = singleton_->stack_.back(); info = singleton_->create(parent, descr); singleton_->beginTimer(info); @@ -320,7 +322,7 @@ bool Foam::profiling::writeData(Ostream& os) const { elapsed[stacki] = (now - times_[stacki]); } - elapsed.last() = 0; + elapsed.back() = 0; os.beginBlock("profiling"); diff --git a/src/OpenFOAM/global/profiling/profilingInformation.H b/src/OpenFOAM/global/profiling/profilingInformation.H index 367726da68..578e5fb1d0 100644 --- a/src/OpenFOAM/global/profiling/profilingInformation.H +++ b/src/OpenFOAM/global/profiling/profilingInformation.H @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef profilingInformation_H -#define profilingInformation_H +#ifndef Foam_profilingInformation_H +#define Foam_profilingInformation_H #include "label.H" #include "scalar.H" diff --git a/src/OpenFOAM/global/profiling/profilingTrigger.H b/src/OpenFOAM/global/profiling/profilingTrigger.H index 6082bf2576..236122d29b 100644 --- a/src/OpenFOAM/global/profiling/profilingTrigger.H +++ b/src/OpenFOAM/global/profiling/profilingTrigger.H @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef profilingTrigger_H -#define profilingTrigger_H +#ifndef Foam_profilingTrigger_H +#define Foam_profilingTrigger_H #include "string.H" diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C index e2b1e23818..d23d23737d 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/refinementHistory.C @@ -271,15 +271,15 @@ Foam::label Foam::refinementHistory::allocateSplitCell if (freeSplitCells_.size()) { - index = freeSplitCells_.remove(); + index = freeSplitCells_.back(); + freeSplitCells_.pop_back(); splitCells_[index] = splitCell8(parent); } else { index = splitCells_.size(); - - splitCells_.append(splitCell8(parent)); + splitCells_.push_back(splitCell8(parent)); } diff --git a/src/fileFormats/fire/FIRECore.H b/src/fileFormats/fire/FIRECore.H index 0db246f32a..ce7bed379d 100644 --- a/src/fileFormats/fire/FIRECore.H +++ b/src/fileFormats/fire/FIRECore.H @@ -38,7 +38,6 @@ SourceFiles #define FIRECore_H #include "point.H" -#include "string.H" #include "labelList.H" #include "pointField.H" #include "IOstreams.H" diff --git a/src/fileFormats/nastran/NASCore.H b/src/fileFormats/nastran/NASCore.H index 0fd8e9b160..f41c3b23b9 100644 --- a/src/fileFormats/nastran/NASCore.H +++ b/src/fileFormats/nastran/NASCore.H @@ -38,7 +38,6 @@ SourceFiles #define Foam_fileFormats_NASCore_H #include "scalar.H" -#include "string.H" #include "Enum.H" #include "face.H" #include "point.H" diff --git a/src/fileFormats/vtk/file/foamVtmWriter.C b/src/fileFormats/vtk/file/foamVtmWriter.C index cf5b75160f..35f051b0e7 100644 --- a/src/fileFormats/vtk/file/foamVtmWriter.C +++ b/src/fileFormats/vtk/file/foamVtmWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -399,18 +399,17 @@ Foam::label Foam::vtk::vtmWriter::endBlock(const word& blockName) { if (!blocks_.empty()) { - const word curr(blocks_.remove()); - // Verify expected end tag - if (!blockName.empty() && blockName != curr) + if (!blockName.empty() && blockName != blocks_.back()) { WarningInFunction << "expecting to end block '" << blockName - << "' but found '" << curr << "' instead" + << "' but found '" << blocks_.back() << "' instead" << endl; } - entries_.append(vtmEntry::endblock()); + blocks_.pop_back(); + entries_.push_back(vtmEntry::endblock()); } return blocks_.size(); diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.C b/src/fileFormats/vtk/format/foamVtkFormatter.C index f5e11ce1cb..a9c62304ed 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkFormatter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -112,7 +112,7 @@ Foam::vtk::formatter& Foam::vtk::formatter::closeTag(const bool isEmpty) if (isEmpty) { // Eg, - xmlTags_.remove(); + xmlTags_.pop_back(); os_ << " /"; } os_ << '>' << nl; @@ -124,7 +124,8 @@ Foam::vtk::formatter& Foam::vtk::formatter::closeTag(const bool isEmpty) Foam::vtk::formatter& Foam::vtk::formatter::endTag(const word& tagName) { - const word curr(xmlTags_.remove()); + const word curr(std::move(xmlTags_.back())); + xmlTags_.pop_back(); indent(); if (inTag_) diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/faceAreaWeightAMI/faceAreaWeightAMI.C b/src/meshTools/AMIInterpolation/AMIInterpolation/faceAreaWeightAMI/faceAreaWeightAMI.C index ccf7556809..1a7c197aee 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/faceAreaWeightAMI/faceAreaWeightAMI.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/faceAreaWeightAMI/faceAreaWeightAMI.C @@ -131,6 +131,7 @@ void Foam::faceAreaWeightAMI::calcAddressing bool continueWalk = true; DynamicList