Commit c1561256 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: construct fixed-length items as a fixed-length subset (#1708)

For example,

    const edge meshE(patch.meshPoints(), patch.edges()[edgei]);
parent 836dc16f
......@@ -173,6 +173,13 @@ public:
//- Construct from UList
inline explicit FixedList(const UList<T>& list);
//- Copy construct from a subset of the input
inline FixedList
(
const UList<T>& list,
const FixedList<label, N>& indices
);
//- Construct from SLList
inline explicit FixedList(const SLList<T>& list);
......
......@@ -136,6 +136,20 @@ inline Foam::FixedList<T, N>::FixedList(const UList<T>& list)
}
template<class T, unsigned N>
inline Foam::FixedList<T, N>::FixedList
(
const UList<T>& list,
const FixedList<label, N>& indices
)
{
for (unsigned i=0; i<N; ++i)
{
v_[i] = list[indices[i]];
}
}
template<class T, unsigned N>
inline Foam::FixedList<T, N>::FixedList(const SLList<T>& list)
{
......
......@@ -292,11 +292,11 @@ Foam::List<T>::List(List<T>& a, bool reuse)
template<class T>
Foam::List<T>::List(const UList<T>& list, const labelUList& mapAddressing)
Foam::List<T>::List(const UList<T>& list, const labelUList& indices)
:
UList<T>(nullptr, mapAddressing.size())
UList<T>(nullptr, indices.size())
{
const label len = mapAddressing.size();
const label len = indices.size();
if (len)
{
......@@ -306,12 +306,35 @@ Foam::List<T>::List(const UList<T>& list, const labelUList& mapAddressing)
for (label i=0; i < len; ++i)
{
vp[i] = list[mapAddressing[i]];
vp[i] = list[indices[i]];
}
}
}
template<class T>
template<unsigned N>
Foam::List<T>::List
(
const UList<T>& list,
const FixedList<label,N>& indices
)
:
UList<T>(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<class T>
template<class InputIterator>
Foam::List<T>::List(InputIterator begIter, InputIterator endIter)
......
......@@ -153,8 +153,12 @@ public:
//- Construct as copy or re-use as specified
List(List<T>& a, bool reuse);
//- Construct as subset
List(const UList<T>& list, const labelUList& mapAddressing);
//- Copy construct subset of list
List(const UList<T>& list, const labelUList& indices);
//- Copy construct subset of list
template<unsigned N>
List(const UList<T>& list, const FixedList<label, N>& indices);
//- Construct given begin/end iterators.
// Uses std::distance for the size.
......
......@@ -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<label, 2>& list, const bool doSort);
//- Copy construct from a subset of the input
inline edge
(
const UList<label>& list,
const FixedList<label, 2>& indices
);
//- Construct from Istream
inline edge(Istream& is);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -74,6 +74,16 @@ inline Foam::edge::edge(const FixedList<label, 2>& list, const bool doSort)
{}
inline Foam::edge::edge
(
const labelUList& list,
const FixedList<label, 2>& indices
)
:
labelPair(list[indices.first()], list[indices.last()])
{}
inline Foam::edge::edge(Istream& is)
:
labelPair(is)
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -69,7 +69,7 @@ public:
// Constructors
//- Construct null, with invalid point labels (-1)
//- Default construct, with invalid point labels (-1)
inline tetCell();
//- Construct from four point labels
......@@ -81,11 +81,18 @@ public:
const label d
);
//- Construct from an initializer list of four point labels
inline explicit tetCell(std::initializer_list<label> list);
//- Construct from FixedList of four point labels
inline tetCell(const FixedList<label, 4>& lst);
inline tetCell(const FixedList<label, 4>& list);
//- Construct from an initializer list of four point labels
inline explicit tetCell(std::initializer_list<label> lst);
//- Copy construct from a subset of the input list
inline tetCell
(
const labelUList& list,
const FixedList<label, 4>& indices
);
//- Construct from Istream
inline tetCell(Istream& is);
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -52,15 +53,25 @@ inline Foam::tetCell::tetCell
}
inline Foam::tetCell::tetCell(const FixedList<label, 4>& lst)
inline Foam::tetCell::tetCell(std::initializer_list<label> list)
:
FixedList<label, 4>(lst)
FixedList<label, 4>(list)
{}
inline Foam::tetCell::tetCell(std::initializer_list<label> lst)
inline Foam::tetCell::tetCell(const FixedList<label, 4>& list)
:
FixedList<label, 4>(lst)
FixedList<label, 4>(list)
{}
inline Foam::tetCell::tetCell
(
const labelUList& list,
const FixedList<label, 4>& indices
)
:
FixedList<label, 4>(list, indices)
{}
......
......@@ -56,7 +56,7 @@ SourceFiles
namespace Foam
{
// Forward declarations
// Forward Declarations
class face;
class triFace;
......@@ -72,7 +72,6 @@ class triFace
:
public FixedList<label, 3>
{
public:
// Constructors
......@@ -88,11 +87,18 @@ public:
const label c
);
//- Construct from an initializer list of three point labels
inline explicit triFace(std::initializer_list<label> list);
//- Copy construct from a list of three point labels.
inline explicit triFace(const labelUList& lst);
inline explicit triFace(const labelUList& list);
//- Construct from an initializer list of three point labels
inline explicit triFace(std::initializer_list<label> lst);
//- Copy construct from a subset of the input
inline triFace
(
const labelUList& list,
const FixedList<label, 3>& indices
);
//- Construct from Istream
inline triFace(Istream& is);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2017-2018 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -81,15 +81,25 @@ inline Foam::triFace::triFace
}
inline Foam::triFace::triFace(const labelUList& lst)
inline Foam::triFace::triFace(std::initializer_list<label> list)
:
FixedList<label, 3>(lst)
FixedList<label, 3>(list)
{}
inline Foam::triFace::triFace(std::initializer_list<label> lst)
inline Foam::triFace::triFace(const labelUList& list)
:
FixedList<label, 3>(lst)
FixedList<label, 3>(list)
{}
inline Foam::triFace::triFace
(
const labelUList& list,
const FixedList<label, 3>& indices
)
:
FixedList<label, 3>(list, indices)
{}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2012 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -59,7 +59,7 @@ public:
// Constructors
//- Construct null
//- Default construct
inline tetPoints()
{}
......@@ -78,6 +78,17 @@ public:
operator[](3) = d;
}
//- Copy construct from subset of points
inline tetPoints
(
const UList<point>& points,
const FixedList<label, 4>& indices
)
:
FixedList<point, 4>(points, indices)
{}
// Member Functions
//- Return the tetrahedron
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -58,7 +58,7 @@ public:
// Constructors
//- Construct null
//- Default construct
inline triPoints()
{}
......@@ -75,6 +75,16 @@ public:
operator[](2) = c;
}
//- Copy construct from subset of points
inline triPoints
(
const UList<point>& points,
const FixedList<label, 3>& indices
)
:
FixedList<point, 3>(points, indices)
{}
// Member Functions
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment