https://mooseframework.inl.gov
Loading...
Searching...
No Matches
GeochemistrySortedIndices.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11
13{
14std::vector<unsigned>
15sortedIndices(const std::vector<Real> & to_sort, bool ascending)
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}
26} // namespace GeochemistrySortedIndices
Utility to produce sorted information.
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-...