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  greater
 A list compare binary predicate for reverse sort. More...
 
struct  less
 A list compare binary predicate for normal sort. More...
 
struct  uniqueEqOp
 List helper to append y unique elements onto the end of x. More...
 

Functions

void identity (labelUList &map, label start=0)
 Set identity map with (map[i] == i) More...
 
template<class ListType , class UnaryPredicate >
label find (const ListType &input, const UnaryPredicate &pred, const label start=0)
 Find index of the first occurrence that satisfies the predicate. More...
 
template<class ListType , class UnaryPredicate >
bool found (const ListType &input, const UnaryPredicate &pred, const label start=0)
 True if there is a value in the list that satisfies the predicate. More...
 
template<class T >
void setValue (UList< T > &list, const labelUList &locations, const T &val)
 Set various locations of the list with a specified value. More...
 
template<class T >
void setValue (UList< T > &list, const labelHashSet &locations, const T &val)
 Set various locations of the list with a specified value. More...
 
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. More...
 
template<class T >
void setValue (UList< T > &list, const bitSet &locations, const T &val)
 Set various locations of the list with a specified value. More...
 
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. More...
 
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. More...
 
template<class T >
List< TcreateWithValue (const label len, const labelUList &locations, const T &val, const T &deflt=T())
 
template<class T >
List< TcreateWithValue (const label len, const labelHashSet &locations, const T &val, const T &deflt=T())
 
template<class T >
List< TcreateWithValue (const label len, const UList< bool > &locations, const T &val, const T &deflt=T())
 
template<class T >
List< TcreateWithValue (const label len, const bitSet &locations, const T &val, const T &deflt=T())
 
template<class T >
List< TcreateWithValue (const label len, const label index, const T &val, const T &deflt=T())
 
template<class T >
List< TcreateWithValue (const label len, const label index, T &&val, const T &deflt=T())
 

Detailed Description

Various utility functions to work on Lists.

Source files

Function Documentation

◆ identity()

void identity ( labelUList map,
label  start = 0 
)

Set identity map with (map[i] == i)

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

Definition at line 202 of file ListOps.C.

References UList< T >::begin(), UList< T >::end(), and Foam::start.

Referenced by SortableList< T >::partialReverseSort(), SortableList< T >::partialSort(), SortList< T >::reset(), SortList< T >::reverseSort(), and SortList< T >::sort().

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

◆ find()

label Foam::ListOps::find ( const ListType &  input,
const UnaryPredicate &  pred,
const label  start = 0 
)

◆ found()

bool found ( 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 occurences before start are ignored. Linear search.

Returns
true if found.

Definition at line 1163 of file ListOpsTemplates.C.

References find(), and Foam::start.

Referenced by writeObjects::write().

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

◆ setValue() [1/4]

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 1175 of file ListOpsTemplates.C.

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

Here is the call graph for this function:

◆ setValue() [2/4]

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 1196 of file ListOpsTemplates.C.

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

Here is the call graph for this function:

◆ setValue() [3/4]

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 1217 of file ListOpsTemplates.C.

References Foam::BitOps::count(), stdFoam::end(), Foam::min(), UList< T >::size(), and Foam::val.

Here is the call graph for this function:

◆ setValue() [4/4]

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 1240 of file ListOpsTemplates.C.

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

Here is the call graph for this function:

◆ create() [1/2]

List<T> Foam::ListOps::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.
auto neg = ListOps::create<label>
(
ints,
std::negate<label>()
);
auto labels = ListOps::create<label>
(
ints,
labelOp<int>()
);
auto vectors = ListOps::create<vector>
(
ints,
[](const int& val){ return vector(1.5*val, 0, 0); }
);

◆ create() [2/2]

List<T> Foam::ListOps::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]

List<T> Foam::ListOps::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

◆ createWithValue() [2/6]

List<T> Foam::ListOps::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

◆ createWithValue() [3/6]

List<T> Foam::ListOps::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

◆ createWithValue() [4/6]

List<T> Foam::ListOps::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

◆ createWithValue() [5/6]

List<T> Foam::ListOps::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

◆ createWithValue() [6/6]

List<T> Foam::ListOps::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
List<pointField> gatheredPoints(Pstream::nProcs());
gatheredPoints[Pstream::myProcNo()] = pointField
(
mesh.points(),
uniqueMeshPoints
);
...
// Or else
auto gatheredPoints = ListOps::createWithValue<pointField>
(
pointField(mesh.points(), uniqueMeshPoints)
);
...
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:426
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:444
Foam::neg
dimensionedScalar neg(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:199