mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: added IndirectSubList
- provides an indirect access to a sub-section of a list that is
somewhat less efficient than a Foam::SubList, but supports the
following:
* adjustment of its addressing range after construction
* recovery of the original, underlying list at any time
This can be more convenient for some coding cases.
For example,
template<class Addr>
void renumberFaces(IndirectListBase<face, Addr>& faces, ...);
which can be called for
* Specific faces:
UIndirectList<face>(mesh.faces(), facesToChange)
* A sub-range of faces:
IndirectSubList<face>(mesh.faces(), pp.range())
* All faces:
IndirectSubList<face>(mesh.faces())
CONFIG: added IndirectListsFwd.H with some common forwarding
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -31,8 +31,9 @@ Description
|
||||
#include "labelList.H"
|
||||
#include "FixedList.H"
|
||||
#include "sliceRange.H"
|
||||
#include "SliceList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "IndirectSubList.H"
|
||||
#include "SliceList.H"
|
||||
#include "Random.H"
|
||||
|
||||
using namespace Foam;
|
||||
@ -146,6 +147,23 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< nl << "Random list: " << flatOutput(list1) << nl;
|
||||
|
||||
{
|
||||
IndirectSubList<scalar> sublist1(list1, labelRange(0, 10));
|
||||
|
||||
Info<< nl << "SubList: " << sublist1.addressing() << " = "
|
||||
<< flatOutput(sublist1) << nl;
|
||||
|
||||
// Adjust addressing
|
||||
sublist1.addressing().reset(5, 8);
|
||||
|
||||
// This should resolve as a no-op
|
||||
sublist1 = sublist1;
|
||||
|
||||
Info<< "SubList: " << sublist1.addressing() << " = "
|
||||
<< flatOutput(sublist1) << nl;
|
||||
}
|
||||
|
||||
|
||||
SliceList<scalar> slice1(list1, sliceRange(0, 15, 3));
|
||||
|
||||
Info<< nl << "slicing with: " << slice1.addressing() << nl;
|
||||
|
||||
@ -52,7 +52,7 @@ namespace Foam
|
||||
template<class T>
|
||||
class BiIndirectList
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
UList<T>& posList_;
|
||||
UList<T>& negList_;
|
||||
|
||||
@ -72,6 +72,9 @@ public:
|
||||
//- Copy construct addressing, shallow copy values list reference
|
||||
inline IndirectList(const IndirectList<T>& list);
|
||||
|
||||
//- Move construct addressing, shallow copy values list reference
|
||||
inline IndirectList(IndirectList<T>&& list);
|
||||
|
||||
//- Copy construct addressing, shallow copy values list reference
|
||||
inline explicit IndirectList(const UIndirectList<T>& list);
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -73,6 +73,19 @@ inline Foam::IndirectList<T>::IndirectList(const IndirectList<T>& list)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::IndirectList<T>::IndirectList(IndirectList<T>&& list)
|
||||
:
|
||||
// Move addressing
|
||||
IndirectListAddressing<labelList>(std::move(list.addressing())),
|
||||
UIndirectList<T>
|
||||
(
|
||||
list.values(),
|
||||
IndirectListAddressing<labelList>::addressing()
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::IndirectList<T>::IndirectList(const UIndirectList<T>& list)
|
||||
:
|
||||
|
||||
@ -5,8 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,12 +27,11 @@ Class
|
||||
Foam::IndirectListAddressing
|
||||
|
||||
Description
|
||||
A class for storing list addressing (labels, slices etc) which are
|
||||
normally to used by IndirectList. A private inheritance is often used
|
||||
by any inheriting classes.
|
||||
A class for storing list addressing (labels, slices etc), which are
|
||||
normally to used by IndirectList.
|
||||
Private inheritance is often used by any inheriting classes.
|
||||
|
||||
SourceFiles
|
||||
IndirectListAddressing.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -31,21 +31,23 @@ template<class T, class Addr>
|
||||
Foam::label Foam::IndirectListBase<T, Addr>::find
|
||||
(
|
||||
const T& val,
|
||||
const label start
|
||||
label pos
|
||||
) const
|
||||
{
|
||||
const label len = addr_.size();
|
||||
|
||||
if (start >= 0 && len)
|
||||
if (pos >= 0 && len)
|
||||
{
|
||||
List_CONST_ACCESS(T, values_, vals);
|
||||
|
||||
for (label i = start; i < len; ++i)
|
||||
while (pos < len)
|
||||
{
|
||||
if (vals[addr_[i]] == val)
|
||||
if (vals[addr_[pos]] == val)
|
||||
{
|
||||
return i;
|
||||
return pos;
|
||||
}
|
||||
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,20 +59,26 @@ template<class T, class Addr>
|
||||
Foam::label Foam::IndirectListBase<T, Addr>::rfind
|
||||
(
|
||||
const T& val,
|
||||
const label pos
|
||||
label pos
|
||||
) const
|
||||
{
|
||||
// pos == -1 has same meaning as std::string::npos - search from end
|
||||
|
||||
if (pos < 0 || pos >= addr_.size())
|
||||
{
|
||||
pos = addr_.size()-1;
|
||||
}
|
||||
|
||||
List_CONST_ACCESS(T, values_, vals);
|
||||
|
||||
const label len1 = (addr_.size()-1);
|
||||
|
||||
// pos == -1 has same meaning as std::string::npos - search from end
|
||||
for (label i = ((pos >= 0 && pos < len1) ? pos : len1); i >= 0; --i)
|
||||
while (pos >= 0)
|
||||
{
|
||||
if (vals[addr_[i]] == val)
|
||||
if (vals[addr_[pos]] == val)
|
||||
{
|
||||
return i;
|
||||
return pos;
|
||||
}
|
||||
|
||||
--pos;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -33,7 +33,6 @@ Description
|
||||
is held outside of the class.
|
||||
|
||||
SourceFiles
|
||||
IndirectListBase.H
|
||||
IndirectListBase.C
|
||||
IndirectListBaseI.H
|
||||
IndirectListBaseIO.C
|
||||
@ -70,7 +69,7 @@ protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Copy values The number of elements in the list
|
||||
//- Deep copy values from the list
|
||||
template<class ListType>
|
||||
inline void copyList(const ListType& rhs);
|
||||
|
||||
@ -112,7 +111,7 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- No null construct
|
||||
//- No default construct
|
||||
IndirectListBase() = delete;
|
||||
|
||||
//- Store references to the values list and the addressing array
|
||||
@ -184,19 +183,21 @@ public:
|
||||
// Search
|
||||
|
||||
//- Find index of the first occurrence of the value.
|
||||
// When start is specified, any occurences before start are ignored.
|
||||
// Any occurences before the start pos are ignored.
|
||||
// Linear search.
|
||||
// \return -1 if not found.
|
||||
label find(const T& val, const label start=0) const;
|
||||
label find(const T& val, label pos = 0) const;
|
||||
|
||||
//- Find index of the last occurrence of the value.
|
||||
// When pos is specified, any occurrences after pos are ignored.
|
||||
// Any occurrences after the end pos are ignored.
|
||||
// Linear search.
|
||||
// \return -1 if not found.
|
||||
label rfind(const T& val, const label pos=-1) const;
|
||||
label rfind(const T& val, label pos = -1) const;
|
||||
|
||||
//- True if the value if found in the list. Linear search.
|
||||
inline bool found(const T& val, const label start=0) const;
|
||||
//- True if the value if found in the list.
|
||||
// Any occurences before the start pos are ignored.
|
||||
// Linear search.
|
||||
inline bool found(const T& val, label pos=0) const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
@ -5,8 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,6 +31,15 @@ template<class T, class Addr>
|
||||
template<class ListType>
|
||||
inline void Foam::IndirectListBase<T, Addr>::copyList(const ListType& rhs)
|
||||
{
|
||||
if
|
||||
(
|
||||
this
|
||||
== reinterpret_cast<IndirectListBase<T,Addr>*>(const_cast<ListType*>(&rhs))
|
||||
)
|
||||
{
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
const label len = addr_.size();
|
||||
|
||||
if (len != rhs.size())
|
||||
@ -94,10 +102,10 @@ template<class T, class Addr>
|
||||
inline bool Foam::IndirectListBase<T, Addr>::found
|
||||
(
|
||||
const T& val,
|
||||
const label pos
|
||||
label pos
|
||||
) const
|
||||
{
|
||||
return this->find(val, pos) != -1;
|
||||
return (this->find(val, pos) >= 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
60
src/OpenFOAM/containers/IndirectLists/IndirectListsFwd.H
Normal file
60
src/OpenFOAM/containers/IndirectLists/IndirectListsFwd.H
Normal file
@ -0,0 +1,60 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 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/>.
|
||||
|
||||
InClass
|
||||
Foam
|
||||
|
||||
Description
|
||||
Forward declarations for common indirect list types.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef IndirectListsFwd_H
|
||||
#define IndirectListsFwd_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Addr> class IndirectListBase;
|
||||
template<class T> class UIndirectList;
|
||||
template<class T> class IndirectList;
|
||||
template<class T> class IndirectSubList;
|
||||
template<class T> class SliceList;
|
||||
|
||||
//Not common enough: template<class T> class SortList;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,119 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 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/>.
|
||||
|
||||
Class
|
||||
Foam::IndirectSubList
|
||||
|
||||
Description
|
||||
Indirect access to a sub-section of a list.
|
||||
|
||||
In many cases, using a Foam::SubList provides a simpler and more
|
||||
efficient means of accessing a sub-list.
|
||||
There are, however, some advantages of a IndirectSubList:
|
||||
- allows adjustment of its addressing range after construct
|
||||
- can recover the original, underlying list at any time
|
||||
|
||||
SeeAlso
|
||||
Foam::SubList
|
||||
|
||||
SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef IndirectSubList_H
|
||||
#define IndirectSubList_H
|
||||
|
||||
#include "IndirectListAddressing.H"
|
||||
#include "IndirectListBase.H"
|
||||
#include "labelRange.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class IndirectSubList Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class T>
|
||||
class IndirectSubList
|
||||
:
|
||||
private IndirectListAddressing<labelRange>,
|
||||
public IndirectListBase<T, labelRange>
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from UList, the entire size
|
||||
explicit IndirectSubList(const UList<T>& values)
|
||||
:
|
||||
IndirectListAddressing<labelRange>(labelRange(0, values.size())),
|
||||
IndirectListBase<T, labelRange>
|
||||
(
|
||||
values,
|
||||
IndirectListAddressing<labelRange>::addressing()
|
||||
)
|
||||
{}
|
||||
|
||||
//- Construct from values list and range
|
||||
IndirectSubList
|
||||
(
|
||||
const UList<T>& values,
|
||||
const labelRange& addr
|
||||
)
|
||||
:
|
||||
IndirectListAddressing<labelRange>(addr),
|
||||
IndirectListBase<T, labelRange>
|
||||
(
|
||||
values,
|
||||
IndirectListAddressing<labelRange>::addressing()
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- The list addressing
|
||||
using IndirectListAddressing::addressing;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Use standard assignment operations
|
||||
using IndirectListBase<T, labelRange>::operator=;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -30,7 +30,6 @@ Description
|
||||
A List with indirect slice addressing.
|
||||
|
||||
SourceFiles
|
||||
SliceList.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -82,7 +81,6 @@ public:
|
||||
|
||||
//- Use standard assignment operations
|
||||
using IndirectListBase<T, sliceRange>::operator=;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -37,7 +37,6 @@ Description
|
||||
variant etc.
|
||||
|
||||
SourceFiles
|
||||
UIndirectListI.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -52,7 +51,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
// Forward Declarations
|
||||
template<class T> class UIndirectList;
|
||||
|
||||
// Common list types
|
||||
@ -78,8 +77,7 @@ public:
|
||||
IndirectListBase<T, labelUList>(values, addr)
|
||||
{}
|
||||
|
||||
//- Copy construct from UIndirectList with
|
||||
//- shallow copy of values and addressing arrays
|
||||
//- Copy construct (shallow copy of values and addressing arrays)
|
||||
UIndirectList(const UIndirectList<T>& list)
|
||||
:
|
||||
UIndirectList<T>(list.values(), list.addressing())
|
||||
|
||||
Reference in New Issue
Block a user