mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: prevent conversion of string to regExp in stringListOps (closes #739)
* For most cases, this conversion would be largely unintentional
and also less efficient. If the regex is desirable, the caller
should invoke it explicitly.
For example,
findStrings(regExp(str), listOfStrings);
Or use one of the keyType, wordRe, wordRes variants instead.
If string is to be used as a plain (non-regex) matcher,
this can be directly invoked
findMatchingStrings(str, listOfStrings);
or using the ListOps instead:
findIndices(listOfStrings, str);
* provide function interfaces for keyType.
This commit is contained in:
@ -53,7 +53,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< "stringList " << strLst << nl;
|
Info<< "stringList " << strLst << nl;
|
||||||
|
|
||||||
labelList matches = findStrings(".*ee.*", strLst);
|
labelList matches = findStrings(regExp(".*ee.*"), strLst);
|
||||||
|
|
||||||
Info<< "matches found for regexp .*ee.* :" << nl << matches << nl;
|
Info<< "matches found for regexp .*ee.* :" << nl << matches << nl;
|
||||||
forAll(matches, i)
|
forAll(matches, i)
|
||||||
@ -71,7 +71,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
Info<< endl;
|
Info<< endl;
|
||||||
|
|
||||||
stringList subLst = subsetStrings(".*ee.*", strLst);
|
stringList subLst = subsetStrings(regExp(".*ee.*"), strLst);
|
||||||
Info<< "subset stringList: " << subLst << nl;
|
Info<< "subset stringList: " << subLst << nl;
|
||||||
|
|
||||||
subLst = subsetStrings(reLst, strLst);
|
subLst = subsetStrings(reLst, strLst);
|
||||||
@ -80,7 +80,7 @@ int main(int argc, char *argv[])
|
|||||||
inplaceSubsetStrings(reLst, strLst);
|
inplaceSubsetStrings(reLst, strLst);
|
||||||
Info<< "subsetted stringList: " << strLst << nl;
|
Info<< "subsetted stringList: " << strLst << nl;
|
||||||
|
|
||||||
inplaceSubsetStrings(".*l.*", strLst);
|
inplaceSubsetStrings(regExp(".*l.*"), strLst);
|
||||||
Info<< "subsetted stringList: " << strLst << nl;
|
Info<< "subsetted stringList: " << strLst << nl;
|
||||||
|
|
||||||
Info<< "\nEnd\n" << endl;
|
Info<< "\nEnd\n" << endl;
|
||||||
|
|||||||
@ -178,7 +178,6 @@ bool addEntry
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// List of indices into thisKeys
|
// List of indices into thisKeys
|
||||||
labelList findMatches
|
labelList findMatches
|
||||||
(
|
(
|
||||||
@ -194,19 +193,19 @@ labelList findMatches
|
|||||||
{
|
{
|
||||||
// Wildcard match
|
// Wildcard match
|
||||||
matches = findStrings(key, thisKeys);
|
matches = findStrings(key, thisKeys);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (shortcuts.size())
|
else if (shortcuts.size())
|
||||||
{
|
{
|
||||||
// See if patchGroups expand to valid thisKeys
|
// See if patchGroups expand to valid thisKeys
|
||||||
labelList indices = findStrings(key, shortcutNames);
|
labelList indices = findStrings(key, shortcutNames);
|
||||||
forAll(indices, i)
|
|
||||||
|
for (const label idx : indices)
|
||||||
{
|
{
|
||||||
const word& name = shortcutNames[indices[i]];
|
const word& name = shortcutNames[idx];
|
||||||
const wordList& keys = shortcuts[name];
|
const wordList& keys = shortcuts[name];
|
||||||
forAll(keys, j)
|
forAll(keys, j)
|
||||||
{
|
{
|
||||||
label index = thisKeys.find(keys[j]);
|
const label index = thisKeys.find(keys[j]);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
matches.append(index);
|
matches.append(index);
|
||||||
|
|||||||
@ -137,6 +137,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
labelList regionIDs =
|
labelList regionIDs =
|
||||||
findStrings(regionName, surf.regions());
|
findStrings(regionName, surf.regions());
|
||||||
|
|
||||||
if (modifier().modify(regionIDs, surf))
|
if (modifier().modify(regionIDs, surf))
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|||||||
@ -576,18 +576,22 @@ Foam::labelList Foam::polyBoundaryMesh::findIndices
|
|||||||
{
|
{
|
||||||
DynamicList<label> indices;
|
DynamicList<label> indices;
|
||||||
|
|
||||||
if (!key.empty())
|
if (key.empty())
|
||||||
{
|
{
|
||||||
if (key.isPattern())
|
// no-op
|
||||||
|
}
|
||||||
|
else if (key.isPattern())
|
||||||
{
|
{
|
||||||
indices = findStrings(key, this->names());
|
const regExp keyRe(key);
|
||||||
|
|
||||||
|
indices = findStrings(keyRe, this->names());
|
||||||
|
|
||||||
if (usePatchGroups && groupPatchIDs().size())
|
if (usePatchGroups && groupPatchIDs().size())
|
||||||
{
|
{
|
||||||
labelHashSet indexSet(indices);
|
labelHashSet indexSet(indices);
|
||||||
|
|
||||||
const wordList allGroupNames = groupPatchIDs().toc();
|
const wordList allGroupNames = groupPatchIDs().toc();
|
||||||
labelList groupIDs = findStrings(key, allGroupNames);
|
labelList groupIDs = findStrings(keyRe, allGroupNames);
|
||||||
forAll(groupIDs, i)
|
forAll(groupIDs, i)
|
||||||
{
|
{
|
||||||
const word& grpName = allGroupNames[groupIDs[i]];
|
const word& grpName = allGroupNames[groupIDs[i]];
|
||||||
@ -619,8 +623,7 @@ Foam::labelList Foam::polyBoundaryMesh::findIndices
|
|||||||
|
|
||||||
if (usePatchGroups && groupPatchIDs().size())
|
if (usePatchGroups && groupPatchIDs().size())
|
||||||
{
|
{
|
||||||
const HashTable<labelList>::const_iterator iter =
|
const auto iter = groupPatchIDs().cfind(key);
|
||||||
groupPatchIDs().find(key);
|
|
||||||
|
|
||||||
if (iter.found())
|
if (iter.found())
|
||||||
{
|
{
|
||||||
@ -637,7 +640,6 @@ Foam::labelList Foam::polyBoundaryMesh::findIndices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
@ -645,9 +647,11 @@ Foam::labelList Foam::polyBoundaryMesh::findIndices
|
|||||||
|
|
||||||
Foam::label Foam::polyBoundaryMesh::findIndex(const keyType& key) const
|
Foam::label Foam::polyBoundaryMesh::findIndex(const keyType& key) const
|
||||||
{
|
{
|
||||||
if (!key.empty())
|
if (key.empty())
|
||||||
{
|
{
|
||||||
if (key.isPattern())
|
// no-op
|
||||||
|
}
|
||||||
|
else if (key.isPattern())
|
||||||
{
|
{
|
||||||
labelList indices = this->findIndices(key);
|
labelList indices = this->findIndices(key);
|
||||||
|
|
||||||
@ -667,7 +671,6 @@ Foam::label Foam::polyBoundaryMesh::findIndex(const keyType& key) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// not found
|
// not found
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@ -342,9 +342,11 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
|
|||||||
{
|
{
|
||||||
labelList indices;
|
labelList indices;
|
||||||
|
|
||||||
if (!key.empty())
|
if (key.empty())
|
||||||
{
|
{
|
||||||
if (key.isPattern())
|
// no-op
|
||||||
|
}
|
||||||
|
else if (key.isPattern())
|
||||||
{
|
{
|
||||||
indices = findStrings(key, this->names());
|
indices = findStrings(key, this->names());
|
||||||
}
|
}
|
||||||
@ -361,7 +363,6 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
|
|||||||
}
|
}
|
||||||
indices.setSize(count);
|
indices.setSize(count);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
@ -373,16 +374,17 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
|
|||||||
const keyType& key
|
const keyType& key
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (!key.empty())
|
if (key.empty())
|
||||||
{
|
{
|
||||||
if (key.isPattern())
|
// no-op
|
||||||
|
}
|
||||||
|
else if (key.isPattern())
|
||||||
{
|
{
|
||||||
labelList indices = this->findIndices(key);
|
labelList indices = this->findIndices(key);
|
||||||
|
|
||||||
// return first element
|
|
||||||
if (!indices.empty())
|
if (!indices.empty())
|
||||||
{
|
{
|
||||||
return indices[0];
|
return indices.first(); // first match
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -395,7 +397,6 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Not found
|
// Not found
|
||||||
return -1;
|
return -1;
|
||||||
@ -412,7 +413,7 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID
|
|||||||
|
|
||||||
forAll(zones, zonei)
|
forAll(zones, zonei)
|
||||||
{
|
{
|
||||||
if (zones[zonei].name() == zoneName)
|
if (zoneName == zones[zonei].name())
|
||||||
{
|
{
|
||||||
return zonei;
|
return zonei;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ SourceFiles
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
//- Extract list indices
|
//- Extract list indices for all matches.
|
||||||
// The unary match predicate has the following signature:
|
// The unary match predicate has the following signature:
|
||||||
// \code
|
// \code
|
||||||
// bool operator()(const std::string& text);
|
// bool operator()(const std::string& text);
|
||||||
@ -78,26 +78,17 @@ namespace Foam
|
|||||||
template<class StringType>
|
template<class StringType>
|
||||||
labelList findStrings
|
labelList findStrings
|
||||||
(
|
(
|
||||||
const char* re,
|
const keyType& matcher,
|
||||||
const UList<StringType>& input,
|
const UList<StringType>& input,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return findMatchingStrings(regExp(re), input, invert);
|
return
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//- Return list indices for strings matching the regular expression
|
|
||||||
// Template partial specialization of findMatchingStrings
|
|
||||||
template<class StringType>
|
|
||||||
labelList findStrings
|
|
||||||
(
|
(
|
||||||
const std::string& re,
|
matcher.isPattern()
|
||||||
const UList<StringType>& input,
|
? findMatchingStrings(regExp(matcher), input, invert)
|
||||||
const bool invert=false
|
: findMatchingStrings(matcher, input, invert)
|
||||||
)
|
);
|
||||||
{
|
|
||||||
return findMatchingStrings(regExp(re), input, invert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -178,25 +169,17 @@ namespace Foam
|
|||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
StringListType subsetStrings
|
StringListType subsetStrings
|
||||||
(
|
(
|
||||||
const char* re,
|
const keyType& matcher,
|
||||||
const StringListType& input,
|
const StringListType& input,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return subsetMatchingStrings(regExp(re), input, invert);
|
return
|
||||||
}
|
|
||||||
|
|
||||||
//- Extract elements of StringList when regular expression matches
|
|
||||||
// Template partial specialization of subsetMatchingStrings
|
|
||||||
template<class StringListType>
|
|
||||||
StringListType subsetStrings
|
|
||||||
(
|
(
|
||||||
const std::string& re,
|
matcher.isPattern()
|
||||||
const StringListType& input,
|
? subsetMatchingStrings(regExp(matcher), input, invert)
|
||||||
const bool invert=false
|
: subsetMatchingStrings(matcher, input, invert)
|
||||||
)
|
);
|
||||||
{
|
|
||||||
return subsetMatchingStrings(regExp(re), input, invert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Extract elements of StringList when regular expression matches
|
//- Extract elements of StringList when regular expression matches
|
||||||
@ -265,30 +248,22 @@ namespace Foam
|
|||||||
inplaceSubsetMatchingStrings(matcher, input, invert);
|
inplaceSubsetMatchingStrings(matcher, input, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Inplace extract elements of StringList when regular expression matches
|
//- Extract elements of StringList when regular expression matches
|
||||||
// Template partial specialization of inplaceSubsetMatchingStrings
|
// Template partial specialization of subsetMatchingStrings
|
||||||
template<class StringListType>
|
template<class StringListType>
|
||||||
void inplaceSubsetStrings
|
void inplaceSubsetStrings
|
||||||
(
|
(
|
||||||
const char* re,
|
const keyType& matcher,
|
||||||
StringListType& input,
|
StringListType& input,
|
||||||
const bool invert=false
|
const bool invert=false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
inplaceSubsetMatchingStrings(regExp(re), input, invert);
|
return
|
||||||
}
|
|
||||||
|
|
||||||
//- Inplace extract elements of StringList when regular expression matches
|
|
||||||
// Template partial specialization of inplaceSubsetMatchingStrings
|
|
||||||
template<class StringListType>
|
|
||||||
void inplaceSubsetStrings
|
|
||||||
(
|
(
|
||||||
const std::string& re,
|
matcher.isPattern()
|
||||||
StringListType& input,
|
? inplaceSubsetMatchingStrings(regExp(matcher), input, invert)
|
||||||
const bool invert=false
|
: inplaceSubsetMatchingStrings(matcher, input, invert)
|
||||||
)
|
);
|
||||||
{
|
|
||||||
inplaceSubsetMatchingStrings(regExp(re), input, invert);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Inplace extract elements of StringList when regular expression matches
|
//- Inplace extract elements of StringList when regular expression matches
|
||||||
@ -330,6 +305,79 @@ namespace Foam
|
|||||||
inplaceSubsetMatchingStrings(wordRes::matcher(regexs), input, invert);
|
inplaceSubsetMatchingStrings(wordRes::matcher(regexs), input, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Find using C-string as a regex
|
||||||
|
// \deprecated (FEB-2018) Treating string as regex may be inefficient
|
||||||
|
// and lead to unintended results.
|
||||||
|
// Use regExp, keyType, wordRe instead, or findMatchingStrings()
|
||||||
|
template<class StringType>
|
||||||
|
labelList findStrings
|
||||||
|
(
|
||||||
|
const char* disallowed,
|
||||||
|
const UList<StringType>& input,
|
||||||
|
const bool invert=false
|
||||||
|
) = delete;
|
||||||
|
|
||||||
|
//- Find using string as a regex
|
||||||
|
// \deprecated (FEB-2018) Treating string as regex may be inefficient
|
||||||
|
// and lead to unintended results.
|
||||||
|
// Use regExp, keyType, wordRe instead, or findMatchingStrings()
|
||||||
|
template<class StringType>
|
||||||
|
labelList findStrings
|
||||||
|
(
|
||||||
|
const std::string& disallowed,
|
||||||
|
const UList<StringType>& input,
|
||||||
|
const bool invert=false
|
||||||
|
) = delete;
|
||||||
|
|
||||||
|
//- Subset using C-string as a regex
|
||||||
|
// \deprecated (FEB-2018) Treating string as regex may be inefficient
|
||||||
|
// and lead to unintended results.
|
||||||
|
// Use regExp, keyType, wordRe instead, or subsetMatchingStrings()
|
||||||
|
template<class StringListType>
|
||||||
|
StringListType subsetStrings
|
||||||
|
(
|
||||||
|
const char* disallowed,
|
||||||
|
const StringListType& input,
|
||||||
|
const bool invert=false
|
||||||
|
) = delete;
|
||||||
|
|
||||||
|
//- Subset using string as a regex
|
||||||
|
// \deprecated (FEB-2018) Treating string as regex may be inefficient
|
||||||
|
// and lead to unintended results.
|
||||||
|
// Use regExp, keyType, wordRe instead, or subsetMatchingStrings()
|
||||||
|
template<class StringListType>
|
||||||
|
StringListType subsetStrings
|
||||||
|
(
|
||||||
|
const std::string& disallowed,
|
||||||
|
const StringListType& input,
|
||||||
|
const bool invert=false
|
||||||
|
) = delete;
|
||||||
|
|
||||||
|
//- Subset using C-string as a regex
|
||||||
|
// \deprecated (FEB-2018) Treating string as regex may be inefficient
|
||||||
|
// and lead to unintended results.
|
||||||
|
// Use regExp, keyType, wordRe instead, or inplaceSubsetMatchingStrings()
|
||||||
|
template<class StringListType>
|
||||||
|
void inplaceSubsetStrings
|
||||||
|
(
|
||||||
|
const char* disallowed,
|
||||||
|
StringListType& input,
|
||||||
|
const bool invert=false
|
||||||
|
) = delete;
|
||||||
|
|
||||||
|
//- Subset using string as a regex
|
||||||
|
// \deprecated (FEB-2018) Treating string as regex may be inefficient
|
||||||
|
// and lead to unintended results.
|
||||||
|
// Use keyType, wordRe instead, or inplaceSubsetMatchingStrings()
|
||||||
|
template<class StringListType>
|
||||||
|
void inplaceSubsetStrings
|
||||||
|
(
|
||||||
|
const std::string& disallowed,
|
||||||
|
StringListType& input,
|
||||||
|
const bool invert=false
|
||||||
|
) = delete;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -149,11 +149,7 @@ void Foam::ensightMesh::correct()
|
|||||||
if (!matcher.empty())
|
if (!matcher.empty())
|
||||||
{
|
{
|
||||||
useAll = false;
|
useAll = false;
|
||||||
matched = findMatchingStrings
|
matched = findStrings(matcher, patchNames);
|
||||||
(
|
|
||||||
matcher,
|
|
||||||
patchNames
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,11 +244,7 @@ void Foam::ensightMesh::correct()
|
|||||||
const wordRes& matcher = option().faceZoneSelection();
|
const wordRes& matcher = option().faceZoneSelection();
|
||||||
|
|
||||||
wordList selectZones = mesh_.faceZones().names();
|
wordList selectZones = mesh_.faceZones().names();
|
||||||
inplaceSubsetMatchingStrings
|
subsetMatchingStrings(matcher, selectZones);
|
||||||
(
|
|
||||||
matcher,
|
|
||||||
selectZones
|
|
||||||
);
|
|
||||||
|
|
||||||
// have same order as later with sortedToc()
|
// have same order as later with sortedToc()
|
||||||
Foam::sort(selectZones);
|
Foam::sort(selectZones);
|
||||||
|
|||||||
@ -194,9 +194,11 @@ Foam::labelList Foam::faBoundaryMesh::findIndices
|
|||||||
{
|
{
|
||||||
DynamicList<label> indices;
|
DynamicList<label> indices;
|
||||||
|
|
||||||
if (!key.empty())
|
if (key.empty())
|
||||||
{
|
{
|
||||||
if (key.isPattern())
|
// no-op
|
||||||
|
}
|
||||||
|
else if (key.isPattern())
|
||||||
{
|
{
|
||||||
indices = findStrings(key, this->names());
|
indices = findStrings(key, this->names());
|
||||||
}
|
}
|
||||||
@ -215,7 +217,6 @@ Foam::labelList Foam::faBoundaryMesh::findIndices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,27 +77,27 @@ Foam::ParticleErosion<CloudType>::ParticleErosion
|
|||||||
psi_(this->coeffDict().template lookupOrDefault<scalar>("psi", 2.0)),
|
psi_(this->coeffDict().template lookupOrDefault<scalar>("psi", 2.0)),
|
||||||
K_(this->coeffDict().template lookupOrDefault<scalar>("K", 2.0))
|
K_(this->coeffDict().template lookupOrDefault<scalar>("K", 2.0))
|
||||||
{
|
{
|
||||||
const wordList allPatchNames = owner.mesh().boundaryMesh().names();
|
const wordList allPatchNames(owner.mesh().boundaryMesh().names());
|
||||||
wordList patchName(this->coeffDict().lookup("patches"));
|
const wordReList patchNames(this->coeffDict().lookup("patches"));
|
||||||
|
|
||||||
labelHashSet uniquePatchIDs;
|
labelHashSet uniqIds;
|
||||||
forAllReverse(patchName, i)
|
for (const wordRe& re : patchNames)
|
||||||
{
|
{
|
||||||
labelList patchIDs = findStrings(patchName[i], allPatchNames);
|
labelList ids = findStrings(re, allPatchNames);
|
||||||
|
|
||||||
if (patchIDs.empty())
|
if (ids.empty())
|
||||||
{
|
{
|
||||||
WarningInFunction
|
WarningInFunction
|
||||||
<< "Cannot find any patch names matching " << patchName[i]
|
<< "Cannot find any patch names matching " << re
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
uniquePatchIDs.insert(patchIDs);
|
uniqIds.insert(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
patchIDs_ = uniquePatchIDs.toc();
|
patchIDs_ = uniqIds.sortedToc();
|
||||||
|
|
||||||
// trigger ther creation of the Q field
|
// trigger creation of the Q field
|
||||||
preEvolve();
|
preEvolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,13 +117,6 @@ Foam::ParticleErosion<CloudType>::ParticleErosion
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class CloudType>
|
|
||||||
Foam::ParticleErosion<CloudType>::~ParticleErosion()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class CloudType>
|
template<class CloudType>
|
||||||
|
|||||||
@ -120,7 +120,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~ParticleErosion();
|
virtual ~ParticleErosion() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|||||||
@ -134,33 +134,32 @@ Foam::PatchPostProcessing<CloudType>::PatchPostProcessing
|
|||||||
times_(),
|
times_(),
|
||||||
patchData_()
|
patchData_()
|
||||||
{
|
{
|
||||||
const wordList allPatchNames = owner.mesh().boundaryMesh().names();
|
const wordList allPatchNames(owner.mesh().boundaryMesh().names());
|
||||||
wordList patchName(this->coeffDict().lookup("patches"));
|
const wordReList patchNames(this->coeffDict().lookup("patches"));
|
||||||
|
|
||||||
labelHashSet uniquePatchIDs;
|
labelHashSet uniqIds;
|
||||||
forAllReverse(patchName, i)
|
for (const wordRe& re : patchNames)
|
||||||
{
|
{
|
||||||
labelList patchIDs = findStrings(patchName[i], allPatchNames);
|
labelList ids = findStrings(re, allPatchNames);
|
||||||
|
|
||||||
if (patchIDs.empty())
|
if (ids.empty())
|
||||||
{
|
{
|
||||||
WarningInFunction
|
WarningInFunction
|
||||||
<< "Cannot find any patch names matching " << patchName[i]
|
<< "Cannot find any patch names matching " << re
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
uniquePatchIDs.insert(patchIDs);
|
uniqIds.insert(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
patchIDs_ = uniquePatchIDs.toc();
|
patchIDs_ = uniqIds.sortedToc();
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
forAll(patchIDs_, i)
|
for (const label patchi : patchIDs_)
|
||||||
{
|
{
|
||||||
const label patchi = patchIDs_[i];
|
Info<< "Post-process patch "
|
||||||
const word& patchName = owner.mesh().boundaryMesh()[patchi].name();
|
<< owner.mesh().boundaryMesh()[patchi].name() << endl;
|
||||||
Info<< "Post-process patch " << patchName << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,13 +182,6 @@ Foam::PatchPostProcessing<CloudType>::PatchPostProcessing
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class CloudType>
|
|
||||||
Foam::PatchPostProcessing<CloudType>::~PatchPostProcessing()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class CloudType>
|
template<class CloudType>
|
||||||
|
|||||||
@ -115,7 +115,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~PatchPostProcessing();
|
virtual ~PatchPostProcessing() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|||||||
@ -46,22 +46,22 @@ Foam::patchInteractionDataList::patchInteractionDataList
|
|||||||
patchGroupIDs_(this->size())
|
patchGroupIDs_(this->size())
|
||||||
{
|
{
|
||||||
const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
|
const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
|
||||||
const wordList allPatchNames = bMesh.names();
|
const wordList allPatchNames(bMesh.names());
|
||||||
|
|
||||||
const List<patchInteractionData>& items = *this;
|
const List<patchInteractionData>& items = *this;
|
||||||
forAllReverse(items, i)
|
forAllReverse(items, i)
|
||||||
{
|
{
|
||||||
const word& patchName = items[i].patchName();
|
const word& patchName = items[i].patchName();
|
||||||
labelList patchIDs = findStrings(patchName, allPatchNames);
|
labelList ids = findIndices(allPatchNames, patchName);
|
||||||
|
|
||||||
if (patchIDs.empty())
|
if (ids.empty())
|
||||||
{
|
{
|
||||||
WarningInFunction
|
WarningInFunction
|
||||||
<< "Cannot find any patch names matching " << patchName
|
<< "Cannot find any patch names matching " << patchName
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
patchGroupIDs_[i].transfer(patchIDs);
|
patchGroupIDs_[i].transfer(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all patches are specified
|
// Check that all patches are specified
|
||||||
|
|||||||
@ -101,22 +101,26 @@ const Foam::coordinateSystems& Foam::coordinateSystems::New
|
|||||||
Foam::labelList Foam::coordinateSystems::findIndices(const keyType& key) const
|
Foam::labelList Foam::coordinateSystems::findIndices(const keyType& key) const
|
||||||
{
|
{
|
||||||
labelList indices;
|
labelList indices;
|
||||||
if (key.isPattern())
|
if (key.empty())
|
||||||
{
|
{
|
||||||
indices = findStrings(key, toc());
|
// no-op
|
||||||
|
}
|
||||||
|
else if (key.isPattern())
|
||||||
|
{
|
||||||
|
indices = findStrings(key, this->toc());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
indices.setSize(size());
|
indices.setSize(this->size());
|
||||||
label nFound = 0;
|
label count = 0;
|
||||||
forAll(*this, i)
|
forAll(*this, i)
|
||||||
{
|
{
|
||||||
if (key == operator[](i).name())
|
if (key == operator[](i).name())
|
||||||
{
|
{
|
||||||
indices[nFound++] = i;
|
indices[count++] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indices.setSize(nFound);
|
indices.setSize(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return indices;
|
return indices;
|
||||||
@ -125,13 +129,16 @@ Foam::labelList Foam::coordinateSystems::findIndices(const keyType& key) const
|
|||||||
|
|
||||||
Foam::label Foam::coordinateSystems::findIndex(const keyType& key) const
|
Foam::label Foam::coordinateSystems::findIndex(const keyType& key) const
|
||||||
{
|
{
|
||||||
if (key.isPattern())
|
if (key.empty())
|
||||||
|
{
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
else if (key.isPattern())
|
||||||
{
|
{
|
||||||
labelList indices = findIndices(key);
|
labelList indices = findIndices(key);
|
||||||
// return first element
|
|
||||||
if (!indices.empty())
|
if (!indices.empty())
|
||||||
{
|
{
|
||||||
return indices[0];
|
return indices.first(); // first match
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -145,6 +152,7 @@ Foam::label Foam::coordinateSystems::findIndex(const keyType& key) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not found
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -120,12 +120,12 @@ Foam::label Foam::triSurfaceLoader::select(const wordRe& mat)
|
|||||||
|
|
||||||
if (mat.isPattern())
|
if (mat.isPattern())
|
||||||
{
|
{
|
||||||
foundIds = findMatchingStrings(mat, available_);
|
foundIds = findStrings(mat, available_);
|
||||||
sort(foundIds);
|
sort(foundIds);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const word& plain = static_cast<const word&>(mat);
|
const word& plain = mat;
|
||||||
if (available_.found(plain))
|
if (available_.found(plain))
|
||||||
{
|
{
|
||||||
foundIds.append(available_[plain]);
|
foundIds.append(available_[plain]);
|
||||||
@ -164,7 +164,7 @@ Foam::label Foam::triSurfaceLoader::select(const UList<wordRe>& matcher)
|
|||||||
{
|
{
|
||||||
if (mat.isPattern())
|
if (mat.isPattern())
|
||||||
{
|
{
|
||||||
labelList indices = findMatchingStrings(mat, available_);
|
labelList indices = findStrings(mat, available_);
|
||||||
sort(indices);
|
sort(indices);
|
||||||
|
|
||||||
for (const label idx : indices)
|
for (const label idx : indices)
|
||||||
@ -177,7 +177,7 @@ Foam::label Foam::triSurfaceLoader::select(const UList<wordRe>& matcher)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const word& plain = static_cast<const word&>(mat);
|
const word& plain = mat;
|
||||||
if (available_.found(plain))
|
if (available_.found(plain))
|
||||||
{
|
{
|
||||||
const label idx = available_[plain];
|
const label idx = available_[plain];
|
||||||
|
|||||||
@ -249,7 +249,7 @@ curvatureSeparation::curvatureSeparation
|
|||||||
|
|
||||||
forAllReverse(prIn, i)
|
forAllReverse(prIn, i)
|
||||||
{
|
{
|
||||||
labelList patchIDs = findStrings(prIn[i].first(), allPatchNames);
|
labelList patchIDs = findIndices(allPatchNames, prIn[i].first());
|
||||||
forAll(patchIDs, j)
|
forAll(patchIDs, j)
|
||||||
{
|
{
|
||||||
const label patchi = patchIDs[j];
|
const label patchi = patchIDs[j];
|
||||||
|
|||||||
Reference in New Issue
Block a user