From 2b7b3700c2768531e26b46a6463ad146eb116b1f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 Apr 2021 13:42:38 +0200 Subject: [PATCH] ENH: replace keyType with wordRe for matching selectors. - The keyType is primarily used within dictionary reading, whereas wordRe and wordRes are used for selectors in code. Unifying on wordRe and wordRes reduces the number matching options. --- .../test/PointEdgeWave/Test-PointEdgeWave.C | 5 +- .../mesh/manipulation/subsetMesh/subsetMesh.C | 4 +- .../db/dynamicLibrary/codedBase/codedBase.C | 2 - .../meshes/Identifiers/DynamicID/DynamicID.H | 109 ++++++++++-------- .../pointBoundaryMesh/pointBoundaryMesh.C | 6 +- .../pointBoundaryMesh/pointBoundaryMesh.H | 8 +- .../polyBoundaryMesh/polyBoundaryMesh.C | 25 +--- .../polyBoundaryMesh/polyBoundaryMesh.H | 15 +-- .../processorCyclicPolyPatch.C | 6 +- .../meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C | 44 +++---- .../meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H | 17 ++- .../faMesh/faBoundaryMesh/faBoundaryMesh.C | 23 +--- .../faMesh/faBoundaryMesh/faBoundaryMesh.H | 12 +- .../porosityModel/porosityModel.C | 4 +- .../porosityModel/porosityModel.H | 6 +- .../fvMesh/fvBoundaryMesh/fvBoundaryMesh.C | 6 +- .../fvMesh/fvBoundaryMesh/fvBoundaryMesh.H | 6 +- .../field/externalCoupled/externalCoupled.C | 2 +- .../externalCoupledTemplates.C | 26 ++--- .../ParticleErosion/ParticleErosion.C | 14 +-- .../LocalInteraction/patchInteractionData.C | 36 +----- .../LocalInteraction/patchInteractionData.H | 70 +++++------ .../patchInteractionDataList.C | 25 ++-- .../blockMesh/blockMeshTools/blockMeshTools.C | 48 +++++--- .../blockMesh/blockMeshTools/blockMeshTools.H | 10 +- .../layerParameters/layerParameters.C | 2 +- .../coordinate/systems/coordinateSystems.C | 76 +++--------- .../coordinate/systems/coordinateSystems.H | 15 +-- 28 files changed, 255 insertions(+), 367 deletions(-) diff --git a/applications/test/PointEdgeWave/Test-PointEdgeWave.C b/applications/test/PointEdgeWave/Test-PointEdgeWave.C index 4004d2720a..441f2bc1d4 100644 --- a/applications/test/PointEdgeWave/Test-PointEdgeWave.C +++ b/applications/test/PointEdgeWave/Test-PointEdgeWave.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,11 +50,13 @@ int main(int argc, char *argv[]) #include "createTime.H" #include "createPolyMesh.H" + const wordRes patchSelection(args.getList(1)); + const polyBoundaryMesh& pbm = mesh.boundaryMesh(); labelList patchIDs ( - pbm.patchSet(args.getList(1)).sortedToc() + pbm.patchSet(patchSelection).sortedToc() ); Info<< "Starting walk from patches " diff --git a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C index f20f3f4e68..d09c36f7a4 100644 --- a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C +++ b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -495,7 +495,7 @@ int main(int argc, char *argv[]) wordRes zoneNames; if (useCellZone) { - List selectionNames = args.getList(1); + wordRes selectionNames(args.getList(1)); zoneNames.transfer(selectionNames); Info<< "Using cellZone " << flatOutput(zoneNames) << nl << endl; diff --git a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C index 7d9fbbc721..5cc0775529 100644 --- a/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C +++ b/src/OpenFOAM/db/dynamicLibrary/codedBase/codedBase.C @@ -59,11 +59,9 @@ static inline void writeEntryIfPresent ) { const entry* eptr = dict.findEntry(key, keyType::LITERAL); - if (eptr) { const tokenList& toks = eptr->stream(); - if (!toks.empty()) { os.writeEntry(key, toks[0]); diff --git a/src/OpenFOAM/meshes/Identifiers/DynamicID/DynamicID.H b/src/OpenFOAM/meshes/Identifiers/DynamicID/DynamicID.H index 8ddb596f6d..184b6fab2e 100644 --- a/src/OpenFOAM/meshes/Identifiers/DynamicID/DynamicID.H +++ b/src/OpenFOAM/meshes/Identifiers/DynamicID/DynamicID.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,7 +39,7 @@ Description #ifndef DynamicID_H #define DynamicID_H -#include "keyType.H" +#include "wordRe.H" #include "labelList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,11 +47,6 @@ Description namespace Foam { -// Forward declarations -template class DynamicID; -template -Ostream& operator<<(Ostream&, const DynamicID&); - /*---------------------------------------------------------------------------*\ Class DynamicID Declaration \*---------------------------------------------------------------------------*/ @@ -59,12 +54,12 @@ Ostream& operator<<(Ostream&, const DynamicID&); template class DynamicID { - // Private data + // Private Data - //- Zone name - keyType key_; + //- Selector name + wordRe key_; - //- Zone indices + //- Selection indices labelList indices_; @@ -72,18 +67,36 @@ public: // Constructors - //- Construct from name - DynamicID(const keyType& key, const ObjectType& obj) + //- Construct from selector name and object + DynamicID(const wordRe& key, const ObjectType& obj) : key_(key), indices_(obj.indices(key_)) {} - //- Construct from Istream + //- Construct from selector name and object + DynamicID(wordRe&& key, const ObjectType& obj) + : + key_(std::move(key)), + indices_(obj.indices(key_)) + {} + + //- Construct from selector name and object + DynamicID(const word& key, const ObjectType& obj) + : + DynamicID(wordRe(key), obj) + {} + + //- Construct from selector name and object + DynamicID(const keyType& key, const ObjectType& obj) + : + DynamicID(wordRe(key), obj) + {} + + //- Construct from Istream and object DynamicID(Istream& is, const ObjectType& obj) : - key_(is), - indices_(obj.indices(key_)) + DynamicID(wordRe(is), obj) {} @@ -93,56 +106,50 @@ public: // Member Functions - // Access + // Access - //- Return name - const keyType& name() const - { - return key_; - } + //- The selector name + const wordRe& name() const noexcept + { + return key_; + } - //- Return indices of matching zones - const labelList& indices() const - { - return indices_; - } + //- The indices of matching items + const labelList& indices() const noexcept + { + return indices_; + } - //- Return index of first matching zone - label index() const - { - return indices_.empty() ? -1 : indices_.first(); - } + //- The index of the first matching items, -1 if no matches + label index() const + { + return indices_.empty() ? -1 : indices_.first(); + } - //- Has the zone been found - bool active() const - { - return !indices_.empty(); - } + //- Has the zone been found + bool active() const noexcept + { + return !indices_.empty(); + } - // Edit + // Edit - //- Update - void update(const ObjectType& obj) - { - indices_ = obj.indices(key_); - } - - - // IOstream Operators - - friend Ostream& operator<< - (Ostream&, const DynamicID&); + //- Update + void update(const ObjectType& obj) + { + indices_ = obj.indices(key_); + } }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template -Ostream& operator<<(Ostream& os, const DynamicID& dynId) +Ostream& operator<<(Ostream& os, const DynamicID& obj) { os << token::BEGIN_LIST - << dynId.name() << token::SPACE << dynId.index() + << obj.name() << token::SPACE << obj.index() << token::END_LIST; os.check(FUNCTION_NAME); diff --git a/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.C b/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.C index f8dff17d4c..2fee220290 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.C +++ b/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -63,11 +63,11 @@ Foam::pointBoundaryMesh::pointBoundaryMesh Foam::labelList Foam::pointBoundaryMesh::indices ( - const keyType& key, + const wordRe& matcher, const bool useGroups ) const { - return mesh()().boundaryMesh().indices(key, useGroups); + return mesh()().boundaryMesh().indices(matcher, useGroups); } diff --git a/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.H b/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.H index a7a852ae09..d6a470afcc 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.H +++ b/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -94,14 +94,14 @@ public: // Member Functions //- Return the mesh reference - const pointMesh& mesh() const + const pointMesh& mesh() const noexcept { return mesh_; } //- Find patch indices given a name // A no-op (returns empty list) for an empty key - labelList indices(const keyType& key, const bool useGroups) const; + labelList indices(const wordRe& matcher, const bool useGroups) const; //- Find patch index given a name // A no-op (returns -1) for an empty patchName @@ -118,7 +118,7 @@ public: //- Identical to the indices() method (AUG-2018) FOAM_DEPRECATED_FOR(2018-08, "indices() method") - labelList findIndices(const keyType& key, const bool useGroups) const + labelList findIndices(const wordRe& key, bool useGroups) const { return indices(key, useGroups); } diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 001b19df7b..341c984bdc 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -604,20 +604,19 @@ Foam::labelRange Foam::polyBoundaryMesh::range(const label patchi) const Foam::labelList Foam::polyBoundaryMesh::indices ( - const keyType& key, + const wordRe& matcher, const bool useGroups ) const { - if (key.empty()) + if (matcher.empty()) { return labelList(); } DynamicList