diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.H b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.H index af1f509fb6..8b16e629aa 100644 --- a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.H +++ b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.H @@ -132,9 +132,6 @@ class domainDecomposition labelList& elementToZone ); - //- Append single element to list - static void append(labelList&, const label); - //- Add face to inter-processor patch void addInterProcFace ( diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecompositionMesh.C b/applications/utilities/parallelProcessing/decomposePar/domainDecompositionMesh.C index 904adb05e3..964df9248d 100644 --- a/applications/utilities/parallelProcessing/decomposePar/domainDecompositionMesh.C +++ b/applications/utilities/parallelProcessing/decomposePar/domainDecompositionMesh.C @@ -39,14 +39,6 @@ Description // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::domainDecomposition::append(labelList& lst, const label elem) -{ - label sz = lst.size(); - lst.setSize(sz+1); - lst[sz] = elem; -} - - void Foam::domainDecomposition::addInterProcFace ( const label facei, @@ -354,9 +346,8 @@ void Foam::domainDecomposition::decomposeMesh() procFaceAddressing_[proci].size(); // Add size as last element to substarts and transfer - append + subPatchStarts[proci][interPatch].append ( - subPatchStarts[proci][interPatch], curInterPatchFaces[interPatch].size() ); procProcessorPatchSubPatchIDs_[proci][i].transfer diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecompositionTemplates.C b/applications/utilities/parallelProcessing/decomposePar/domainDecompositionTemplates.C index 4dc857b7e3..d6d1a97131 100644 --- a/applications/utilities/parallelProcessing/decomposePar/domainDecompositionTemplates.C +++ b/applications/utilities/parallelProcessing/decomposePar/domainDecompositionTemplates.C @@ -103,8 +103,8 @@ void Foam::domainDecomposition::processInterCyclics if (interPatchFaces[proci][interI].size() > oldSz) { // Added faces to this interface. Add an entry - append(subPatchIDs[proci][interI], patchi); - append(subPatchStarts[proci][interI], oldSz); + subPatchIDs[proci][interI].append(patchi); + subPatchStarts[proci][interI].append(oldSz); } } } diff --git a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C index d7fd8eef9c..2e1d2cabc1 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C +++ b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -376,9 +376,9 @@ void Foam::dlLibraryTable::close(bool verbose) } -bool Foam::dlLibraryTable::append(const fileName& libName) +bool Foam::dlLibraryTable::push_back(const fileName& libName) { - if (libName.empty() || libNames_.found(libName)) + if (libName.empty() || libNames_.contains(libName)) { return false; } @@ -390,13 +390,13 @@ bool Foam::dlLibraryTable::append(const fileName& libName) } -Foam::label Foam::dlLibraryTable::append(const UList& libNames) +Foam::label Foam::dlLibraryTable::push_back(const UList& libNames) { label nAdded = 0; for (const fileName& libName : libNames) { - if (append(libName)) + if (push_back(libName)) { ++nAdded; } diff --git a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H index f3ca9d581c..1b9a445d2a 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H +++ b/src/OpenFOAM/db/dynamicLibrary/dlLibraryTable/dlLibraryTable.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -227,13 +227,13 @@ public: List loaded() const; //- Names of the libraries in use, or requested - const UList& names() const + const UList& names() const noexcept { return libNames_; } //- Pointers to the libraries in use. Access with caution. - const UList& pointers() const + const UList& pointers() const noexcept { return libPtrs_; } @@ -241,16 +241,18 @@ public: //- Clears the table, without attempting to close the libraries void clear(); - //- Add to the list of names, but do not yet open. - // Ignores duplicate names. - bool append(const fileName& libName); //- Add to the list of names, but do not yet open. - // Ignores duplicate names. - label append(const UList& libNames); + // Ignores empty and duplicate names. + bool push_back(const fileName& libName); + + //- Add to the list of names, but do not yet open. + // Ignores empty and duplicate names. + label push_back(const UList& libNames); + //- Open named, but unopened libraries. - //- These names will normally have been added with the append() method. + //- These names will normally have been added with push_back(). bool open(bool verbose = true); //- Open the named library, warn by default if problems occur. @@ -312,6 +314,23 @@ public: //- Return info proxy, //- used to print library table information to a stream InfoProxy info() const noexcept { return *this; } + + + // Housekeeping + + //- Add to the list of names, but do not yet open. + //FOAM_DEPRECATED_FOR(2024-04, "push_back()") + bool append(const fileName& libName) + { + return push_back(libName); + } + + //- Add to the list of names, but do not yet open. + //FOAM_DEPRECATED_FOR(2024-04, "push_back()") + label append(const UList& libNames) + { + return push_back(libNames); + } }; diff --git a/src/conversion/ccm/reader/ccmSolutionTable.H b/src/conversion/ccm/reader/ccmSolutionTable.H index 7440154686..d99b342eb4 100644 --- a/src/conversion/ccm/reader/ccmSolutionTable.H +++ b/src/conversion/ccm/reader/ccmSolutionTable.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,6 +42,7 @@ namespace Foam namespace ccm { +// Forward Declarations class fieldEntry; class fieldTable; class solutionEntry; @@ -55,14 +56,16 @@ Ostream& operator<<(Ostream& os, const solutionEntry& entry); \*---------------------------------------------------------------------------*/ //- A linked-list that is searchable by the 'name()' of the items -template +template class namesList : - public SLList + public SLList { public: - using const_iterator = typename SLList::const_iterator; - using iterator = typename SLList::iterator; + + using const_iterator = typename SLList::const_iterator; + using iterator = typename SLList::iterator; + // Constructors @@ -72,12 +75,12 @@ public: // Access - //- Return true if a list element has a name that matches key + //- True if a list element has a name that matches key bool found(const word& key) const { - forAllConstIters(*this, iter) + for (const Type& item : *this) { - if (iter().name() == key) + if (item.name() == key) { return true; } @@ -87,18 +90,22 @@ public: } - //- Find a list element has a name matching key + //- Find list element by name iterator find(const word& key) { - forAllIters(*this, iter) + const auto last = SLList::end(); + + iterator iter = SLList::begin(); + + for (; (iter != last); ++iter) { - if (iter().name() == key) + if ((*iter).name() == key) { - return iter; + break; } } - return SLList::end(); + return iter; } @@ -109,20 +116,22 @@ public: const wordRes& deny = wordRes() ) const { - List matched(SLList::size()); + List matched(SLList::size()); - label matchi = 0; - forAllConstIters(*this, iter) + label count = 0; + + for (const Type& item : *this) { - const word& name = iter().name(); + const word& name = item.name(); if (allow.match(name) && !deny.match(name)) { - matched[matchi++] = name; + matched[count] = name; + ++count; } } - matched.resize(matchi); + matched.resize(count); return matched; } }; @@ -181,34 +190,19 @@ public: // Access //- The field name (PROSTAR short name) - const word& name() const - { - return name_; - } + const word& name() const noexcept { return name_; } //- The full field name - const string& fullName() const - { - return fullName_; - } + const string& fullName() const noexcept { return fullName_; } //- The field units - const string& units() const - { - return units_; - } + const string& units() const noexcept { return units_; } //- The max cell id for the field - label maxCellId() const - { - return maxCellId_; - } + label maxCellId() const noexcept { return maxCellId_; } //- The max face id for the field - label maxFaceId() const - { - return maxFaceId_; - } + label maxFaceId() const noexcept { return maxFaceId_; } // Edit @@ -223,21 +217,21 @@ public: } //- Set the max cell Id for the field - void maxCellId(const int newMax) + void maxCellId(const int val) { - if (maxCellId_ < newMax) + if (maxCellId_ < val) { - maxCellId_ = newMax; + maxCellId_ = val; } } //- Set the max face Id for the field - void maxFaceId(const int newMax) + void maxFaceId(const int val) { - if (maxFaceId_ < newMax) + if (maxFaceId_ < val) { - maxFaceId_ = newMax; + maxFaceId_ = val; } } @@ -299,22 +293,13 @@ public: // Access //- The solution name - const word& name() const - { - return name_; - } + const word& name() const noexcept { return name_; } //- The solution iteration/timestep - label iteration() const - { - return iter_; - } + label iteration() const noexcept { return iter_; } //- The solution time (sec) - scalar timeValue() const - { - return time_; - } + scalar timeValue() const noexcept { return time_; } // IOstream Operators @@ -356,11 +341,8 @@ public: // Constructor - //- Null construct - fieldTable() - : - namesList() - {} + //- Default construct + fieldTable() = default; // Access @@ -368,36 +350,36 @@ public: //- The maximum cell Id referenced in the list label maxCellId() const { - label maxId = 0; - forAllConstIters(*this, iter) + label result = 0; + for (const auto& item : *this) { - const label currMax = iter().maxCellId(); + const label val = item.maxCellId(); - if (maxId < currMax) + if (result < val) { - maxId = currMax; + result = val; } } - return maxId; + return result; } //- The maximum face Id referenced in the list label maxFaceId() const { - label maxId = 0; - forAllConstIters(*this, iter) + label result = 0; + for (const auto& item : *this) { - const label currMax = iter().maxFaceId(); + const label val = item.maxFaceId(); - if (maxId < currMax) + if (result < val) { - maxId = currMax; + result = val; } } - return maxId; + return result; } diff --git a/src/conversion/common/tables/boundaryRegion.C b/src/conversion/common/tables/boundaryRegion.C index 4cfe6b70d2..221df81be8 100644 --- a/src/conversion/common/tables/boundaryRegion.C +++ b/src/conversion/common/tables/boundaryRegion.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,31 +29,59 @@ License #include "boundaryRegion.H" #include "IOMap.H" #include "OFstream.H" +#include "predicates.H" + +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +template +static Map names_impl +( + const Map& input, + const MatchPredicate& nameMatcher +) +{ + Map output; + output.reserve(input.size()); + + forAllConstIters(input, iter) + { + word lookupName; + if (!iter().readIfPresent("Label", lookupName)) + { + lookupName = "boundaryRegion_" + Foam::name(iter.key()); + } + + if (nameMatcher(lookupName)) + { + output.emplace(iter.key(), std::move(lookupName)); + } + } + + return output; +} + +} // End namespace Foam + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::boundaryRegion::boundaryRegion() -: - Map() -{} - - Foam::boundaryRegion::boundaryRegion ( - const objectRegistry& registry, + const objectRegistry& obr, const word& name, const fileName& instance ) -: - Map() { - readDict(registry, name, instance); + readDict(obr, name, instance); } // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -Foam::label Foam::boundaryRegion::append(const dictionary& dict) +Foam::label Foam::boundaryRegion::maxIndex() const { label maxId = -1; forAllConstIters(*this, iter) @@ -64,6 +92,14 @@ Foam::label Foam::boundaryRegion::append(const dictionary& dict) } } + return maxId; +} + + +Foam::label Foam::boundaryRegion::push_back(const dictionary& dict) +{ + label maxId = this->maxIndex(); + insert(++maxId, dict); return maxId; } @@ -71,64 +107,52 @@ Foam::label Foam::boundaryRegion::append(const dictionary& dict) Foam::Map Foam::boundaryRegion::names() const { - Map lookup; - - forAllConstIters(*this, iter) - { - lookup.insert - ( - iter.key(), - iter().getOrDefault - ( - "Label", - "boundaryRegion_" + Foam::name(iter.key()) - ) - ); - } - - return lookup; + return names_impl(*this, predicates::always{}); } -Foam::Map Foam::boundaryRegion::names -( - const wordRes& patterns -) const +Foam::Map Foam::boundaryRegion::names(const wordRes& patterns) const { - Map lookup; - - forAllConstIters(*this, iter) - { - const word lookupName = iter().getOrDefault - ( - "Label", - "boundaryRegion_" + Foam::name(iter.key()) - ); - - if (patterns.match(lookupName)) - { - lookup.insert(iter.key(), lookupName); - } - } - - return lookup; + return names_impl(*this, patterns); } Foam::Map Foam::boundaryRegion::boundaryTypes() const { - Map lookup; + Map output; + output.reserve(size()); forAllConstIters(*this, iter) { - lookup.insert - ( - iter.key(), - iter().getOrDefault("BoundaryType", "patch") - ); + word lookupType; + if (!iter().readIfPresent("BoundaryType", lookupType)) + { + lookupType = "patch"; + } + + output.emplace(iter.key(), std::move(lookupType)); } - return lookup; + return output; +} + + +Foam::word Foam::boundaryRegion::name(const label id) const +{ + word lookupName; + + const auto iter = cfind(id); + if (iter.good()) + { + iter.val().readIfPresent("Label", lookupName); + } + + if (lookupName.empty() && id >= 0) + { + lookupName = "boundaryRegion_" + Foam::name(id); + } + + return lookupName; } @@ -141,7 +165,10 @@ Foam::label Foam::boundaryRegion::findIndex(const word& name) const forAllConstIters(*this, iter) { - if (iter().getOrDefault("Label", word::null) == name) + const auto& dict = iter.val(); + + word lookupName; + if (dict.readIfPresent("Label", lookupName) && (lookupName == name)) { return iter.key(); } @@ -153,35 +180,35 @@ Foam::label Foam::boundaryRegion::findIndex(const word& name) const Foam::word Foam::boundaryRegion::boundaryType(const word& name) const { - word bndType("patch"); + word lookupType("patch"); - label id = this->findIndex(name); + const label id = this->findIndex(name); if (id >= 0) { - operator[](id).readIfPresent("BoundaryType", bndType); + operator[](id).readIfPresent("BoundaryType", lookupType); } - return bndType; + return lookupType; } void Foam::boundaryRegion::readDict ( - const objectRegistry& registry, + const objectRegistry& obr, const word& name, const fileName& instance ) { - clear(); + Map::clear(); - // read constant/dictName + // Read constant/dictName IOMap ioObj ( IOobject ( name, instance, - registry, + obr, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER @@ -201,7 +228,7 @@ void Foam::boundaryRegion::readDict void Foam::boundaryRegion::writeDict ( - const objectRegistry& registry, + const objectRegistry& obr, const word& name, const fileName& instance ) const @@ -213,7 +240,7 @@ void Foam::boundaryRegion::writeDict ( name, instance, - registry, + obr, IOobject::NO_READ, IOobject::NO_WRITE, IOobject::NO_REGISTER @@ -221,13 +248,16 @@ void Foam::boundaryRegion::writeDict ); ioObj.note() = - "persistent data for thirdParty mesh <-> OpenFOAM translation"; + "persistent data for third-party mesh <-> OpenFOAM translation"; - Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl; + Info<< "Writing " << ioObj.name() << " to " + << ioObj.objectRelPath() << endl; OFstream os(ioObj.objectPath()); ioObj.writeHeader(os); os << *this; + + IOobject::writeEndDivider(os); } @@ -259,6 +289,8 @@ void Foam::boundaryRegion::rename(const dictionary& mapDict) // This avoid re-matching any renamed regions Map mapping; + mapping.reserve(mapDict.size()); + for (const entry& dEntry : mapDict) { const word oldName(dEntry.stream()); @@ -272,12 +304,19 @@ void Foam::boundaryRegion::rename(const dictionary& mapDict) forAllConstIters(mapping, iter) { + const word& newName = iter.val(); + dictionary& dict = operator[](iter.key()); - Info<< "rename patch: " << iter() - << " <- " << dict.get("Label") << nl; + word oldName; + if (!dict.readIfPresent("Label", oldName)) + { + oldName = "boundaryRegion_" + Foam::name(iter.key()); + } - dict.set("Label", iter()); + Info<< "rename patch: " << newName << " <- " << oldName << nl; + + dict.set("Label", newName); } } diff --git a/src/conversion/common/tables/boundaryRegion.H b/src/conversion/common/tables/boundaryRegion.H index bad8b56108..c669d1e9d4 100644 --- a/src/conversion/common/tables/boundaryRegion.H +++ b/src/conversion/common/tables/boundaryRegion.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,14 +52,12 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef boundaryRegion_H -#define boundaryRegion_H +#ifndef Foam_boundaryRegion_H +#define Foam_boundaryRegion_H -#include "polyMesh.H" #include "Map.H" #include "dictionary.H" #include "labelList.H" -#include "wordList.H" #include "wordRes.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -66,6 +65,9 @@ SourceFiles namespace Foam { +// Forward Declarations +class objectRegistry; + /*---------------------------------------------------------------------------*\ Class boundaryRegion Declaration \*---------------------------------------------------------------------------*/ @@ -74,23 +76,21 @@ class boundaryRegion : public Map { - // Private Member Functions - - //- No copy construct - boundaryRegion(const boundaryRegion&) = delete; - - public: + //- No copy construct + boundaryRegion(const boundaryRegion&) = delete; + + // Constructors - //- Construct null - boundaryRegion(); + //- Default construct + boundaryRegion() noexcept = default; - //- Construct read from registry, name. instance - boundaryRegion + //- Read construct from registry, name, instance + explicit boundaryRegion ( - const objectRegistry&, + const objectRegistry& obr, const word& name = "boundaryRegion", const fileName& instance = "constant" ); @@ -102,29 +102,38 @@ public: // Member Functions - //- Append to the end, return index - label append(const dictionary&); + //- Add to the end, return index + label push_back(const dictionary& dict); - //- Return index corresponding to patch 'name' - // returns -1 if not found + //- The max table index, -1 if empty + label maxIndex() const; + + //- The index corresponding to entry with 'Label' of given name, + //- or -1 if not found label findIndex(const word& name) const; - //- Return a Map of (id => name) + //- The 'Label' name corresponding to id, + //- or boundaryRegion_ID if not otherwise defined + word name(const label id) const; + + //- Return the extracted Map of (id => name) Map names() const; - //- Return a Map of (id => names) selected by patterns + //- Return the extracted Map of (id => names) selected by patterns Map names(const wordRes& patterns) const; - //- Return a Map of (id => type) + //- Return the extracted Map of (id => type) Map boundaryTypes() const; - //- Return BoundaryType corresponding to patch 'name' + //- Return BoundaryType corresponding to patch 'name', + //- "patch" if not found word boundaryType(const word& name) const; + //- Read constant/boundaryRegion void readDict ( - const objectRegistry&, + const objectRegistry& obr, const word& name = "boundaryRegion", const fileName& instance = "constant" ); @@ -132,7 +141,7 @@ public: //- Write constant/boundaryRegion for later reuse void writeDict ( - const objectRegistry&, + const objectRegistry& obr, const word& name = "boundaryRegion", const fileName& instance = "constant" ) const; @@ -140,7 +149,7 @@ public: // Member Operators - //- Assignment + //- Copy assignment void operator=(const boundaryRegion&); //- Assign from Map @@ -155,8 +164,15 @@ public: // newPatchName originalName; // \endverbatim void rename(const dictionary&); + + + // Housekeeping + + //- Add to the end, return index + label append(const dictionary& dict) { return push_back(dict); } }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/conversion/common/tables/cellTable.C b/src/conversion/common/tables/cellTable.C index 3ec2971c96..082f845793 100644 --- a/src/conversion/common/tables/cellTable.C +++ b/src/conversion/common/tables/cellTable.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,51 +28,60 @@ License #include "cellTable.H" #include "IOMap.H" +#include "polyMesh.H" #include "OFstream.H" +#include "predicates.H" +#include "ListOps.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const char* const Foam::cellTable::defaultMaterial_ = "fluid"; +static const char* const defaultMaterial_ = "fluid"; + + +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +template +static Map names_impl +( + const Map& input, + const MatchPredicate& nameMatcher +) +{ + Map output; + output.reserve(input.size()); + + forAllConstIters(input, iter) + { + word lookupName; + if (!iter().readIfPresent("Label", lookupName)) + { + lookupName = "cellTable_" + Foam::name(iter.key()); + } + + if (nameMatcher(lookupName)) + { + output.emplace(iter.key(), std::move(lookupName)); + } + } + + return output; +} + +} // End namespace Foam // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -Foam::Map Foam::cellTable::zoneMap() const -{ - Map