diff --git a/src/OpenFOAM/primitives/strings/wordRes/wordRes.C b/src/OpenFOAM/primitives/strings/wordRes/wordRes.C index 3f53f6492ff3a0b8909add61b50f5911cec516a5..618c47932c46f591068930fe430afb04e5e626bb 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<wordRe>& input) label count = 0; forAll(input, i) { - const wordRe& select = input[i]; + const auto& select = input[i]; - if - ( - select.isPattern() - || uniqWord.insert(static_cast<const word&>(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<wordRe>& 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 5cfe6b9b5758ca341ce4db9b96cd5d16b241700e..00ca657fe80b2c5656a3f3a5f1c810dd71fbcb3c 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<wordRe>& 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 30b11ffc9e373ea8f9f08bec40f13a8f6af3d8f4..47cd1050bed4fb196242aee6c254a0c3e2df5124 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<const word&>(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 edba7c8535a7cafaf3571fbff0b4a4e7497d92a2..67bc5ca3cbcd799c762c0551c5c3118b5c203a11 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() {