https://mooseframework.inl.gov
Functions
GeochemistrySortedIndices Namespace Reference

Utility to produce sorted information. More...

Functions

std::vector< unsigned > sortedIndices (const std::vector< Real > &to_sort, bool ascending)
 Produces a vector of indices corresponding to the smallest-to-biggest entries in to_sort (or biggest-to-smallest if ascending=false). More...
 

Detailed Description

Utility to produce sorted information.

Function Documentation

◆ sortedIndices()

std::vector< unsigned > GeochemistrySortedIndices::sortedIndices ( const std::vector< Real > &  to_sort,
bool  ascending 
)

Produces a vector of indices corresponding to the smallest-to-biggest entries in to_sort (or biggest-to-smallest if ascending=false).

Eg: to_sort = {1, 2, 5, 3, -2} then this will return {4, 0, 1, 3, 2} because to_sort[4]=-2 is the least entry, to_sort[0]=1 is the next biggest, etc, and to_sort[2]=5 is the greatest. Note that this doesn't actually sort the vector to_sort, but instead just produces the indices

Parameters
to_sortvector to consider
ascendingwhether to sort in ascending order
Returns
a vector of indices corresponding to the sorted version of to_sort

Definition at line 15 of file GeochemistrySortedIndices.C.

Referenced by GeochemistryConsoleOutput::output(), GeochemistryConsoleOutput::outputNernstInfo(), GeochemicalSolver::reduceInitialResidual(), GeochemicalSolver::swapNeeded(), and TEST().

16 {
17  std::vector<unsigned> order(to_sort.size());
18  unsigned ind = 0;
19  std::iota(order.begin(), order.end(), ind++);
20  if (ascending)
21  std::sort(order.begin(), order.end(), [&](int i, int j) { return to_sort[i] < to_sort[j]; });
22  else
23  std::sort(order.begin(), order.end(), [&](int i, int j) { return to_sort[i] > to_sort[j]; });
24  return order;
25 }
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")