Loading...
Searching...
No Matches
Foam::ListOps Namespace Reference

Various utility functions to work on Lists. More...

Classes

struct  appendEqOp
 List helper to append y elements onto the end of x. More...
struct  uniqueEqOp
 List helper to append y unique elements onto the end of x. More...
struct  unionEqOp
 List helper to add y unique elements to x. More...
struct  less
 A list compare binary predicate for normal sort. More...
struct  greater
 A list compare binary predicate for reverse sort. More...

Functions

template<class Type1, class Type2>
bool equal (const UList< Type1 > &a, const UList< Type2 > &b)
 Test for list equality with different but compatible data types. Eg, int32 and int64.
template<class Type1, class Type2, class BinaryPredicate>
bool equal (const UList< Type1 > &a, const UList< Type2 > &b, BinaryPredicate pred)
 Test for list equality with different but compatible data types.
void identity (labelUList &map, label start=0)
 Fill an identity map with (map[i] == i).
template<class ListType>
label count (const ListType &input, typename ListType::const_reference val, const label start=0)
 Count the occurrences of the given element.
template<class ListType, class UnaryPredicate>
label count_if (const ListType &input, const UnaryPredicate &pred, const label start=0)
 Count the number of matching entries.
template<class ListType, class UnaryPredicate>
label find_if (const ListType &input, const UnaryPredicate &pred, const label start=0)
 Find index of the first occurrence that satisfies the predicate.
template<class ListType, class UnaryPredicate>
label find (const ListType &input, const UnaryPredicate &pred, const label start=0)
 Same as ListOps::find_if.
template<class ListType, class UnaryPredicate>
bool found_if (const ListType &input, const UnaryPredicate &pred, const label start=0)
 True if there is a value in the list that satisfies the predicate.
template<class ListType, class UnaryPredicate>
bool found (const ListType &input, const UnaryPredicate &pred, const label start=0)
 Same as found_if.
template<class ListType, class UnaryPredicate>
labelList findIndices (const ListType &input, const UnaryPredicate &pred, label start=0)
 Linear search to find all occurences of given element.
template<class T>
void setValue (UList< T > &list, const labelUList &locations, const T &val)
 Set various locations of the list with a specified value.
template<class T>
void setValue (UList< T > &list, const labelHashSet &locations, const T &val)
 Set various locations of the list with a specified value.
template<class T>
void setValue (UList< T > &list, const UList< bool > &locations, const T &val)
 Set various locations of the list with a specified value.
template<class T>
void setValue (UList< T > &list, const bitSet &locations, const T &val)
 Set various locations of the list with a specified value.
template<class T, class T2, class UnaryOperation>
List< Tcreate (const UList< T2 > &input, const UnaryOperation &op)
 Create a List from a List of a dissimilar type, using the entire list.
template<class T, class InputIterator, class UnaryOperation>
List< Tcreate (InputIterator first, InputIterator last, const UnaryOperation &op)
 Create a List from an iterator range [first,last) of a dissimilar type.
template<class T>
List< TcreateWithValue (const label len, const labelUList &locations, const T &val, const T &deflt=T())
 Create a List filled with default values and various locations with another specified value.
template<class T>
List< TcreateWithValue (const label len, const labelHashSet &locations, const T &val, const T &deflt=T())
 Create a List filled with default values and various locations with another specified value.
template<class T>
List< TcreateWithValue (const label len, const UList< bool > &locations, const T &val, const T &deflt=T())
 Create a List filled with default values and various locations with another specified value.
template<class T>
List< TcreateWithValue (const label len, const bitSet &locations, const T &val, const T &deflt=T())
 Create a List filled with default values and various locations with another specified value.
template<class T>
List< TcreateWithValue (const label len, const label index, const T &val, const T &deflt=T())
 Create a List filled with default values and one specified value, which is copy assigned at the specified index.
template<class T>
List< TcreateWithValue (const label len, const label index, T &&val, const T &deflt=T())
 Create a List filled with default values and one specified value, which is move assigned at the specified index.

Detailed Description

Various utility functions to work on Lists.

Source files

Function Documentation

◆ equal() [1/2]

template<class Type1, class Type2>
bool equal ( const UList< Type1 > & a,
const UList< Type2 > & b )

Test for list equality with different but compatible data types. Eg, int32 and int64.

Definition at line 1120 of file ListOpsTemplates.C.

References b, UList< T >::cbegin(), UList< T >::cend(), and UList< T >::size().

Here is the call graph for this function:

◆ equal() [2/2]

template<class Type1, class Type2, class BinaryPredicate>
bool equal ( const UList< Type1 > & a,
const UList< Type2 > & b,
BinaryPredicate pred )

Test for list equality with different but compatible data types.

Definition at line 1135 of file ListOpsTemplates.C.

References b, UList< T >::cbegin(), UList< T >::cend(), and UList< T >::size().

Here is the call graph for this function:

◆ identity()

void identity ( labelUList & map,
label start = 0 )
inline

Fill an identity map with (map[i] == i).

Optionally with an alternative start index, so that (map[i] == i+start)

Definition at line 796 of file ListOps.H.

References Foam::identity(), and identity().

Referenced by identity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ count()

template<class ListType>
label count ( const ListType & input,
typename ListType::const_reference val,
const label start = 0 )

Count the occurrences of the given element.

When start is specified, any occurrences before start are ignored. Like std::count but works with list indexing

◆ count_if()

template<class ListType, class UnaryPredicate>
label count_if ( const ListType & input,
const UnaryPredicate & pred,
const label start = 0 )

Count the number of matching entries.

When start is specified, any occurrences before start are ignored. Linear search. Like std::count_if but works with list indexing

◆ find_if()

template<class ListType, class UnaryPredicate>
label find_if ( const ListType & input,
const UnaryPredicate & pred,
const label start = 0 )

Find index of the first occurrence that satisfies the predicate.

When start is specified, any occurrences before start are ignored. Linear search. Like std::find_if but works with list indexing.

Returns
position in list or -1 if not found.

Referenced by find(), and found_if().

Here is the caller graph for this function:

◆ find()

template<class ListType, class UnaryPredicate>
label find ( const ListType & input,
const UnaryPredicate & pred,
const label start = 0 )

Same as ListOps::find_if.

Definition at line 854 of file ListOps.H.

References find_if().

Here is the call graph for this function:

◆ found_if()

template<class ListType, class UnaryPredicate>
bool found_if ( const ListType & input,
const UnaryPredicate & pred,
const label start = 0 )

True if there is a value in the list that satisfies the predicate.

When start is specified, any occurrences before start are ignored. Linear search.

Returns
true if found.

Definition at line 1230 of file ListOpsTemplates.C.

References find_if().

Referenced by found().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ found()

template<class ListType, class UnaryPredicate>
bool found ( const ListType & input,
const UnaryPredicate & pred,
const label start = 0 )

Same as found_if.

Definition at line 885 of file ListOps.H.

References found_if().

Referenced by ABAQUSsurfaceFormat< Face >::write(), NASsurfaceFormat< Face >::write(), STARCDsurfaceFormat< Face >::write(), writeObjects::write(), starcdWriter::write(), nastranWriter::writeTemplate(), and starcdWriter::writeTemplate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findIndices()

template<class ListType, class UnaryPredicate>
labelList findIndices ( const ListType & input,
const UnaryPredicate & pred,
label start = 0 )

Linear search to find all occurences of given element.

References Foam::T().

Here is the call graph for this function:

◆ setValue() [1/4]

template<class T>
void setValue ( UList< T > & list,
const labelUList & locations,
const T & val )

Set various locations of the list with a specified value.

Parameters
listthe list to modify
locationswhere to apply the specified value An out-of-range index is silently ignored.
valthe value to set at the specified locations

Definition at line 1291 of file ListOpsTemplates.C.

References UList< T >::size(), and Foam::T().

Here is the call graph for this function:

◆ setValue() [2/4]

template<class T>
void setValue ( UList< T > & list,
const labelHashSet & locations,
const T & val )

Set various locations of the list with a specified value.

Parameters
listthe list to modify
locationswhere to apply the specified value An out-of-range index is silently ignored.
valthe value to set at the specified locations

Definition at line 1312 of file ListOpsTemplates.C.

References UList< T >::size(), and Foam::T().

Here is the call graph for this function:

◆ setValue() [3/4]

template<class T>
void setValue ( UList< T > & list,
const UList< bool > & locations,
const T & val )

Set various locations of the list with a specified value.

Parameters
listthe list to modify
locationswhere to apply the specified value An out-of-range index is silently ignored.
valthe value to set at the specified locations

Definition at line 1333 of file ListOpsTemplates.C.

References Foam::min(), UList< T >::size(), and Foam::T().

Here is the call graph for this function:

◆ setValue() [4/4]

template<class T>
void setValue ( UList< T > & list,
const bitSet & locations,
const T & val )

Set various locations of the list with a specified value.

Parameters
listthe list to modify
locationswhere to apply the specified value An out-of-range index is silently ignored.
valthe value to set at the specified locations

Definition at line 1354 of file ListOpsTemplates.C.

References bitSet::find_first(), bitSet::find_next(), Foam::pos(), UList< T >::size(), and Foam::T().

Here is the call graph for this function:

◆ create() [1/2]

template<class T, class T2, class UnaryOperation>
List< T > create ( const UList< T2 > & input,
const UnaryOperation & op )

Create a List from a List of a dissimilar type, using the entire list.

For example, convert a list of ints to floats, vectors etc.

Parameters
inputthe list input values.
opthe unary conversion operator, which can be used to convert to other types.
(
ints,
std::negate<label>()
);
(
ints,
);
(
ints,
[](const int& val){ return vector(1.5*val, 0, 0); }
);
List< T > create(const UList< T2 > &input, const UnaryOperation &op)
Create a List from a List of a dissimilar type, using the entire list.
dimensionedScalar neg(const dimensionedScalar &ds)
Vector< scalar > vector
Definition vector.H:57
Conversion/extraction to label operation.
Definition label.H:207

Referenced by distanceSurface::filterRegionProximity(), and triSurface::transfer().

Here is the caller graph for this function:

◆ create() [2/2]

template<class T, class InputIterator, class UnaryOperation>
List< T > create ( InputIterator first,
InputIterator last,
const UnaryOperation & op )

Create a List from an iterator range [first,last) of a dissimilar type.

Uses std::distance for the size.

Parameters
firstthe begin of the iterator range
lastthe end of the iterator range
opthe unary conversion operator, which can be used to convert to other types.

◆ createWithValue() [1/6]

template<class T>
List< T > createWithValue ( const label len,
const labelUList & locations,
const T & val,
const T & deflt = T() )

Create a List filled with default values and various locations with another specified value.

Parameters
lenthe length of the list
locationswhere to apply the specified value An out-of-range index is silently ignored.
valthe value to set at the specified locations
defltthe initialization default value

References Foam::T().

Referenced by mapDistributePolyMesh::distributeCellIndices(), mapDistributePolyMesh::distributeFaceIndices(), mapDistributePolyMesh::distributePatchIndices(), mapDistributePolyMesh::distributePointIndices(), distanceSurface::filterFaceProximity(), and distanceSurface::filterRegionProximity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createWithValue() [2/6]

template<class T>
List< T > createWithValue ( const label len,
const labelHashSet & locations,
const T & val,
const T & deflt = T() )

Create a List filled with default values and various locations with another specified value.

Parameters
lenthe length of the list
locationswhere to apply the specified value An out-of-range index is silently ignored.
valthe value to set at the specified locations
defltthe initialization default value

References Foam::T().

Here is the call graph for this function:

◆ createWithValue() [3/6]

template<class T>
List< T > createWithValue ( const label len,
const UList< bool > & locations,
const T & val,
const T & deflt = T() )

Create a List filled with default values and various locations with another specified value.

Parameters
lenthe length of the list
locationswhere to apply the specified value An out-of-range index is silently ignored.
valthe value to set at the specified locations
defltthe initialization default value

References Foam::T().

Here is the call graph for this function:

◆ createWithValue() [4/6]

template<class T>
List< T > createWithValue ( const label len,
const bitSet & locations,
const T & val,
const T & deflt = T() )

Create a List filled with default values and various locations with another specified value.

Parameters
lenthe length of the list
locationswhere to apply the specified value An out-of-range index is silently ignored.
valthe value to set at the specified locations
defltthe initialization default value

References Foam::T().

Here is the call graph for this function:

◆ createWithValue() [5/6]

template<class T>
List< T > createWithValue ( const label len,
const label index,
const T & val,
const T & deflt = T() )

Create a List filled with default values and one specified value, which is copy assigned at the specified index.

Parameters
lenthe length of the list
indexwhere to apply the specified value. An out-of-range index is silently ignored.
valthe value to copy assign at the specified index
defltthe initialization default value

References Foam::T().

Here is the call graph for this function:

◆ createWithValue() [6/6]

template<class T>
List< T > createWithValue ( const label len,
const label index,
T && val,
const T & deflt = T() )

Create a List filled with default values and one specified value, which is move assigned at the specified index.

Parameters
lenthe length of the list
indexwhere to apply the specified value. An out-of-range index is silently ignored.
valthe value to move assign at the specified index
defltthe initialization default value

For example,

// Gather all unique points on master
gatheredPoints[Pstream::myProcNo()] = pointField
(
mesh.points(),
uniqueMeshPoints
);
...
// Or else
(
pointField(mesh.points(), uniqueMeshPoints)
);
...
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
Definition UPstream.H:1706
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
Definition UPstream.H:1697
dynamicFvMesh & mesh
List< T > createWithValue(const label len, const labelUList &locations, const T &val, const T &deflt=T())
Create a List filled with default values and various locations with another specified value.
vectorField pointField
pointField is a vectorField.

References Foam::T().

Here is the call graph for this function: