From 9fef27cb7d19c4046fee53495b0888ceff081d26 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 22 May 2017 14:59:05 +0200 Subject: [PATCH] ENH: relocate inplaceUniq (wordReList) into wordRes --- .../primitives/strings/wordRes/wordRes.C | 36 ++++++++++++++----- .../primitives/strings/wordRes/wordRes.H | 4 +++ .../utilities/ensightWrite/ensightWrite.C | 28 +++------------ .../utilities/ensightWrite/ensightWrite.H | 3 -- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/OpenFOAM/primitives/strings/wordRes/wordRes.C b/src/OpenFOAM/primitives/strings/wordRes/wordRes.C index 3f53f6492f..618c47932c 100644 --- a/src/OpenFOAM/primitives/strings/wordRes/wordRes.C +++ b/src/OpenFOAM/primitives/strings/wordRes/wordRes.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,15 +36,12 @@ Foam::wordReList Foam::wordRes::uniq(const UList& input) label count = 0; forAll(input, i) { - const wordRe& select = input[i]; + const auto& select = input[i]; - if - ( - select.isPattern() - || uniqWord.insert(static_cast(select)) - ) + if (select.isPattern() || uniqWord.insert(select)) { - retain[count++] = select; + retain[count] = select; + ++count; } } @@ -53,4 +50,27 @@ Foam::wordReList Foam::wordRes::uniq(const UList& input) } +void Foam::wordRes::inplaceUniq(wordReList& input) +{ + wordHashSet uniqWord; + + label count = 0; + forAll(input, i) + { + const auto& select = input[i]; + + if (select.isPattern() || uniqWord.insert(select)) + { + if (count != i) + { + input[count] = input[i]; + } + ++count; + } + } + + input.setSize(count); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/strings/wordRes/wordRes.H b/src/OpenFOAM/primitives/strings/wordRes/wordRes.H index 5cfe6b9b57..00ca657fe8 100644 --- a/src/OpenFOAM/primitives/strings/wordRes/wordRes.H +++ b/src/OpenFOAM/primitives/strings/wordRes/wordRes.H @@ -78,6 +78,10 @@ public: // No filtering is done on regular expressions. static wordReList uniq(const UList& input); + //- Inplace subset of wordReList with duplicate words filtered out. + // No filtering is done on regular expressions. + static void inplaceUniq(wordReList& input); + // Member Functions diff --git a/src/functionObjects/utilities/ensightWrite/ensightWrite.C b/src/functionObjects/utilities/ensightWrite/ensightWrite.C index 30b11ffc9e..47cd1050be 100644 --- a/src/functionObjects/utilities/ensightWrite/ensightWrite.C +++ b/src/functionObjects/utilities/ensightWrite/ensightWrite.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,6 +26,7 @@ License #include "ensightWrite.H" #include "Time.H" #include "polyMesh.H" +#include "wordRes.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -47,25 +48,6 @@ namespace functionObjects // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::functionObjects::ensightWrite::uniqWords(wordReList& lst) -{ - boolList retain(lst.size()); - wordHashSet uniq; - forAll(lst, i) - { - const wordRe& select = lst[i]; - - retain[i] = - ( - select.isPattern() - || uniq.insert(static_cast(select)) - ); - } - - inplaceSubset(retain, lst); -} - - int Foam::functionObjects::ensightWrite::process(const word& fieldName) { int state = 0; @@ -140,7 +122,7 @@ bool Foam::functionObjects::ensightWrite::read(const dictionary& dict) if (dict.found("patches")) { wordReList lst(dict.lookup("patches")); - uniqWords(lst); + wordRes::inplaceUniq(lst); writeOpts_.patchSelection(lst); } @@ -148,7 +130,7 @@ bool Foam::functionObjects::ensightWrite::read(const dictionary& dict) if (dict.found("faceZones")) { wordReList lst(dict.lookup("faceZones")); - uniqWords(lst); + wordRes::inplaceUniq(lst); writeOpts_.faceZoneSelection(lst); } @@ -174,7 +156,7 @@ bool Foam::functionObjects::ensightWrite::read(const dictionary& dict) // output fields // dict.lookup("fields") >> selectFields_; - uniqWords(selectFields_); + wordRes::inplaceUniq(selectFields_); return true; } diff --git a/src/functionObjects/utilities/ensightWrite/ensightWrite.H b/src/functionObjects/utilities/ensightWrite/ensightWrite.H index edba7c8535..67bc5ca3cb 100644 --- a/src/functionObjects/utilities/ensightWrite/ensightWrite.H +++ b/src/functionObjects/utilities/ensightWrite/ensightWrite.H @@ -135,9 +135,6 @@ class ensightWrite // Private Member Functions - //- Eliminate duplicate 'word' entries - static void uniqWords(wordReList&); - //- Ensight case handler ensightCase& ensCase() {