Skip to content
Snippets Groups Projects
Commit cbf43acd authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: provide static uniq method in wordReListMatcher (issue #259)

- this functionality will be more frequently used in the future,
  thus place in a commonly available location.
parent a6a90838
Branches
Tags
No related merge requests found
......@@ -95,6 +95,7 @@ $(strings)/fileName/fileNameIO.C
$(strings)/keyType/keyType.C
$(strings)/wordRe/wordRe.C
$(strings)/lists/hashedWordList.C
$(strings)/lists/wordReListMatcher.C
$(strings)/stringOps/stringOps.C
ops = primitives/ops
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "wordReListMatcher.H"
#include "HashSet.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::wordReList Foam::wordReListMatcher::uniq(const UList<wordRe>& input)
{
wordReList retain(input.size());
wordHashSet uniqWord;
label nUniq = 0;
forAll(input, i)
{
const wordRe& select = input[i];
if
(
select.isPattern()
|| uniqWord.insert(static_cast<const word&>(select))
)
{
retain[nUniq++] = select;
}
}
retain.setSize(nUniq);
return retain;
}
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -77,13 +77,20 @@ public:
inline const UList<wordRe>& operator()() const;
// Searching
// Searching
//- Return true if string matches any of the regular expressions
// Smart match as regular expression or as a string.
// Optionally specify a literal match only.
inline bool match(const string&, bool literalMatch=false) const;
// Helpers
//- Return a wordReList with duplicate words filtered out.
// No filtering is done on regular expressions.
static wordReList uniq(const UList<wordRe>& input);
};
......
......@@ -27,6 +27,7 @@ License
#include "volFields.H"
#include "dictionary.H"
#include "wordReListMatcher.H"
#include "steadyStateDdtScheme.H"
#include "addToRunTimeSelectionTable.H"
......@@ -77,25 +78,6 @@ bool Foam::functionObjects::ddt2::checkFormatName(const word& str)
}
void Foam::functionObjects::ddt2::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);
}
bool Foam::functionObjects::ddt2::accept(const word& fieldName) const
{
// check input vs possible result names
......@@ -160,10 +142,11 @@ bool Foam::functionObjects::ddt2::read(const dictionary& dict)
return false;
}
fvMeshFunctionObject::read(dict);
dict.lookup("fields") >> selectFields_;
uniqWords(selectFields_);
selectFields_ = wordReListMatcher::uniq
(
wordReList(dict.lookup("fields"))
);
Info<< type() << " fields: " << selectFields_ << nl;
resultName_ = dict.lookupOrDefault<word>
(
......
......@@ -124,9 +124,6 @@ class ddt2
//- Check that the word contains the appropriate substitution token(s).
static bool checkFormatName(const word&);
//- Eliminate duplicate 'word' entries
static void uniqWords(wordReList&);
//- Accept unless field name appears to have already been processed
bool accept(const word& fieldName) const;
......
......@@ -27,6 +27,7 @@ License
#include "volFields.H"
#include "dictionary.H"
#include "wordReListMatcher.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -76,25 +77,6 @@ bool Foam::functionObjects::zeroGradient::checkFormatName(const word& str)
}
void Foam::functionObjects::zeroGradient::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::zeroGradient::process(const word& fieldName)
{
int state = 0;
......@@ -138,8 +120,11 @@ bool Foam::functionObjects::zeroGradient::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
dict.lookup("fields") >> selectFields_;
uniqWords(selectFields_);
selectFields_ = wordReListMatcher::uniq
(
wordReList(dict.lookup("fields"))
);
Info<< type() << " fields: " << selectFields_ << nl;
resultName_ = dict.lookupOrDefault<word>("result", type() + "(@@)");
return checkFormatName(resultName_);
......
......@@ -110,9 +110,6 @@ class zeroGradient
//- Check that the word contains the appropriate substitution token(s).
static bool checkFormatName(const word&);
//- Eliminate duplicate 'word' entries
static void uniqWords(wordReList&);
//- Accept unless field only has constraint patches
// (ie, empty/zero-gradient/processor).
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment