COMP: add missing include for SortList
- extend test to include partition + sort
This commit is contained in:
parent
3524a6f4df
commit
a81d757721
3
applications/test/partition-sort/Make/files
Normal file
3
applications/test/partition-sort/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-partition-sort.cxx
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-partition-sort
|
2
applications/test/partition-sort/Make/options
Normal file
2
applications/test/partition-sort/Make/options
Normal file
@ -0,0 +1,2 @@
|
||||
/* EXE_INC = */
|
||||
/* EXE_LIBS = */
|
97
applications/test/partition-sort/Test-partition-sort.cxx
Normal file
97
applications/test/partition-sort/Test-partition-sort.cxx
Normal file
@ -0,0 +1,97 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-partition-sort
|
||||
|
||||
Description
|
||||
Test behaviour of std::partition, etc.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "IndirectList.H"
|
||||
#include "SortList.H"
|
||||
#include "Random.H"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
labelList input(40);
|
||||
labelList order(Foam::identity(input.size()));
|
||||
|
||||
UIndirectList<label> sorted(input, order);
|
||||
|
||||
std::generate_n
|
||||
(
|
||||
input.begin(),
|
||||
input.size(),
|
||||
Random::uniformGeneratorOp<label>(123456, -5, 15)
|
||||
);
|
||||
|
||||
Info<< "input: "; input.writeList(Info) << nl;
|
||||
//Info<< "input: "; sorted.writeList(Info) << nl;
|
||||
|
||||
// Partition with 0/+ve values first, -ve values second
|
||||
auto part2 =
|
||||
std::stable_partition
|
||||
(
|
||||
order.begin(),
|
||||
order.end(),
|
||||
[&](const label a) { return (input[a] >= 0); }
|
||||
);
|
||||
|
||||
Info<< "partitioned at: "
|
||||
<< label(std::distance(order.begin(), part2)) << nl;
|
||||
|
||||
|
||||
//Info<< "partitioned: "; input.writeList(Info) << nl;
|
||||
Info<< "partitioned: "; sorted.writeList(Info) << nl;
|
||||
|
||||
// Sort -ve values with increasing distance away from 0, so a reverse sort
|
||||
std::stable_sort
|
||||
(
|
||||
part2,
|
||||
order.end(),
|
||||
[&](const label a, const label b) { return (input[b] < input[a]); }
|
||||
);
|
||||
|
||||
//Info<< "sorted: "; input.writeList(Info) << nl;
|
||||
Info<< "sorted: "; sorted.writeList(Info) << nl;
|
||||
Info<< "order: "; order.writeList(Info) << nl;
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
@ -1,3 +1,3 @@
|
||||
Test-sortList.C
|
||||
Test-sortList.cxx
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-sortList
|
||||
|
@ -1,2 +1,2 @@
|
||||
/* EXE_INC = -I$(LIB_SRC)/finiteVolume/lnInclude */
|
||||
/* EXE_LIBS = -lfiniteVolume */
|
||||
/* EXE_INC = */
|
||||
/* EXE_LIBS = */
|
||||
|
@ -25,6 +25,7 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Tests for SortList and Sortable List
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
@ -25,6 +25,8 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ListOps.H" // For uniqueOrder()
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
|
Loading…
Reference in New Issue
Block a user