ENH: improve consistency of ListOps and stringListOps

- subsetList, inplaceSubsetList with optional inverted logic.

- use moveable elements where possible.

- allow optional starting offset for the identity global function.
  Eg,  'identity(10, start)' vs 'identity(10) + start'
This commit is contained in:
Mark Olesen
2018-02-21 12:58:00 +01:00
parent 3ee2f3293e
commit f959927910
22 changed files with 472 additions and 425 deletions

View File

@ -37,6 +37,12 @@ Description
using namespace Foam; using namespace Foam;
void printCompare(const face& a, const face& b)
{
Info<< "Compare " << a << " and " << b
<< " Match = " << face::compare(a, b) << endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:
@ -96,44 +102,35 @@ int main(int argc, char *argv[])
Info<< nl << nl << "Compare two faces: " << endl; Info<< nl << nl << "Compare two faces: " << endl;
face a(identity(5)); face a(identity(5));
Info<< "Compare " << a << " and " << a << " Match = " << face::compare(a, a) printCompare(a, a);
<< endl;
face b(reverseList(a)); face b(reverseList(a));
Info<< "Compare " << a << " and " << b << " Match = " << face::compare(a, b) printCompare(a, b);
<< endl;
face c(a); face c(a);
c[4] = 3; c[4] = 3;
Info<< "Compare " << a << " and " << c << " Match = " << face::compare(a, c) printCompare(a, c);
<< endl;
face d(rotateList(a, 2)); face d(rotateList(a, 2));
Info<< "Compare " << a << " and " << d << " Match = " << face::compare(a, d) printCompare(a, d);
<< endl;
face g(labelList(5, 1)); face g(labelList(5, 1));
face h(g); face h(g);
Info<< "Compare " << g << " and " << h << " Match = " << face::compare(g, h) printCompare(g, h);
<< endl;
g[0] = 2; g[0] = 2;
h[3] = 2; h[3] = 2;
Info<< "Compare " << g << " and " << h << " Match = " << face::compare(g, h) printCompare(g, h);
<< endl;
g[4] = 3; g[4] = 3;
h[4] = 3; h[4] = 3;
Info<< "Compare " << g << " and " << h << " Match = " << face::compare(g, h) printCompare(g, h);
<< endl;
face face1(identity(1)); face face1(identity(1));
Info<< "Compare " << face1 << " and " << face1 printCompare(face1, face1);
<< " Match = " << face::compare(face1, face1) << endl;
face face2(identity(1)+1); face face2(identity(1, 2));
Info<< "Compare " << face1 << " and " << face2 printCompare(face1, face2);
<< " Match = " << face::compare(face1, face2) << endl;
Info<< nl << nl << "Zero face" << nl << endl; Info<< nl << nl << "Zero face" << nl << endl;

View File

@ -261,7 +261,7 @@ int main(int argc, char *argv[])
// ( // (
// mesh, // mesh,
// pp, // pp,
// identity(pp.size())+pp.start() // identity(pp.size(), pp.start())
// ) // )
// ); // );
// forAll(pn, pointi) // forAll(pn, pointi)
@ -278,7 +278,7 @@ int main(int argc, char *argv[])
// ( // (
// mesh, // mesh,
// pp, // pp,
// identity(pp.size())+pp.start() // identity(pp.size(), pp.start())
// ) // )
// ); // );
// forAll(pn, pointi) // forAll(pn, pointi)

View File

@ -247,7 +247,7 @@ int main(int argc, char *argv[])
<< " by this amount" << nl << endl; << " by this amount" << nl << endl;
patch1Map = identity(surface1.patches().size()); patch1Map = identity(surface1.patches().size());
patch2Map = identity(surface2.patches().size()) + patch1Map.size(); patch2Map = identity(surface2.patches().size(), patch1Map.size());
nNewPatches = surface1.patches().size()+surface2.patches().size(); nNewPatches = surface1.patches().size()+surface2.patches().size();
} }

View File

@ -165,10 +165,10 @@ void createBoundaryEdgeTrees
// Boundary edges // Boundary edges
treeBoundaryEdges[surfI] = treeBoundaryEdges[surfI] =
labelList identity
( (
identity(surf.nEdges() - surf.nInternalEdges()) surf.nEdges() - surf.nInternalEdges(),
+ surf.nInternalEdges() surf.nInternalEdges()
); );
Random rndGen(17301893); Random rndGen(17301893);

View File

@ -84,14 +84,7 @@ Foam::scalar Foam::Distribution<Type>::totalWeight(direction cmpt) const
template<class Type> template<class Type>
Foam::List<Foam::label> Foam::Distribution<Type>::keys(direction cmpt) const Foam::List<Foam::label> Foam::Distribution<Type>::keys(direction cmpt) const
{ {
List<label> keys = identity((*this)[cmpt].size()); return identity((*this)[cmpt].size(), listStarts_[cmpt]);
forAll(keys, k)
{
keys[k] += listStarts_[cmpt];
}
return keys;
} }

View File

@ -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-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -42,22 +42,23 @@ Foam::labelList Foam::invert
forAll(map, i) forAll(map, i)
{ {
const label newPos = map[i]; const label newIdx = map[i];
if (newPos >= 0) if (newIdx >= 0)
{ {
if (inverse[newPos] >= 0) if (inverse[newIdx] >= 0)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Map is not one-to-one. At index " << i << "Map is not one-to-one. At index " << i
<< " element " << newPos << " has already occurred before" << " element " << newIdx << " has already occurred before"
<< nl << "Please use invertOneToMany instead" << nl << "Please use invertOneToMany instead"
<< abort(FatalError); << abort(FatalError);
} }
inverse[newPos] = i; inverse[newIdx] = i;
} }
} }
return inverse; return inverse;
} }
@ -68,31 +69,31 @@ Foam::labelListList Foam::invertOneToMany
const labelUList& map const labelUList& map
) )
{ {
labelList nElems(len, 0); labelList sizes(len, 0);
forAll(map, i) for (const label newIdx : map)
{ {
if (map[i] >= 0) if (newIdx >= 0)
{ {
nElems[map[i]]++; sizes[newIdx]++;
} }
} }
labelListList inverse(len); labelListList inverse(len);
forAll(nElems, i) for (label i=0; i<len; ++i)
{ {
inverse[i].setSize(nElems[i]); inverse[i].setSize(sizes[i]);
nElems[i] = 0; sizes[i] = 0; // reset size counter
} }
forAll(map, i) forAll(map, i)
{ {
const label newI = map[i]; const label newIdx = map[i];
if (newI >= 0) if (newIdx >= 0)
{ {
inverse[newI][nElems[newI]++] = i; inverse[newIdx][sizes[newIdx]++] = i;
} }
} }
@ -100,13 +101,13 @@ Foam::labelListList Foam::invertOneToMany
} }
Foam::labelList Foam::identity(const label len) Foam::labelList Foam::identity(const label len, const label start)
{ {
labelList map(len); labelList map(len);
for (label i = 0; i < len; ++i) for (label i = 0; i < len; ++i)
{ {
map[i] = i; map[i] = i + start;
} }
return map; return map;

View File

@ -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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -59,12 +59,12 @@ static const List<Type>& emptyList()
//- Renumber the values (not the indices) of a list. //- Renumber the values (not the indices) of a list.
// Negative ListType elements are left untouched. // Negative ListType elements are left untouched.
template<class ListType> template<class ListType>
ListType renumber(const labelUList& oldToNew, const ListType& lst); ListType renumber(const labelUList& oldToNew, const ListType& input);
//- Inplace renumber the values (not the indices) of a list. //- Inplace renumber the values (not the indices) of a list.
// Negative ListType elements are left untouched. // Negative ListType elements are left untouched.
template<class ListType> template<class ListType>
void inplaceRenumber(const labelUList& oldToNew, ListType& lst); void inplaceRenumber(const labelUList& oldToNew, ListType& input);
//- Reorder the elements of a list. //- Reorder the elements of a list.
@ -76,7 +76,7 @@ template<class ListType>
ListType reorder ListType reorder
( (
const labelUList& oldToNew, const labelUList& oldToNew,
const ListType& lst, const ListType& input,
const bool prune = false const bool prune = false
); );
@ -89,7 +89,7 @@ template<class ListType>
void inplaceReorder void inplaceReorder
( (
const labelUList& oldToNew, const labelUList& oldToNew,
ListType& lst, ListType& input,
const bool prune = false const bool prune = false
); );
@ -99,22 +99,22 @@ void inplaceReorder
//- Map values. Do not map negative values. //- Map values. Do not map negative values.
template<class Container> template<class Container>
void inplaceMapValue(const labelUList& oldToNew, Container& lst); void inplaceMapValue(const labelUList& oldToNew, Container& input);
//- Recreate with mapped keys. Do not map elements with negative key. //- Recreate with mapped keys. Do not map elements with negative key.
template<class Container> template<class Container>
void inplaceMapKey(const labelUList& oldToNew, Container& lst); void inplaceMapKey(const labelUList& oldToNew, Container& input);
//- Generate the (stable) sort order for the list //- Generate the (stable) sort order for the list
template<class T> template<class T>
void sortedOrder(const UList<T>& lst, labelList& order); void sortedOrder(const UList<T>& input, labelList& order);
//- Sort using specified list compare predicate //- Sort using specified list compare predicate
template<class T, class ListComparePredicate> template<class T, class ListComparePredicate>
void sortedOrder void sortedOrder
( (
const UList<T>& lst, const UList<T>& input,
labelList& order, labelList& order,
const ListComparePredicate& comp const ListComparePredicate& comp
); );
@ -122,14 +122,14 @@ void sortedOrder
//- Generate (sorted) indices corresponding to duplicate list values //- Generate (sorted) indices corresponding to duplicate list values
template<class T> template<class T>
void duplicateOrder(const UList<T>& lst, labelList& order); void duplicateOrder(const UList<T>& input, labelList& order);
//- Generate (sorted) indices corresponding to duplicate list values //- Generate (sorted) indices corresponding to duplicate list values
// sort using specified list compare predicate // sort using specified list compare predicate
template<class T, class ListComparePredicate> template<class T, class ListComparePredicate>
void duplicateOrder void duplicateOrder
( (
const UList<T>& lst, const UList<T>& input,
labelList& order, labelList& order,
const ListComparePredicate& comp const ListComparePredicate& comp
); );
@ -137,14 +137,14 @@ void duplicateOrder
//- Generate (sorted) indices corresponding to unique list values //- Generate (sorted) indices corresponding to unique list values
template<class T> template<class T>
void uniqueOrder(const UList<T>& lst, labelList& order); void uniqueOrder(const UList<T>& input, labelList& order);
//- Generate (sorted) indices corresponding to unique list values //- Generate (sorted) indices corresponding to unique list values
// sort using specified list compare predicate // sort using specified list compare predicate
template<class T, class ListComparePredicate> template<class T, class ListComparePredicate>
void uniqueOrder void uniqueOrder
( (
const UList<T>& lst, const UList<T>& input,
labelList& order, labelList& order,
const ListComparePredicate& comp const ListComparePredicate& comp
); );
@ -153,14 +153,14 @@ void uniqueOrder
//- Inplace sorting and removal of duplicates. //- Inplace sorting and removal of duplicates.
// Do not use FixedList for the input list, since it doesn't resize. // Do not use FixedList for the input list, since it doesn't resize.
template<class ListType> template<class ListType>
void inplaceUniqueSort(ListType& lst); void inplaceUniqueSort(ListType& input);
//- Inplace sorting and removal of duplicates. //- Inplace sorting and removal of duplicates.
// Do not use FixedList for the input list, since it doesn't resize. // Do not use FixedList for the input list, since it doesn't resize.
template<class ListType, class ListComparePredicate> template<class ListType, class ListComparePredicate>
void inplaceUniqueSort void inplaceUniqueSort
( (
ListType& lst, ListType& input,
const ListComparePredicate& comp const ListComparePredicate& comp
); );
@ -178,19 +178,19 @@ void inplaceSubset(const UList<T>& select, const T& value, ListType&);
//- Extract elements of List when select is true //- Extract elements of List when select is true
// eg, to extract all selected elements: // eg, to extract all selected elements:
// subset<boolList, labelList>(selectedElems, lst); // subset<boolList, labelList>(selectedElems, list);
// Note a labelHashSet can also be used as the bool-list. // Note a labelHashSet can also be used as the bool-list.
// Do not use FixedList for the input list, since it doesn't resize. // Do not use FixedList for the input list, since it doesn't resize.
template<class BoolListType, class ListType> template<class BoolListType, class ListType>
ListType subset(const BoolListType& select, const ListType& lst); ListType subset(const BoolListType& select, const ListType& input);
//- Inplace extract elements of List when select is true //- Inplace extract elements of List when select is true
// eg, to extract all selected elements: // eg, to extract all selected elements:
// inplaceSubset<boolList, labelList>(selectedElems, lst); // inplaceSubset<boolList, labelList>(selectedElems, list);
// Note a labelHashSet can also be used as the bool-list. // Note a labelHashSet can also be used as the bool-list.
// Do not use FixedList for the input list, since it doesn't resize. // Do not use FixedList for the input list, since it doesn't resize.
template<class BoolListType, class ListType> template<class BoolListType, class ListType>
void inplaceSubset(const BoolListType& select, ListType& lst); void inplaceSubset(const BoolListType& select, ListType& input);
//- Copy a subset of the input list when predicate is true. //- Copy a subset of the input list when predicate is true.
@ -199,7 +199,8 @@ template<class ListType, class UnaryPredicate>
ListType subsetList ListType subsetList
( (
const ListType& input, const ListType& input,
const UnaryPredicate& pred const UnaryPredicate& pred,
const bool invert=false
); );
//- Inplace subset of the list when predicate is true. //- Inplace subset of the list when predicate is true.
@ -208,7 +209,8 @@ template<class ListType, class UnaryPredicate>
void inplaceSubsetList void inplaceSubsetList
( (
ListType& input, ListType& input,
const UnaryPredicate& pred const UnaryPredicate& pred,
const bool invert=false
); );
@ -242,7 +244,8 @@ List<OutputIntListType> invertManyToMany
} }
//- Create identity map of the given length with (map[i] == i) //- Create identity map of the given length with (map[i] == i)
labelList identity(const label len); // Optionally with an alternative start index, so that (map[i] == i+start)
labelList identity(const label len, const label start=0);
//- Find first occurence of given element and return index, //- Find first occurence of given element and return index,
// return -1 if not found. Linear search. // return -1 if not found. Linear search.
@ -265,23 +268,23 @@ labelList findIndices
( (
const ListType& input, const ListType& input,
typename ListType::const_reference val, typename ListType::const_reference val,
const label start=0 label start=0
); );
//- Opposite of findIndices: set values at indices to given value //- Opposite of findIndices: set values at indices to given value
template<class ListType> template<class ListType>
void setValues void setValues
( (
ListType& l, ListType& input,
const labelUList& indices, const labelUList& indices,
typename ListType::const_reference t typename ListType::const_reference val
); );
//- Opposite of findIndices: set values at indices to given value //- Opposite of findIndices: set values at indices to given value
template<class ListType> template<class ListType>
ListType createWithValues ListType createWithValues
( (
const label sz, const label len,
typename ListType::const_reference initValue, typename ListType::const_reference initValue,
const labelUList& indices, const labelUList& indices,
typename ListType::const_reference setValue typename ListType::const_reference setValue
@ -290,13 +293,13 @@ ListType createWithValues
//- Find index of max element (and larger than given element). //- Find index of max element (and larger than given element).
// return -1 if not found. Linear search. // return -1 if not found. Linear search.
template<class ListType> template<class ListType>
label findMax(const ListType& l, const label start=0); label findMax(const ListType& input, const label start=0);
//- Find index of min element (and less than given element). //- Find index of min element (and less than given element).
// return -1 if not found. Linear search. // return -1 if not found. Linear search.
template<class ListType> template<class ListType>
label findMin(const ListType& l, const label start=0); label findMin(const ListType& input, const label start=0);
//- Find first occurrence of given element in sorted list and return index, //- Find first occurrence of given element in sorted list and return index,
@ -304,21 +307,21 @@ label findMin(const ListType& l, const label start=0);
template<class ListType> template<class ListType>
label findSortedIndex label findSortedIndex
( (
const ListType& l, const ListType& input,
typename ListType::const_reference t, typename ListType::const_reference val,
const label start=0 const label start=0
); );
//- Find last element < given value in sorted list and return index, //- Find last element < given value in sorted list and return index,
// return -1 if not found. Binary search. // return -1 if not found. Binary search.
template<class ListType, class BinaryOp> template<class ListType, class BinaryPredicate>
label findLower label findLower
( (
const ListType& l, const ListType& input,
typename ListType::const_reference t, typename ListType::const_reference val,
const label start, const label start,
const BinaryOp& bop const BinaryPredicate& pred
); );
@ -327,8 +330,8 @@ label findLower
template<class ListType> template<class ListType>
label findLower label findLower
( (
const ListType& l, const ListType& input,
typename ListType::const_reference t, typename ListType::const_reference val,
const label start=0 const label start=0
); );
@ -369,12 +372,12 @@ public:
//- Reverse a list. First element becomes last element etc. //- Reverse a list. First element becomes last element etc.
template<class ListType> template<class ListType>
ListType reverseList(const ListType& list); ListType reverseList(const ListType& input);
//- Inplace reversal of a list using Swap. //- Inplace reversal of a list using Swap.
template<class ListType> template<class ListType>
void inplaceReverseList(ListType& list); void inplaceReverseList(ListType& input);
//- Rotate a list by n places. If n is positive rotate clockwise/right/down. //- Rotate a list by n places. If n is positive rotate clockwise/right/down.

File diff suppressed because it is too large Load Diff

View File

@ -369,7 +369,7 @@ inline void Foam::UList<T>::swap(UList<T>& lst)
template<class T> template<class T>
inline void Foam::reverse(UList<T>& lst, const label n) inline void Foam::reverse(UList<T>& lst, const label n)
{ {
for (int i=0; i<n/2; ++i) for (label i=0; i<n/2; ++i)
{ {
Foam::Swap(lst[i], lst[n-1-i]); Foam::Swap(lst[i], lst[n-1-i]);
} }

View File

@ -54,7 +54,7 @@ namespace Foam
labelList findMatchingStrings labelList findMatchingStrings
( (
const UnaryMatchPredicate& matcher, const UnaryMatchPredicate& matcher,
const UList<StringType>& lst, const UList<StringType>& input,
const bool invert=false const bool invert=false
); );
@ -65,11 +65,11 @@ namespace Foam
labelList findStrings labelList findStrings
( (
const regExp& matcher, const regExp& matcher,
const UList<StringType>& lst, const UList<StringType>& input,
const bool invert=false const bool invert=false
) )
{ {
return findMatchingStrings(matcher, lst, invert); return findMatchingStrings(matcher, input, invert);
} }
@ -79,11 +79,11 @@ namespace Foam
labelList findStrings labelList findStrings
( (
const char* re, const char* re,
const UList<StringType>& lst, const UList<StringType>& input,
const bool invert=false const bool invert=false
) )
{ {
return findMatchingStrings(regExp(re), lst, invert); return findMatchingStrings(regExp(re), input, invert);
} }
@ -93,11 +93,11 @@ namespace Foam
labelList findStrings labelList findStrings
( (
const std::string& re, const std::string& re,
const UList<StringType>& lst, const UList<StringType>& input,
const bool invert=false const bool invert=false
) )
{ {
return findMatchingStrings(regExp(re), lst, invert); return findMatchingStrings(regExp(re), input, invert);
} }
@ -107,11 +107,11 @@ namespace Foam
labelList findStrings labelList findStrings
( (
const wordRe& matcher, const wordRe& matcher,
const UList<StringType>& lst, const UList<StringType>& input,
const bool invert=false const bool invert=false
) )
{ {
return findMatchingStrings(matcher, lst, invert); return findMatchingStrings(matcher, input, invert);
} }
@ -121,11 +121,11 @@ namespace Foam
labelList findStrings labelList findStrings
( (
const wordRes& matcher, const wordRes& matcher,
const UList<StringType>& lst, const UList<StringType>& input,
const bool invert=false const bool invert=false
) )
{ {
return findMatchingStrings(matcher, lst, invert); return findMatchingStrings(matcher, input, invert);
} }
//- Return list indices for strings matching one of the regular expression //- Return list indices for strings matching one of the regular expression
@ -148,13 +148,13 @@ namespace Foam
// optionally invert the match // optionally invert the match
// eg, to extract all selected elements: // eg, to extract all selected elements:
// \code // \code
// subsetMatchingStrings<regExp, stringList>(myRegExp, lst); // subsetMatchingStrings<regExp, stringList>(myRegExp, list);
// \endcode // \endcode
template<class UnaryMatchPredicate, class StringListType> template<class UnaryMatchPredicate, class StringListType>
StringListType subsetMatchingStrings StringListType subsetMatchingStrings
( (
const UnaryMatchPredicate& matcher, const UnaryMatchPredicate& matcher,
const StringListType& lst, const StringListType& input,
const bool invert=false const bool invert=false
); );
@ -165,11 +165,11 @@ namespace Foam
StringListType subsetStrings StringListType subsetStrings
( (
const regExp& matcher, const regExp& matcher,
const StringListType& lst, const StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
return subsetMatchingStrings(matcher, lst, invert); return subsetMatchingStrings(matcher, input, invert);
} }
@ -179,11 +179,11 @@ namespace Foam
StringListType subsetStrings StringListType subsetStrings
( (
const char* re, const char* re,
const StringListType& lst, const StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
return subsetMatchingStrings(regExp(re), lst, invert); return subsetMatchingStrings(regExp(re), input, invert);
} }
//- Extract elements of StringList when regular expression matches //- Extract elements of StringList when regular expression matches
@ -192,11 +192,11 @@ namespace Foam
StringListType subsetStrings StringListType subsetStrings
( (
const std::string& re, const std::string& re,
const StringListType& lst, const StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
return subsetMatchingStrings(regExp(re), lst, invert); return subsetMatchingStrings(regExp(re), input, invert);
} }
//- Extract elements of StringList when regular expression matches //- Extract elements of StringList when regular expression matches
@ -205,11 +205,11 @@ namespace Foam
StringListType subsetStrings StringListType subsetStrings
( (
const wordRe& matcher, const wordRe& matcher,
const StringListType& lst, const StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
return subsetMatchingStrings(matcher, lst, invert); return subsetMatchingStrings(matcher, input, invert);
} }
//- Extract elements of StringList when regular expression matches //- Extract elements of StringList when regular expression matches
@ -218,11 +218,11 @@ namespace Foam
StringListType subsetStrings StringListType subsetStrings
( (
const wordRes& matcher, const wordRes& matcher,
const StringListType& lst, const StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
return subsetMatchingStrings(matcher, lst, invert); return subsetMatchingStrings(matcher, input, invert);
} }
@ -248,7 +248,7 @@ namespace Foam
void inplaceSubsetMatchingStrings void inplaceSubsetMatchingStrings
( (
const UnaryMatchPredicate& matcher, const UnaryMatchPredicate& matcher,
StringListType& lst, StringListType& input,
const bool invert=false const bool invert=false
); );
@ -258,11 +258,11 @@ namespace Foam
void inplaceSubsetStrings void inplaceSubsetStrings
( (
const regExp& matcher, const regExp& matcher,
StringListType& lst, StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
inplaceSubsetMatchingStrings(matcher, lst, invert); inplaceSubsetMatchingStrings(matcher, input, invert);
} }
//- Inplace extract elements of StringList when regular expression matches //- Inplace extract elements of StringList when regular expression matches
@ -271,11 +271,11 @@ namespace Foam
void inplaceSubsetStrings void inplaceSubsetStrings
( (
const char* re, const char* re,
StringListType& lst, StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
inplaceSubsetMatchingStrings(regExp(re), lst, invert); inplaceSubsetMatchingStrings(regExp(re), input, invert);
} }
//- Inplace extract elements of StringList when regular expression matches //- Inplace extract elements of StringList when regular expression matches
@ -284,11 +284,11 @@ namespace Foam
void inplaceSubsetStrings void inplaceSubsetStrings
( (
const std::string& re, const std::string& re,
StringListType& lst, StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
inplaceSubsetMatchingStrings(regExp(re), lst, invert); inplaceSubsetMatchingStrings(regExp(re), input, invert);
} }
//- Inplace extract elements of StringList when regular expression matches //- Inplace extract elements of StringList when regular expression matches
@ -297,11 +297,11 @@ namespace Foam
void inplaceSubsetStrings void inplaceSubsetStrings
( (
const wordRe& matcher, const wordRe& matcher,
StringListType& lst, StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
inplaceSubsetMatchingStrings(matcher, lst, invert); inplaceSubsetMatchingStrings(matcher, input, invert);
} }
//- Inplace extract elements of StringList when regular expression matches //- Inplace extract elements of StringList when regular expression matches
@ -310,11 +310,11 @@ namespace Foam
void inplaceSubsetStrings void inplaceSubsetStrings
( (
const wordRes& matcher, const wordRes& matcher,
StringListType& lst, StringListType& input,
const bool invert=false const bool invert=false
) )
{ {
inplaceSubsetMatchingStrings(matcher, lst, invert); inplaceSubsetMatchingStrings(matcher, input, invert);
} }
//- Inplace extract elements of StringList when regular expression matches //- Inplace extract elements of StringList when regular expression matches

View File

@ -29,21 +29,24 @@ template<class UnaryMatchPredicate, class StringType>
Foam::labelList Foam::findMatchingStrings Foam::labelList Foam::findMatchingStrings
( (
const UnaryMatchPredicate& matcher, const UnaryMatchPredicate& matcher,
const UList<StringType>& lst, const UList<StringType>& input,
const bool invert const bool invert
) )
{ {
labelList indices(lst.size()); const label len = input.size();
labelList indices(len);
label count = 0; label count = 0;
forAll(lst, elemi) for (label i=0; i < len; ++i)
{ {
if (matcher(lst[elemi]) ? !invert : invert) if (matcher(input[i]) ? !invert : invert)
{ {
indices[count++] = elemi; indices[count] = i;
++count;
} }
} }
indices.setSize(count); indices.resize(count);
return indices; return indices;
} }
@ -53,24 +56,27 @@ template<class UnaryMatchPredicate, class StringListType>
StringListType Foam::subsetMatchingStrings StringListType Foam::subsetMatchingStrings
( (
const UnaryMatchPredicate& matcher, const UnaryMatchPredicate& matcher,
const StringListType& lst, const StringListType& input,
const bool invert const bool invert
) )
{ {
StringListType newLst(lst.size()); const label len = input.size();
newLst.setSize(lst.size()); // Consistent sizing (eg, DynamicList)
StringListType output(len);
output.resize(len); // Consistent sizing (eg, DynamicList)
label count = 0; label count = 0;
forAll(lst, elemi) for (label i=0; i < len; ++i)
{ {
if (matcher(lst[elemi]) ? !invert : invert) if (matcher(input[i]) ? !invert : invert)
{ {
newLst[count++] = lst[elemi]; output[count] = input[i];
++count;
} }
} }
newLst.setSize(count); output.resize(count);
return newLst; return output;
} }
@ -78,23 +84,25 @@ template<class UnaryMatchPredicate, class StringListType>
void Foam::inplaceSubsetMatchingStrings void Foam::inplaceSubsetMatchingStrings
( (
const UnaryMatchPredicate& matcher, const UnaryMatchPredicate& matcher,
StringListType& lst, StringListType& input,
const bool invert const bool invert
) )
{ {
const label len = input.size();
label count = 0; label count = 0;
forAll(lst, elemi) for (label i=0; i < len; ++i)
{ {
if (matcher(lst[elemi]) ? !invert : invert) if (matcher(input[i]) ? !invert : invert)
{ {
if (count != elemi) if (count != i)
{ {
lst[count] = lst[elemi]; input[count] = std::move(input[i]);
} }
++count; ++count;
} }
} }
lst.setSize(count); input.resize(count);
} }

View File

@ -2120,7 +2120,7 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
// Initialize all addressing into current mesh // Initialize all addressing into current mesh
constructCellMap[Pstream::myProcNo()] = identity(mesh_.nCells()); constructCellMap[Pstream::myProcNo()] = identity(mesh_.nCells());
constructFaceMap[Pstream::myProcNo()] = identity(mesh_.nFaces()) + 1; constructFaceMap[Pstream::myProcNo()] = identity(mesh_.nFaces(), 1);
constructPointMap[Pstream::myProcNo()] = identity(mesh_.nPoints()); constructPointMap[Pstream::myProcNo()] = identity(mesh_.nPoints());
constructPatchMap[Pstream::myProcNo()] = identity(patches.size()); constructPatchMap[Pstream::myProcNo()] = identity(patches.size());
@ -2407,7 +2407,7 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
constructCellMap[sendProc] = identity(domainMesh.nCells()); constructCellMap[sendProc] = identity(domainMesh.nCells());
constructFaceMap[sendProc] = identity(domainMesh.nFaces()) + 1; constructFaceMap[sendProc] = identity(domainMesh.nFaces(), 1);
constructPointMap[sendProc] = identity(domainMesh.nPoints()); constructPointMap[sendProc] = identity(domainMesh.nPoints());
constructPatchMap[sendProc] = constructPatchMap[sendProc] =
identity(domainMesh.boundaryMesh().size()); identity(domainMesh.boundaryMesh().size());

View File

@ -455,14 +455,14 @@ void Foam::perfectInterface::setRefinement(polyTopoChange& ref) const
const polyPatch& patch1 = patches[slavePatchID_.index()]; const polyPatch& patch1 = patches[slavePatchID_.index()];
labelList pp0Labels(identity(patch0.size())+patch0.start()); labelList pp0Labels(identity(patch0.size(), patch0.start()));
indirectPrimitivePatch pp0 indirectPrimitivePatch pp0
( (
IndirectList<face>(mesh.faces(), pp0Labels), IndirectList<face>(mesh.faces(), pp0Labels),
mesh.points() mesh.points()
); );
labelList pp1Labels(identity(patch1.size())+patch1.start()); labelList pp1Labels(identity(patch1.size(), patch1.start()));
indirectPrimitivePatch pp1 indirectPrimitivePatch pp1
( (
IndirectList<face>(mesh.faces(), pp1Labels), IndirectList<face>(mesh.faces(), pp1Labels),

View File

@ -324,7 +324,10 @@ void Foam::InteractionLists<ParticleType>::buildInteractionLists()
if (isA<wallPolyPatch>(patch)) if (isA<wallPolyPatch>(patch))
{ {
localWallFaces.append(identity(patch.size()) + patch.start()); localWallFaces.append
(
identity(patch.size(), patch.start())
);
} }
} }

View File

@ -135,7 +135,7 @@ void Foam::ParticleCollector<CloudType>::initPolygons
forAll(faces_, facei) forAll(faces_, facei)
{ {
const Field<point>& polyPoints = polygons[facei]; const Field<point>& polyPoints = polygons[facei];
face f(identity(polyPoints.size()) + pointOffset); face f(identity(polyPoints.size(), pointOffset));
UIndirectList<point>(points_, f) = polyPoints; UIndirectList<point>(points_, f) = polyPoints;
area_[facei] = f.mag(points_); area_[facei] = f.mag(points_);

View File

@ -619,8 +619,11 @@ void Foam::meshRefinement::checkData()
localPointRegion::findDuplicateFaces localPointRegion::findDuplicateFaces
( (
mesh_, mesh_,
identity(mesh_.nFaces()-mesh_.nInternalFaces()) identity
+ mesh_.nInternalFaces() (
mesh_.nFaces() - mesh_.nInternalFaces(),
mesh_.nInternalFaces()
)
) )
); );

View File

@ -372,8 +372,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate
// Local constructMap is just identity // Local constructMap is just identity
{ {
tgtConstructMap[Pstream::myProcNo()] = tgtConstructMap[Pstream::myProcNo()] = identity(targetCoarseSize);
identity(targetCoarseSize);
} }
labelList tgtCompactMap(map.constructSize()); labelList tgtCompactMap(map.constructSize());
@ -1134,13 +1133,19 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::append
{ {
mapMap.append mapMap.append
( (
identity(srcConstructMap[proci].size()) identity
+ mapMap.size() + newMapMap.size() (
srcConstructMap[proci].size(),
(mapMap.size() + newMapMap.size())
)
); );
newMapMap.append newMapMap.append
( (
identity(newSrcConstructMap[proci].size()) identity
+ mapMap.size() + newMapMap.size() (
newSrcConstructMap[proci].size(),
(mapMap.size() + newMapMap.size())
)
); );
} }
@ -1188,13 +1193,19 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::append
{ {
mapMap.append mapMap.append
( (
identity(tgtConstructMap[proci].size()) identity
+ mapMap.size() + newMapMap.size() (
tgtConstructMap[proci].size(),
(mapMap.size() + newMapMap.size())
)
); );
newMapMap.append newMapMap.append
( (
identity(newTgtConstructMap[proci].size()) identity
+ mapMap.size() + newMapMap.size() (
newTgtConstructMap[proci].size(),
(mapMap.size() + newMapMap.size())
)
); );
} }

View File

@ -1034,20 +1034,20 @@ Foam::extendedEdgeMesh::edgeTreesByType() const
// External edges // External edges
sliceEdges[0] = sliceEdges[0] =
identity(internalStart_ - externalStart_) + externalStart_; identity((internalStart_ - externalStart_), externalStart_);
// Internal edges // Internal edges
sliceEdges[1] = identity(flatStart_ - internalStart_) + internalStart_; sliceEdges[1] = identity((flatStart_ - internalStart_), internalStart_);
// Flat edges // Flat edges
sliceEdges[2] = identity(openStart_ - flatStart_) + flatStart_; sliceEdges[2] = identity((openStart_ - flatStart_), flatStart_);
// Open edges // Open edges
sliceEdges[3] = identity(multipleStart_ - openStart_) + openStart_; sliceEdges[3] = identity((multipleStart_ - openStart_), openStart_);
// Multiple edges // Multiple edges
sliceEdges[4] = sliceEdges[4] =
identity(edges().size() - multipleStart_) + multipleStart_; identity((edges().size() - multipleStart_), multipleStart_);
forAll(edgeTreesByType_, i) forAll(edgeTreesByType_, i)
{ {

View File

@ -122,8 +122,7 @@ Foam::treeDataFace::treeDataFace
mesh_(patch.boundaryMesh().mesh()), mesh_(patch.boundaryMesh().mesh()),
faceLabels_ faceLabels_
( (
identity(patch.size()) identity(patch.size(), patch.start())
+ patch.start()
), ),
isTreeFace_(mesh_.nFaces(), 0), isTreeFace_(mesh_.nFaces(), 0),
cacheBb_(cacheBb) cacheBb_(cacheBb)

View File

@ -281,7 +281,7 @@ void Foam::mappedPatchBase::findSamples
else else
{ {
// patch faces // patch faces
const labelList patchFaces(identity(pp.size()) + pp.start()); const labelList patchFaces(identity(pp.size(), pp.start()));
treeBoundBox patchBb treeBoundBox patchBb
( (

View File

@ -626,8 +626,7 @@ Foam::List<Foam::labelPair> Foam::localPointRegion::findDuplicateFacePairs
// Faces to test: all boundary faces // Faces to test: all boundary faces
labelList testFaces labelList testFaces
( (
identity(mesh.nFaces()-mesh.nInternalFaces()) identity(mesh.nFaces()-mesh.nInternalFaces(), mesh.nInternalFaces())
+ mesh.nInternalFaces()
); );
// Find correspondencing baffle face (or -1) // Find correspondencing baffle face (or -1)

View File

@ -564,12 +564,7 @@ Foam::triSurfaceMesh::edgeTree() const
// Boundary edges // Boundary edges
labelList bEdges labelList bEdges
( (
identity identity(nEdges() - nInternalEdges(), nInternalEdges())
(
nEdges()
-nInternalEdges()
)
+ nInternalEdges()
); );
treeBoundBox bb(Zero, Zero); treeBoundBox bb(Zero, Zero);