mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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.
This commit is contained in:
@ -95,6 +95,7 @@ $(strings)/fileName/fileNameIO.C
|
|||||||
$(strings)/keyType/keyType.C
|
$(strings)/keyType/keyType.C
|
||||||
$(strings)/wordRe/wordRe.C
|
$(strings)/wordRe/wordRe.C
|
||||||
$(strings)/lists/hashedWordList.C
|
$(strings)/lists/hashedWordList.C
|
||||||
|
$(strings)/lists/wordReListMatcher.C
|
||||||
$(strings)/stringOps/stringOps.C
|
$(strings)/stringOps/stringOps.C
|
||||||
|
|
||||||
ops = primitives/ops
|
ops = primitives/ops
|
||||||
|
|||||||
56
src/OpenFOAM/primitives/strings/lists/wordReListMatcher.C
Normal file
56
src/OpenFOAM/primitives/strings/lists/wordReListMatcher.C
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -84,6 +84,13 @@ public:
|
|||||||
// Optionally specify a literal match only.
|
// Optionally specify a literal match only.
|
||||||
inline bool match(const string&, bool literalMatch=false) const;
|
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 "volFields.H"
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
|
#include "wordReListMatcher.H"
|
||||||
#include "steadyStateDdtScheme.H"
|
#include "steadyStateDdtScheme.H"
|
||||||
#include "addToRunTimeSelectionTable.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
|
bool Foam::functionObjects::ddt2::accept(const word& fieldName) const
|
||||||
{
|
{
|
||||||
// check input vs possible result names
|
// check input vs possible result names
|
||||||
@ -160,10 +142,11 @@ bool Foam::functionObjects::ddt2::read(const dictionary& dict)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fvMeshFunctionObject::read(dict);
|
selectFields_ = wordReListMatcher::uniq
|
||||||
|
(
|
||||||
dict.lookup("fields") >> selectFields_;
|
wordReList(dict.lookup("fields"))
|
||||||
uniqWords(selectFields_);
|
);
|
||||||
|
Info<< type() << " fields: " << selectFields_ << nl;
|
||||||
|
|
||||||
resultName_ = dict.lookupOrDefault<word>
|
resultName_ = dict.lookupOrDefault<word>
|
||||||
(
|
(
|
||||||
|
|||||||
@ -124,9 +124,6 @@ class ddt2
|
|||||||
//- Check that the word contains the appropriate substitution token(s).
|
//- Check that the word contains the appropriate substitution token(s).
|
||||||
static bool checkFormatName(const word&);
|
static bool checkFormatName(const word&);
|
||||||
|
|
||||||
//- Eliminate duplicate 'word' entries
|
|
||||||
static void uniqWords(wordReList&);
|
|
||||||
|
|
||||||
|
|
||||||
//- Accept unless field name appears to have already been processed
|
//- Accept unless field name appears to have already been processed
|
||||||
bool accept(const word& fieldName) const;
|
bool accept(const word& fieldName) const;
|
||||||
|
|||||||
@ -27,6 +27,7 @@ License
|
|||||||
|
|
||||||
#include "volFields.H"
|
#include "volFields.H"
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
|
#include "wordReListMatcher.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * 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 Foam::functionObjects::zeroGradient::process(const word& fieldName)
|
||||||
{
|
{
|
||||||
int state = 0;
|
int state = 0;
|
||||||
@ -138,8 +120,11 @@ bool Foam::functionObjects::zeroGradient::read(const dictionary& dict)
|
|||||||
{
|
{
|
||||||
fvMeshFunctionObject::read(dict);
|
fvMeshFunctionObject::read(dict);
|
||||||
|
|
||||||
dict.lookup("fields") >> selectFields_;
|
selectFields_ = wordReListMatcher::uniq
|
||||||
uniqWords(selectFields_);
|
(
|
||||||
|
wordReList(dict.lookup("fields"))
|
||||||
|
);
|
||||||
|
Info<< type() << " fields: " << selectFields_ << nl;
|
||||||
|
|
||||||
resultName_ = dict.lookupOrDefault<word>("result", type() + "(@@)");
|
resultName_ = dict.lookupOrDefault<word>("result", type() + "(@@)");
|
||||||
return checkFormatName(resultName_);
|
return checkFormatName(resultName_);
|
||||||
|
|||||||
@ -110,9 +110,6 @@ class zeroGradient
|
|||||||
//- Check that the word contains the appropriate substitution token(s).
|
//- Check that the word contains the appropriate substitution token(s).
|
||||||
static bool checkFormatName(const word&);
|
static bool checkFormatName(const word&);
|
||||||
|
|
||||||
//- Eliminate duplicate 'word' entries
|
|
||||||
static void uniqWords(wordReList&);
|
|
||||||
|
|
||||||
|
|
||||||
//- Accept unless field only has constraint patches
|
//- Accept unless field only has constraint patches
|
||||||
// (ie, empty/zero-gradient/processor).
|
// (ie, empty/zero-gradient/processor).
|
||||||
|
|||||||
Reference in New Issue
Block a user