From 15f7260884b708aa813c427f9fafa69c6f7866ad Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 1 Mar 2018 14:12:51 +0100 Subject: [PATCH] ENH: cleanup of ListOps, ListListOps. Adjustments to List, PackedList. - relocated ListAppendEqOp and ListUniqueEqOp to ListOps::appendEqOp and ListOps::UniqueEqOp, respectively for better code isolation and documentation of purpose. - relocated setValues to ListOps::setValue() with many more alternative selectors possible - relocated createWithValues to ListOps::createWithValue for better code isolation. The default initialization value is itself now a default parameter, which allow for less typing. Negative indices in the locations to set are now silently ignored, which makes it possible to use an oldToNew mapping that includes negative indices. - additional ListOps::createWithValue taking a single position to set, available both in copy assign and move assign versions. Since a negative index is ignored, it is possible to combine with the output of List::find() etc. STYLE: changes for PackedList - code simplication in the PackedList iterators, including dropping the unused operator() on iterators, which is not available in plain list versions either. - improved sizing for PackedBoolList creation from a labelUList. ENH: additional List constructors, for handling single element list. - can assist in reducing constructor ambiguity, but can also helps memory optimization when creating a single element list. For example, labelListList labels(one(), identity(mesh.nFaces())); --- applications/test/List/Test-List.C | 188 ++++++++- .../test/PackedList1/Test-PackedList1.C | 6 +- .../test/PackedList2/Test-PackedList2.C | 10 +- .../test/PackedList4/Test-PackedList4.C | 18 +- .../manipulation/checkMesh/checkGeometry.C | 4 +- .../moveDynamicMesh/moveDynamicMesh.C | 2 +- .../parLagrangianRedistributor.C | 8 +- ...agrangianRedistributorRedistributeFields.C | 2 +- .../redistributePar/redistributePar.C | 2 +- src/OpenFOAM/containers/Lists/List/List.C | 86 ++-- src/OpenFOAM/containers/Lists/List/List.H | 50 +-- src/OpenFOAM/containers/Lists/List/ListI.H | 2 +- .../Lists/ListListOps/ListListOps.C | 124 +++--- .../Lists/ListListOps/ListListOps.H | 43 +- .../containers/Lists/ListOps/ListOps.H | 310 ++++++++++++-- .../Lists/ListOps/ListOpsTemplates.C | 382 ++++++++++++++---- .../Lists/PackedList/PackedBoolListI.H | 4 +- .../containers/Lists/PackedList/PackedList.H | 35 +- .../containers/Lists/PackedList/PackedListI.H | 118 +++--- src/OpenFOAM/containers/Lists/UList/UList.H | 4 +- src/OpenFOAM/containers/Lists/UList/UListI.H | 4 +- src/OpenFOAM/meshes/meshShapes/edge/edge.H | 4 +- src/OpenFOAM/meshes/meshShapes/face/face.H | 7 +- .../meshShapes/labelledTri/labelledTri.H | 7 +- .../meshes/meshShapes/triFace/triFace.H | 13 +- .../mapDistribute/mapDistributePolyMesh.C | 32 +- .../snappyHexMeshDriver/snappyRefineDriver.C | 6 +- .../AMIInterpolation/AMIInterpolation.C | 6 +- .../distributedTriSurfaceMesh.C | 8 +- src/sampling/surface/isoSurface/isoSurface.C | 8 +- .../surface/isoSurface/isoSurfaceCell.C | 8 +- 31 files changed, 1017 insertions(+), 484 deletions(-) diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index 1628b6f9ed..9ed62a26f9 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -97,11 +97,14 @@ void printMyString(const UList& lst) int main(int argc, char *argv[]) { argList::noParallel(); + argList::noFunctionObjects(); + argList::addOption("reList", "reList"); argList::addOption("wordList", "wordList"); argList::addOption("stringList", "stringList"); argList::addOption("float", "xx"); - argList::addBoolOption("transform", "Test List::createList functionality"); + argList::addBoolOption("create", "Test ListOps::create functionality"); + argList::addBoolOption("ListList", "Test list of list functionality"); argList::addBoolOption("flag"); #include "setRootCase.H" @@ -332,11 +335,11 @@ int main(int argc, char *argv[]) List sident(range.begin(), range.end()); Info<<"range-list (scalar)=" << sident << nl; - // Sub-ranges also work - List sident2(range(3), range(10)); - Info<<"range-list (scalar)=" << sident2 << nl; +// // Sub-ranges also work +// List sident2(range.at(3), range.at(10)); +// Info<<"subrange-list (scalar)=" << sident2 << nl; - // VERY BAD IDEA: List sident3(range(10), range(3)); + // VERY BAD IDEA: List sident3(range.at(10), range.at(3)); // This doesn't work, and don't know what it should do anyhow // List vident(range.begin(), range.end()); @@ -362,15 +365,15 @@ int main(int argc, char *argv[]) Info<<"-flag:" << args["flag"] << endl; } - if (args.found("transform")) + if (args.found("create")) { - Info<< nl << "Test List::createList functionality" << nl; + Info<< nl << "Test ListOps::create functionality" << nl; const auto labels = identity(15); Info<< "labels: " << flatOutput(labels) << endl; { - auto scalars = List::createList + auto scalars = ListOps::create ( labels, [](const label& val){ return scalar(1.5*val); } @@ -379,7 +382,7 @@ int main(int argc, char *argv[]) } { - auto vectors = List::createList + auto vectors = ListOps::create ( labels, [](const label& val){ return vector(1.2*val, -1.2*val, 0); } @@ -388,7 +391,7 @@ int main(int argc, char *argv[]) } { - auto longs = List::createList + auto longs = ListOps::create ( labels, [](const label& val){ return val; } @@ -396,7 +399,7 @@ int main(int argc, char *argv[]) Info<< "longs: " << flatOutput(longs) << endl; } { - auto negs = List