Merge branch 'feature-indirect-lists' into 'develop'

Feature indirect lists

See merge request Development/OpenFOAM-plus!253
This commit is contained in:
Andrew Heather
2019-04-29 10:48:17 +01:00
committed by Andrew Heather
41 changed files with 1180 additions and 531 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011 OpenFOAM Foundation
@ -27,19 +27,21 @@ Description
\*---------------------------------------------------------------------------*/
#include "IndirectList.H"
#include "IOstreams.H"
#include "argList.H"
#include "Fstream.H"
#include "ListOps.H"
#include "IndirectList.H"
#include "labelIndList.H"
#include "argList.H"
#include "SortList.H"
#include "Random.H"
#include <functional>
using namespace Foam;
template<class ListType>
void printInfo(const ListType& lst)
{
Info<< "full: " << flatOutput(lst.completeList()) << nl
Info<< "full: " << flatOutput(lst.values()) << nl
<< "addr: " << flatOutput(lst.addressing()) << nl
<< "list: " << flatOutput(lst) << nl
<< endl;
@ -103,7 +105,7 @@ int main(int argc, char *argv[])
inplaceReverseList(addresses);
idl1.resetAddressing(std::move(addresses));
idl1.addressing() = std::move(addresses);
printInfo(idl1);
@ -114,10 +116,10 @@ int main(int argc, char *argv[])
printInfo(uidl1);
idl1.resetAddressing(List<label>());
// idl2.resetAddressing(List<label>());
idl1.addressing().clear();
// idl2.addressing().clear();
Info<<"after resetAddressing:" << nl << endl;
Info<<"after reset addressing:" << nl << endl;
printInfo(uidl1);
printInfo(idl1);
@ -140,7 +142,7 @@ int main(int argc, char *argv[])
{
if (Pstream::master())
{
Pout<< "full: " << flatOutput(idl3.completeList()) << nl
Pout<< "full: " << flatOutput(idl3.values()) << nl
<< "send: " << flatOutput(idl3) << endl;
for
@ -173,6 +175,61 @@ int main(int argc, char *argv[])
Pstream::scatter(barrier);
}
// SortList
{
List<scalar> list1(20);
Random rnd(1234);
for (scalar& val : list1)
{
val = 100 * rnd.sample01<scalar>();
}
// Pick out 1/2 the values and make the negative
for (label i=0; i < list1.size()/2; ++i)
{
label pos = rnd.position(0, list1.size()-1);
list1[pos] = -list1[pos];
}
Info<< nl << "Random list: " << flatOutput(list1) << nl;
SortList<scalar> sorter1(list1);
Info<< nl << "Sort indices: " << flatOutput(sorter1.indices()) << nl;
Info<< nl << "Reverse indices: " << flatOutput(sorter1.indices()) << nl;
sorter1.reverse();
Info<< nl << "Again indices: " << flatOutput(sorter1.indices()) << nl;
sorter1.reverseSort();
Info<< nl << "Reverse indices: " << flatOutput(sorter1.indices()) << nl;
Info<< nl << "Sorted : " << flatOutput(sorter1) << nl;
sorter1.sort(std::greater<scalar>());
SortList<scalar> sorter2(list1, std::greater<scalar>());
sorter2.reverse();
Info<< "sorted: ";
for (const auto& val : sorter2)
{
Info<< ' ' << val;
}
Info<< nl;
sorter2.sort([](scalar a, scalar b) { return mag(a) < mag(b); });
Info<< nl << "Mag sorted: " << flatOutput(sorter2) << nl;
}
Info<< "End\n" << endl;
return 0;

View File

@ -29,6 +29,9 @@ Description
#include "labelList.H"
#include "FixedList.H"
#include "sliceRange.H"
#include "SliceList.H"
#include "IndirectList.H"
#include "Random.H"
using namespace Foam;
@ -128,9 +131,60 @@ int main(int argc, char *argv[])
}
}
// Sliced lists
{
List<scalar> list1(100);
Random rnd(1234);
for (scalar& val : list1)
{
val = 100 * rnd.sample01<scalar>();
}
Info<< nl << "Random list: " << flatOutput(list1) << nl;
SliceList<scalar> slice1(list1, sliceRange(0, 15, 3));
Info<< nl << "slicing with: " << slice1.addressing() << nl;
Info<< nl << "Sliced list: " << flatOutput(slice1) << nl;
for (scalar& val : slice1)
{
val = -val;
}
// Changed list via slice:
Info<< nl << "Changed via slice: " << flatOutput(list1) << nl;
// Some indirect list
IndirectList<scalar> indlist
(
list1,
identity(slice1.size(), list1.size()-slice1.size())
);
Info<< nl << "Indirect slice: " << flatOutput(indlist) << nl;
indlist = 1000;
Info<< nl << "zeroed slice: " << flatOutput(indlist) << nl;
slice1 = indlist;
Info<< nl << "self-copy: " << flatOutput(list1) << nl;
slice1 = 100000;
Info<< nl << "set values: " << flatOutput(slice1) << nl
<< " = " << flatOutput(list1) << nl;
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011 OpenFOAM Foundation
@ -67,6 +67,10 @@ int main(int argc, char *argv[])
Info<< "reverse ..." << nl;
printInfo(list1r);
list1r.partialSort(list1r.size()/2);
Info<< "partial sorted ..." << nl;
printInfo(list1r);
SortableList<label> list2(orig);
Info<< "unsorted: " << orig << nl;
printInfo(list2);