diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 4cf97031fb..6c0361c549 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -173,6 +173,13 @@ public: //- Construct from UList inline explicit FixedList(const UList& list); + //- Copy construct from a subset of the input + inline FixedList + ( + const UList& list, + const FixedList& indices + ); + //- Construct from SLList inline explicit FixedList(const SLList& list); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index f2ee9bfc4d..bb24c9a64e 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -136,6 +136,20 @@ inline Foam::FixedList::FixedList(const UList& list) } +template +inline Foam::FixedList::FixedList +( + const UList& list, + const FixedList& indices +) +{ + for (unsigned i=0; i inline Foam::FixedList::FixedList(const SLList& list) { diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 6692039ca0..7dbb9cc9b2 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -292,11 +292,11 @@ Foam::List::List(List& a, bool reuse) template -Foam::List::List(const UList& list, const labelUList& mapAddressing) +Foam::List::List(const UList& list, const labelUList& indices) : - UList(nullptr, mapAddressing.size()) + UList(nullptr, indices.size()) { - const label len = mapAddressing.size(); + const label len = indices.size(); if (len) { @@ -306,12 +306,35 @@ Foam::List::List(const UList& list, const labelUList& mapAddressing) for (label i=0; i < len; ++i) { - vp[i] = list[mapAddressing[i]]; + vp[i] = list[indices[i]]; } } } +template +template +Foam::List::List +( + const UList& list, + const FixedList& indices +) +: + UList(nullptr, label(N)) +{ + const label len = label(N); + + doAlloc(); + + List_ACCESS(T, (*this), vp); + + for (label i=0; i < len; ++i) + { + vp[i] = list[indices[i]]; + } +} + + template template Foam::List::List(InputIterator begIter, InputIterator endIter) diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 9b5d43a609..3f8b19d71e 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -153,8 +153,12 @@ public: //- Construct as copy or re-use as specified List(List& a, bool reuse); - //- Construct as subset - List(const UList& list, const labelUList& mapAddressing); + //- Copy construct subset of list + List(const UList& list, const labelUList& indices); + + //- Copy construct subset of list + template + List(const UList& list, const FixedList& indices); //- Construct given begin/end iterators. // Uses std::distance for the size. diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index fd82c580d9..4c824e771f 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -67,7 +67,7 @@ class edge { public: - // Static data members + // Static Data Members static const char* const typeName; @@ -92,6 +92,13 @@ public: //- Construct from list, sorted with first less-than second inline edge(const FixedList& list, const bool doSort); + //- Copy construct from a subset of the input + inline edge + ( + const UList