mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: update CompactListList code
- eliminate redundant size_ accounting - drop extra 'Container' template parameter and replace functionality with more flexible pack/unpack methods. There is also a pack() method that handles indirect lists of lists that can be used, for example, to pack a patch slice of faces. Drop the 'operator()' method in favour of unpack to expose and properly document the conversion. Should revisit the corresponding code in some places for optimization potential. - align some method names with globalIndex: totalSize(), maxSize() etc
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,7 +25,7 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
CompactListListTest
|
||||
Test-CompactListList
|
||||
|
||||
Description
|
||||
Simple demonstration and test application for the CompactListList class.
|
||||
@ -32,6 +33,7 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "CompactListList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "IOstreams.H"
|
||||
#include "StringStream.H"
|
||||
#include "faceList.H"
|
||||
@ -44,9 +46,9 @@ using namespace Foam;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
{
|
||||
// null construct
|
||||
// Default construct
|
||||
CompactListList<label> cll1;
|
||||
Info<< "cll1:" << cll1 << endl;
|
||||
Info<< "cll1:" << cll1 << nl;
|
||||
|
||||
// Resize and assign row by row
|
||||
labelList row0(2, Zero);
|
||||
@ -61,10 +63,12 @@ int main(int argc, char *argv[])
|
||||
cll1[1].deepCopy(row1);
|
||||
Info<< "cll1:" << cll1 << endl;
|
||||
|
||||
forAll(cll1.m(), i)
|
||||
forAll(cll1.values(), i)
|
||||
{
|
||||
Info<< "i:" << i << " whichRow:" << cll1.whichRow(i) << endl;
|
||||
}
|
||||
|
||||
Info<< "unpack:" << cll1.unpack<face>() << endl;
|
||||
}
|
||||
|
||||
List<List<label>> lll(5);
|
||||
@ -74,23 +78,23 @@ int main(int argc, char *argv[])
|
||||
lll[3].setSize(0, 3);
|
||||
lll[4].setSize(1, 4);
|
||||
|
||||
CompactListList<label> cll2(lll);
|
||||
Info<< "packed:" << CompactListList<label>::pack(lll) << endl;
|
||||
|
||||
auto cll2(CompactListList<label>::pack(lll));
|
||||
|
||||
Info<< "cll2 = " << cll2 << endl;
|
||||
|
||||
forAll(cll2, i)
|
||||
{
|
||||
Info<< cll2[i] << endl;
|
||||
Info<< cll2[i] << nl;
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
|
||||
Info<< "cll2(2, 3) = " << cll2(2, 3) << nl << endl;
|
||||
cll2(2, 3) = 999;
|
||||
Info<< "cll2(2, 3) = " << cll2(2, 3) << nl << endl;
|
||||
|
||||
Info<< "cll2 as List<List<label >> " << cll2()
|
||||
<< endl;
|
||||
Info<< "cll2 as List<List<label>> " << cll2.unpack() << endl;
|
||||
|
||||
cll2.setSize(3);
|
||||
|
||||
@ -140,16 +144,34 @@ int main(int argc, char *argv[])
|
||||
Info<< "cll5 = " << cll5 << endl;
|
||||
}
|
||||
|
||||
// Make some faces
|
||||
{
|
||||
faceList fcs(2);
|
||||
fcs[0] = face(labelList(1, label(111)));
|
||||
fcs[1] = face(labelList(2, label(222)));
|
||||
faceList fcs(5);
|
||||
forAll(fcs, facei)
|
||||
{
|
||||
fcs[facei] = face(identity(4, facei));
|
||||
}
|
||||
|
||||
CompactListList<label, face> compactFcs(fcs);
|
||||
Info<< "comactFcs:" << compactFcs << endl;
|
||||
Info<< "input faces: " << fcs << endl;
|
||||
|
||||
faceList fcs2 = compactFcs();
|
||||
Info<< "fcs2:" << fcs2 << endl;
|
||||
// From <face>
|
||||
auto compactFcs(CompactListList<label>::pack<face>(fcs));
|
||||
Info<< "compact faces:" << compactFcs << endl;
|
||||
|
||||
faceList fcs2 = compactFcs.unpack<face>();
|
||||
Info<< "deserialized:" << fcs2 << endl;
|
||||
|
||||
// From some faces
|
||||
IndirectList<face> subfaces(fcs, labelList({2, 4, 1}));
|
||||
|
||||
Info<< "sub faces: " << subfaces << endl;
|
||||
|
||||
auto subCompact
|
||||
(
|
||||
CompactListList<label>::pack(subfaces)
|
||||
);
|
||||
Info<< "compact faces:" << subCompact << endl;
|
||||
Info<< "deserialized:" << subCompact.unpack() << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,181 +27,332 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "CompactListList.H"
|
||||
#include "labelRange.H"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
void Foam::CompactListList<T>::reportOverflowAndExit
|
||||
(
|
||||
const label idx,
|
||||
const labelUList& localLens
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Overflow : sum of sizes exceeds labelMax ("
|
||||
<< labelMax << ") after index " << idx;
|
||||
|
||||
if (!localLens.empty())
|
||||
{
|
||||
FatalError << " of " << flatOutput(localLens);
|
||||
}
|
||||
|
||||
FatalError
|
||||
<< nl
|
||||
<< "Please recompile with larger datatype for label." << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
template<class ListListType>
|
||||
Foam::CompactListList<T> Foam::CompactListList<T>::packImpl
|
||||
(
|
||||
const ListListType& lists,
|
||||
const bool checkOverflow
|
||||
)
|
||||
{
|
||||
CompactListList<T> compact;
|
||||
|
||||
auto& newOffsets = compact.offsets_;
|
||||
auto& newValues = compact.values_;
|
||||
|
||||
label total = 0;
|
||||
const label len = lists.size();
|
||||
|
||||
if (len)
|
||||
{
|
||||
newOffsets.resize(len+1, Zero);
|
||||
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
newOffsets[i] = total;
|
||||
total += lists[i].size();
|
||||
|
||||
if (checkOverflow && total < newOffsets[i])
|
||||
{
|
||||
reportOverflowAndExit(i);
|
||||
}
|
||||
}
|
||||
newOffsets[len] = total;
|
||||
}
|
||||
|
||||
if (total)
|
||||
{
|
||||
// Copy in the data
|
||||
newValues.resize(total);
|
||||
|
||||
auto outIter = newValues.begin();
|
||||
|
||||
for (const auto& list : lists)
|
||||
{
|
||||
forAll(list, i)
|
||||
{
|
||||
*outIter = list[i];
|
||||
++outIter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return compact;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
template<class SubListType>
|
||||
Foam::CompactListList<T> Foam::CompactListList<T>::pack
|
||||
(
|
||||
const UList<SubListType>& lists,
|
||||
const bool checkOverflow
|
||||
)
|
||||
{
|
||||
return CompactListList<T>::packImpl<UList<SubListType>>
|
||||
(
|
||||
lists,
|
||||
checkOverflow
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
template<class SubListType, class Addr>
|
||||
Foam::CompactListList<T> Foam::CompactListList<T>::pack
|
||||
(
|
||||
const IndirectListBase<SubListType, Addr>& lists,
|
||||
const bool checkOverflow
|
||||
)
|
||||
{
|
||||
return CompactListList<T>::packImpl<IndirectListBase<SubListType, Addr>>
|
||||
(
|
||||
lists,
|
||||
checkOverflow
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Container>
|
||||
Foam::CompactListList<T, Container>::CompactListList(const List<Container>& ll)
|
||||
:
|
||||
size_(ll.size()),
|
||||
offsets_(ll.size()+1)
|
||||
template<class T>
|
||||
Foam::CompactListList<T>::CompactListList(const labelUList& listSizes)
|
||||
{
|
||||
label sumSize = 0;
|
||||
offsets_[0] = 0;
|
||||
forAll(ll, i)
|
||||
const label len = listSizes.size();
|
||||
|
||||
if (len)
|
||||
{
|
||||
sumSize += ll[i].size();
|
||||
offsets_[i+1] = sumSize;
|
||||
}
|
||||
offsets_.resize(len+1);
|
||||
|
||||
m_.setSize(sumSize);
|
||||
|
||||
label k = 0;
|
||||
forAll(ll, i)
|
||||
{
|
||||
const Container& lli = ll[i];
|
||||
|
||||
forAll(lli, j)
|
||||
label total = 0;
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
m_[k++] = lli[j];
|
||||
offsets_[i] = total;
|
||||
total += listSizes[i];
|
||||
|
||||
#ifdef FULLDEBUG
|
||||
if (total < offsets_[i])
|
||||
{
|
||||
reportOverflowAndExit(i, listSizes);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
offsets_[len] = total;
|
||||
values_.resize(total);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
Foam::CompactListList<T, Container>::CompactListList
|
||||
template<class T>
|
||||
Foam::CompactListList<T>::CompactListList
|
||||
(
|
||||
const labelUList& rowSizes
|
||||
)
|
||||
:
|
||||
size_(rowSizes.size()),
|
||||
offsets_(rowSizes.size()+1)
|
||||
{
|
||||
label sumSize = 0;
|
||||
offsets_[0] = 0;
|
||||
forAll(rowSizes, i)
|
||||
{
|
||||
sumSize += rowSizes[i];
|
||||
offsets_[i+1] = sumSize;
|
||||
}
|
||||
|
||||
m_.setSize(sumSize);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
const labelUList& rowSizes,
|
||||
const labelUList& listSizes,
|
||||
const T& val
|
||||
)
|
||||
:
|
||||
size_(rowSizes.size()),
|
||||
offsets_(rowSizes.size()+1)
|
||||
{
|
||||
label sumSize = 0;
|
||||
offsets_[0] = 0;
|
||||
forAll(rowSizes, i)
|
||||
{
|
||||
sumSize += rowSizes[i];
|
||||
offsets_[i+1] = sumSize;
|
||||
}
|
||||
const label len = listSizes.size();
|
||||
|
||||
m_.setSize(sumSize, val);
|
||||
if (len)
|
||||
{
|
||||
offsets_.resize(len+1);
|
||||
|
||||
label total = 0;
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
offsets_[i] = total;
|
||||
total += listSizes[i];
|
||||
|
||||
#ifdef FULLDEBUG
|
||||
if (total < offsets_[i])
|
||||
{
|
||||
reportOverflowAndExit(i, listSizes);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
offsets_[len] = total;
|
||||
values_.resize(total, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Container>
|
||||
void Foam::CompactListList<T, Container>::setSize(const label mRows)
|
||||
template<class T>
|
||||
Foam::label Foam::CompactListList<T>::maxNonLocalSize(const label rowi) const
|
||||
{
|
||||
if (mRows == 0)
|
||||
const label len = (offsets_.size() - 1);
|
||||
|
||||
if (len < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
label maxLen = 0;
|
||||
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
if (i != rowi)
|
||||
{
|
||||
const label localLen = (offsets_[i+1] - offsets_[i]);
|
||||
maxLen = max(maxLen, localLen);
|
||||
}
|
||||
}
|
||||
|
||||
return maxLen;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
std::streamsize Foam::CompactListList<T>::byteSize() const
|
||||
{
|
||||
if (!is_contiguous<T>::value)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Invalid for non-contiguous data types"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
return this->size_bytes();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::labelRange Foam::CompactListList<T>::range(const label i) const
|
||||
{
|
||||
return labelRange(offsets_[i], offsets_[i+1] - offsets_[i]);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::List<Foam::labelRange>
|
||||
Foam::CompactListList<T>::ranges() const
|
||||
{
|
||||
List<labelRange> values;
|
||||
|
||||
const label len = (offsets_.size() - 1);
|
||||
|
||||
if (len < 1)
|
||||
{
|
||||
return values;
|
||||
}
|
||||
|
||||
values.resize(len);
|
||||
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
values[i].reset(offsets_[i], (offsets_[i+1] - offsets_[i]));
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::CompactListList<T>::resize(const labelUList& listSizes)
|
||||
{
|
||||
const label len = listSizes.size();
|
||||
|
||||
if (len)
|
||||
{
|
||||
offsets_.resize(len+1);
|
||||
|
||||
label total = 0;
|
||||
for (label i = 0; i < len; ++i)
|
||||
{
|
||||
offsets_[i] = total;
|
||||
total += listSizes[i];
|
||||
#if 0
|
||||
if (checkOverflow && total < offsets_[i])
|
||||
{
|
||||
reportOverflowAndExit(i, listSizes);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
offsets_[len] = total;
|
||||
values_.resize(total);
|
||||
}
|
||||
else
|
||||
{
|
||||
clear();
|
||||
}
|
||||
if (mRows < size())
|
||||
{
|
||||
size_ = mRows;
|
||||
offsets_.setSize(mRows+1);
|
||||
m_.setSize(offsets_[mRows]);
|
||||
}
|
||||
else if (mRows > size())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot be used to extend the list from " << offsets_.size()
|
||||
<< " to " << mRows << nl
|
||||
<< " Please use one of the other setSize member functions"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
void Foam::CompactListList<T, Container>::setSize
|
||||
(
|
||||
const label mRows,
|
||||
const label nData
|
||||
)
|
||||
template<class T>
|
||||
void Foam::CompactListList<T>::setLocalSize(const label rowi, const label len)
|
||||
{
|
||||
size_ = mRows;
|
||||
offsets_.setSize(mRows+1);
|
||||
m_.setSize(nData);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
void Foam::CompactListList<T, Container>::setSize
|
||||
(
|
||||
const label mRows,
|
||||
const label nData,
|
||||
const T& t
|
||||
)
|
||||
{
|
||||
size_ = mRows;
|
||||
offsets_.setSize(mRows+1);
|
||||
m_.setSize(nData, t);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
void Foam::CompactListList<T, Container>::setSize(const labelUList& rowSizes)
|
||||
{
|
||||
size_ = rowSizes.size();
|
||||
offsets_.setSize(rowSizes.size()+1);
|
||||
|
||||
label sumSize = 0;
|
||||
offsets_[0] = 0;
|
||||
forAll(rowSizes, i)
|
||||
if (rowi >= 0 && rowi+1 < offsets_.size() && len >= 0)
|
||||
{
|
||||
sumSize += rowSizes[i];
|
||||
offsets_[i+1] = sumSize;
|
||||
}
|
||||
const label delta = (len - (offsets_[rowi+1] - offsets_[rowi]));
|
||||
|
||||
m_.setSize(sumSize);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
Foam::labelList Foam::CompactListList<T, Container>::sizes() const
|
||||
{
|
||||
labelList rowSizes(size());
|
||||
|
||||
if (rowSizes.size() > 0)
|
||||
{
|
||||
forAll(rowSizes, i)
|
||||
// TBD: additional overflow check
|
||||
if (delta)
|
||||
{
|
||||
rowSizes[i] = offsets_[i+1] - offsets_[i];
|
||||
for (label i = rowi+1; i < offsets_.size(); ++i)
|
||||
{
|
||||
offsets_[i] += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rowSizes;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
void Foam::CompactListList<T, Container>::clear()
|
||||
template<class T>
|
||||
Foam::labelList Foam::CompactListList<T>::localSizes() const
|
||||
{
|
||||
size_ = 0;
|
||||
offsets_.clear();
|
||||
m_.clear();
|
||||
labelList values;
|
||||
|
||||
const label len = (offsets_.size() - 1);
|
||||
|
||||
if (len < 1)
|
||||
{
|
||||
return values;
|
||||
}
|
||||
|
||||
values.resize(len);
|
||||
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
values[i] = offsets_[i+1] - offsets_[i];
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
void Foam::CompactListList<T, Container>::swap
|
||||
template<class T>
|
||||
void Foam::CompactListList<T>::swap
|
||||
(
|
||||
CompactListList<T, Container>& other
|
||||
CompactListList<T>& other
|
||||
)
|
||||
{
|
||||
if (this == &other)
|
||||
@ -209,16 +360,15 @@ void Foam::CompactListList<T, Container>::swap
|
||||
return; // Self-swap is a no-op
|
||||
}
|
||||
|
||||
std::swap(size_, other.size_);
|
||||
offsets_.swap(other.offsets_);
|
||||
m_.swap(other.m_);
|
||||
values_.swap(other.values_);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
void Foam::CompactListList<T, Container>::transfer
|
||||
template<class T>
|
||||
void Foam::CompactListList<T>::transfer
|
||||
(
|
||||
CompactListList<T, Container>& list
|
||||
CompactListList<T>& list
|
||||
)
|
||||
{
|
||||
if (this == &list)
|
||||
@ -226,25 +376,43 @@ void Foam::CompactListList<T, Container>::transfer
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
this->clear();
|
||||
this->swap(list);
|
||||
offsets_.transfer(list.offsets_);
|
||||
values_.transfer(list.values_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Container>
|
||||
Foam::List<Container> Foam::CompactListList<T, Container>::operator()()
|
||||
const
|
||||
template<class T>
|
||||
template<class SubListType>
|
||||
Foam::List<SubListType>
|
||||
Foam::CompactListList<T>::unpack() const
|
||||
{
|
||||
List<Container> ll(size());
|
||||
List<SubListType> lists(size());
|
||||
|
||||
forAll(ll, i)
|
||||
forAll(lists, i)
|
||||
{
|
||||
ll[i] = Container(operator[](i));
|
||||
lists[i] = SubListType(this->localList(i));
|
||||
}
|
||||
|
||||
return ll;
|
||||
return lists;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
template<class SubListType>
|
||||
Foam::List<SubListType>
|
||||
Foam::CompactListList<T>::unpack(const labelRange& range) const
|
||||
{
|
||||
List<SubListType> lists(range.size());
|
||||
|
||||
auto outIter = lists.begin();
|
||||
|
||||
for (const label i : range)
|
||||
{
|
||||
*outIter = SubListType(this->localList(i));
|
||||
++outIter;
|
||||
}
|
||||
|
||||
return lists;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -37,10 +37,8 @@ Description
|
||||
- offset[i] gives the index of first element of row i
|
||||
- offset[i+1] - offset[i] is the number of elements in row i
|
||||
|
||||
Storage is allocated on free-store during construction.
|
||||
|
||||
As a special case a null-constructed CompactListList has an empty
|
||||
offsets_ (instead of size 1).
|
||||
Note that an empty CompactListList should have empty offsets
|
||||
(not size 1).
|
||||
|
||||
SourceFiles
|
||||
CompactListList.C
|
||||
@ -49,10 +47,10 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef CompactListList_H
|
||||
#define CompactListList_H
|
||||
#ifndef Foam_CompactListList_H
|
||||
#define Foam_CompactListList_H
|
||||
|
||||
#include "labelList.H"
|
||||
#include "List.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -60,212 +58,399 @@ namespace Foam
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
template<class T> class CompactListList;
|
||||
|
||||
template<class T, class Container> class CompactListList;
|
||||
|
||||
template<class T, class Container> Istream& operator>>
|
||||
(
|
||||
Istream&,
|
||||
CompactListList<T, Container>&
|
||||
);
|
||||
template<class T, class Container> Ostream& operator<<
|
||||
(
|
||||
Ostream&,
|
||||
const CompactListList<T, Container>&
|
||||
);
|
||||
template<class T> Istream& operator>>(Istream&, CompactListList<T>&);
|
||||
template<class T> Ostream& operator<<(Ostream&, const CompactListList<T>&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class CompactListList Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class T, class Container = List<T>>
|
||||
template<class T>
|
||||
class CompactListList
|
||||
{
|
||||
// Private Data
|
||||
|
||||
label size_;
|
||||
//- Offset (addressing) table
|
||||
labelList offsets_;
|
||||
|
||||
//- Offset table
|
||||
List<label> offsets_;
|
||||
//- Packed (matrix) of values
|
||||
List<T> values_;
|
||||
|
||||
//- Packed matrix of data
|
||||
List<T> m_;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Report overflow at specified index
|
||||
static void reportOverflowAndExit
|
||||
(
|
||||
const label idx,
|
||||
const labelUList& listSizes = labelUList::null()
|
||||
);
|
||||
|
||||
//- Construct by packing together the list of lists
|
||||
template<class ListListType>
|
||||
static CompactListList<T> packImpl
|
||||
(
|
||||
const ListListType& lists,
|
||||
const bool checkOverflow = false
|
||||
);
|
||||
|
||||
//- Avoid poorly sized offsets/values
|
||||
void enforceSizeSanity();
|
||||
|
||||
//- The max of localSizes, excluding the specified row
|
||||
label maxNonLocalSize(const label rowi) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- The value type the list contains
|
||||
typedef T value_type;
|
||||
|
||||
//- The pointer type for non-const access to value_type items
|
||||
typedef T* pointer;
|
||||
|
||||
//- The pointer type for const access to value_type items
|
||||
typedef const T* const_pointer;
|
||||
|
||||
//- The type used for storing into value_type objects
|
||||
typedef T& reference;
|
||||
|
||||
//- The type used for reading from constant value_type objects.
|
||||
typedef const T& const_reference;
|
||||
|
||||
//- The type to represent the size of a CompactListList
|
||||
typedef label size_type;
|
||||
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Return a null CompactListList
|
||||
inline static const CompactListList<T, Container>& null();
|
||||
//- Return a CompactListList reference to a nullObject
|
||||
inline static const CompactListList<T>& null();
|
||||
|
||||
//- Construct by packing together the list of lists
|
||||
template<class SubListType = List<T>>
|
||||
static CompactListList<T> pack
|
||||
(
|
||||
const UList<SubListType>& lists,
|
||||
const bool checkOverflow = false
|
||||
);
|
||||
|
||||
//- Construct by packing together an indirect list of lists
|
||||
template<class SubListType, class Addr>
|
||||
static CompactListList<T> pack
|
||||
(
|
||||
const IndirectListBase<SubListType, Addr>& lists,
|
||||
const bool checkOverflow = false
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Default construct
|
||||
inline CompactListList();
|
||||
|
||||
//- Construct by converting given List<List<T>>
|
||||
explicit CompactListList(const List<Container>&);
|
||||
|
||||
//- Construct given size of offset table (number of rows)
|
||||
// and number of data.
|
||||
inline CompactListList(const label mRows, const label nData);
|
||||
|
||||
//- Construct given size of offset table (number of rows),
|
||||
// the number of data and a value for all elements.
|
||||
inline CompactListList(const label mRows, const label nData, const T&);
|
||||
|
||||
//- Construct given list of row-sizes.
|
||||
explicit CompactListList(const labelUList& rowSizes);
|
||||
|
||||
//- Construct given list of row-sizes
|
||||
CompactListList(const labelUList& rowSizes, const T&);
|
||||
CompactListList() noexcept = default;
|
||||
|
||||
//- Copy construct
|
||||
inline CompactListList(const CompactListList<T, Container>& lst);
|
||||
inline CompactListList(const CompactListList<T>& list);
|
||||
|
||||
//- Move construct
|
||||
inline CompactListList(CompactListList<T, Container>&& lst);
|
||||
inline CompactListList(CompactListList<T>&& list);
|
||||
|
||||
//- Construct as copy or re-use as specified.
|
||||
inline CompactListList(CompactListList<T, Container>& list, bool reuse);
|
||||
//- Copy/move construct as specified.
|
||||
inline CompactListList(CompactListList<T>& list, bool reuse);
|
||||
|
||||
//- Construct from number of rows and number of values.
|
||||
inline CompactListList(const label mRows, const label nVals);
|
||||
|
||||
//- Construct from number of rows, number of values
|
||||
//- initializing all elements to zero
|
||||
inline CompactListList
|
||||
(
|
||||
const label mRows, const label nVals, const Foam::zero
|
||||
);
|
||||
|
||||
//- Construct from number of rows, number of values
|
||||
//- and uniform value for all elements.
|
||||
inline CompactListList(const label mRows, const label nVals, const T&);
|
||||
|
||||
//- Construct given list of row-sizes.
|
||||
explicit CompactListList(const labelUList& listSizes);
|
||||
|
||||
//- Construct given list of row-sizes and a uniform value
|
||||
CompactListList(const labelUList& listSizes, const T& val);
|
||||
|
||||
//- Construct from Istream.
|
||||
CompactListList(Istream&);
|
||||
explicit CompactListList(Istream& is);
|
||||
|
||||
//- Clone
|
||||
inline autoPtr<CompactListList<T, Container>> clone() const;
|
||||
inline autoPtr<CompactListList<T>> clone() const;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
// Access
|
||||
|
||||
//- True if the number of rows is zero
|
||||
inline bool empty() const noexcept;
|
||||
//- True if the number of rows/sublists is zero
|
||||
inline bool empty() const noexcept;
|
||||
|
||||
//- The primary size (the number of rows)
|
||||
inline label size() const noexcept;
|
||||
//- The primary size (the number of rows/sublists)
|
||||
inline label size() const noexcept;
|
||||
|
||||
//- The total addressed size
|
||||
inline label totalSize() const;
|
||||
//- The total addressed size
|
||||
inline label totalSize() const;
|
||||
|
||||
//- Return the offset table (= size()+1)
|
||||
inline const List<label>& offsets() const;
|
||||
//- Return the offset table (= size()+1)
|
||||
inline const labelList& offsets() const noexcept;
|
||||
|
||||
//- Return non-const access to the offset table
|
||||
inline List<label>& offsets();
|
||||
//- Return non-const access to the offset table
|
||||
inline labelList& offsets() noexcept;
|
||||
|
||||
//- Return the packed matrix of data
|
||||
inline const List<T>& m() const;
|
||||
//- Return the packed matrix of values
|
||||
inline const List<T>& values() const noexcept;
|
||||
|
||||
//- Return non-const access to the packed matrix of data
|
||||
inline List<T>& m();
|
||||
//- Return non-const access to the packed matrix of values
|
||||
inline List<T>& values() noexcept;
|
||||
|
||||
|
||||
// Edit
|
||||
//- Return const pointer to the first data in values()
|
||||
inline const T* cdata() const noexcept;
|
||||
|
||||
//- Reset size of CompactListList.
|
||||
// This form only allows contraction of the CompactListList.
|
||||
void setSize(const label mRows);
|
||||
//- Return pointer to the first data in values()
|
||||
inline T* data() noexcept;
|
||||
|
||||
//- Reset size of CompactListList.
|
||||
void setSize(const label mRows, const label nData);
|
||||
//- Return const pointer to underlying values storage,
|
||||
//- reinterpreted as byte data.
|
||||
// \note Only meaningful for contiguous data
|
||||
inline const char* cdata_bytes() const noexcept;
|
||||
|
||||
//- Reset sizes of CompactListList and value for new elements.
|
||||
void setSize(const label mRows, const label nData, const T&);
|
||||
//- Return pointer to underlying values storage,
|
||||
//- reinterpreted as byte data.
|
||||
// \note Only meaningful for contiguous data
|
||||
inline char* data_bytes() noexcept;
|
||||
|
||||
//- Reset size of CompactListList.
|
||||
void setSize(const labelUList& rowSizes);
|
||||
//- Number of contiguous bytes for the values data,
|
||||
//- no runtime check that the type is actually contiguous
|
||||
// \note Only meaningful for contiguous data
|
||||
inline std::streamsize size_bytes() const noexcept;
|
||||
|
||||
//- Reset size of CompactListList.
|
||||
// This form only allows contraction of the CompactListList.
|
||||
inline void resize(const label mRows);
|
||||
|
||||
//- Reset size of CompactListList.
|
||||
inline void resize(const label mRows, const label nData);
|
||||
|
||||
//- Reset sizes of CompactListList and value for new elements.
|
||||
inline void resize(const label mRows, const label nData, const T&);
|
||||
|
||||
//- Reset size of CompactListList.
|
||||
inline void resize(const labelUList& rowSizes);
|
||||
|
||||
//- Clear the CompactListList, i.e. set sizes to zero.
|
||||
void clear();
|
||||
|
||||
//- Return sizes (to be used e.g. for construction)
|
||||
labelList sizes() const;
|
||||
|
||||
//- Swap contents
|
||||
void swap(CompactListList<T, Container>& other);
|
||||
|
||||
//- Transfer contents into this and annul the argument
|
||||
void transfer(CompactListList<T, Container>& list);
|
||||
//- Number of contiguous bytes for the values data,
|
||||
//- runtime FatalError if type is not contiguous
|
||||
std::streamsize byteSize() const;
|
||||
|
||||
|
||||
// Other
|
||||
// Queries
|
||||
|
||||
//- Return index into m
|
||||
inline label index(const label row, const label col) const;
|
||||
//- The local row sizes. Same as localSizes
|
||||
inline labelList sizes() const;
|
||||
|
||||
//- Get row for index into m.
|
||||
inline label whichRow(const label index) const;
|
||||
//- The local row starts
|
||||
inline const labelUList localStarts() const;
|
||||
|
||||
//- Get column index (j) given above row
|
||||
inline label whichColumn(const label row, const label index) const;
|
||||
//- The local row sizes
|
||||
labelList localSizes() const;
|
||||
|
||||
//- Starting offset for given row
|
||||
inline label localStart(const label i) const;
|
||||
|
||||
//- End offset (exclusive) for given row
|
||||
inline label localEnd(const label i) const;
|
||||
|
||||
//- Size of given row
|
||||
inline label localSize(const label i) const;
|
||||
|
||||
//- Return start/size ranges for all sub-lists
|
||||
List<labelRange> ranges() const;
|
||||
|
||||
//- Return start/size range for given sub-list
|
||||
labelRange range(const label i) const;
|
||||
|
||||
//- The max row length used
|
||||
inline label maxSize() const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
// Edit
|
||||
|
||||
//- Return subscript-checked row as UList.
|
||||
//- Clear addressing and contents
|
||||
inline void clear();
|
||||
|
||||
//- Reset size of CompactListList.
|
||||
// \note this form only allows truncation of the CompactListList.
|
||||
inline void resize(const label mRows);
|
||||
|
||||
//- Redimension CompactListList
|
||||
inline void resize(const label mRows, const label nVals);
|
||||
|
||||
//- Redimension \em without preserving existing content
|
||||
inline void resize_nocopy(const label mRows, const label nVals);
|
||||
|
||||
//- Redimension CompactListList and fill new elements with value.
|
||||
inline void resize(const label mRows, const label nVals, const T&);
|
||||
|
||||
//- Reset dimensions of CompactListList
|
||||
void resize(const labelUList& listSizes);
|
||||
|
||||
//- Alter local addressing size for given row, does not change content
|
||||
void setLocalSize(const label rowi, const label len);
|
||||
|
||||
|
||||
//- Redimension - same as resize()
|
||||
inline void setSize(const label mRows);
|
||||
|
||||
//- Redimension - same as resize()
|
||||
inline void setSize(const label mRows, const label nVals);
|
||||
|
||||
//- Redimension - same as resize()
|
||||
inline void setSize(const label mRows, const label nVals, const T&);
|
||||
|
||||
//- Reset sizes - same as resize()
|
||||
inline void setSize(const labelUList& listSizes);
|
||||
|
||||
//- Swap contents
|
||||
void swap(CompactListList<T>& other);
|
||||
|
||||
//- Transfer contents into this and annul the argument
|
||||
void transfer(CompactListList<T>& list);
|
||||
|
||||
|
||||
// Global addressing queries
|
||||
|
||||
//- From local index on rowi to global (flat) indexing
|
||||
//- into packed values
|
||||
inline label toGlobal(const label rowi, const label i) const;
|
||||
|
||||
//- From global to local index on rowi
|
||||
inline label toLocal(const label rowi, const label i) const;
|
||||
|
||||
//- Find row where global index comes from. Binary search.
|
||||
// \return -1 if out-of-bounds
|
||||
inline label findRow(const label i) const;
|
||||
|
||||
//- Which row does global index come from? Binary search.
|
||||
// FatalError if out-of-bounds
|
||||
inline label whichRow(const label i) const;
|
||||
|
||||
|
||||
// Pack / Unpack
|
||||
|
||||
//- Return non-compact list of lists
|
||||
template<class SubListType = List<T>>
|
||||
List<SubListType> unpack() const;
|
||||
|
||||
//- Return non-compact list of lists for the range of sub-lists
|
||||
template<class SubListType = List<T>>
|
||||
List<SubListType> unpack(const labelRange& range) const;
|
||||
|
||||
|
||||
// Assignment
|
||||
|
||||
//- Copy assignment
|
||||
inline void operator=(const CompactListList<T>& list);
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(CompactListList<T>&& list);
|
||||
|
||||
//- Assignment of all entries to the given value
|
||||
inline void operator=(const T& val);
|
||||
|
||||
//- Assignment of all entries to zero
|
||||
inline void operator=(const Foam::zero);
|
||||
|
||||
|
||||
// Row-based access
|
||||
|
||||
//- Return non-const access to sub-list (no subscript checking)
|
||||
inline UList<T> localList(const label i);
|
||||
|
||||
//- Return const access to sub-list (no subscript checking)
|
||||
inline const UList<T> localList(const label i) const;
|
||||
|
||||
//- Return row as UList - same as localList method
|
||||
inline UList<T> operator[](const label i);
|
||||
|
||||
//- Return const subscript-checked row as UList.
|
||||
//- Return row as const UList - same as localList method
|
||||
inline const UList<T> operator[](const label i) const;
|
||||
|
||||
|
||||
// Element access
|
||||
|
||||
//- Return subscript-checked element.
|
||||
inline T& operator()(const label i, const label j);
|
||||
|
||||
//- Return const subscript-checked element.
|
||||
inline const T& operator()(const label i, const label j) const;
|
||||
|
||||
//- Return as List<Container>
|
||||
List<Container> operator()() const;
|
||||
|
||||
//- Assignment of all entries to the given value
|
||||
inline void operator=(const T& val);
|
||||
// Reading/writing
|
||||
|
||||
//- Copy assignment
|
||||
inline void operator=(const CompactListList<T, Container>& lst);
|
||||
//- Read CompactListList as offsets/values pair from Istream,
|
||||
//- discards current list contents
|
||||
Istream& readList(Istream& is);
|
||||
|
||||
//- Move assignment
|
||||
inline void operator=(CompactListList<T, Container>&& lst);
|
||||
//- Write CompactListList as offsets/values pair
|
||||
Ostream& writeList(Ostream& os, const label shortLen=0) const;
|
||||
|
||||
|
||||
// IO Operators
|
||||
|
||||
//- Read CompactListList from Istream, discarding contents
|
||||
// of existing CompactListList.
|
||||
friend Istream& operator>> <T, Container>
|
||||
//- Read CompactListList offsets/values pair from Istream,
|
||||
//- discarding existing contents
|
||||
friend Istream& operator>> <T>
|
||||
(
|
||||
Istream&,
|
||||
CompactListList<T, Container>&
|
||||
CompactListList<T>&
|
||||
);
|
||||
|
||||
// Write CompactListList to Ostream.
|
||||
friend Ostream& operator<< <T, Container>
|
||||
//- Write CompactListList as offsets/values pair
|
||||
friend Ostream& operator<< <T>
|
||||
(
|
||||
Ostream&,
|
||||
const CompactListList<T, Container>&
|
||||
const CompactListList<T>&
|
||||
);
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- Const access to the packed matrix of values
|
||||
const List<T>& m() const noexcept { return values_; }
|
||||
|
||||
//- Non-const access to the packed matrix of values
|
||||
List<T>& m() noexcept { return values_; }
|
||||
|
||||
//- Return flat index into packed values
|
||||
label index(const label rowi, const label colj) const
|
||||
{
|
||||
return this->toGlobal(rowi, colj);
|
||||
}
|
||||
|
||||
//- Get column within specified row that corresponds to global index
|
||||
label whichColumn(const label rowi, const label i) const
|
||||
{
|
||||
return this->toLocal(rowi, i);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Note: uses default Foam::Swap (move construct/assignment)
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Istream& operator>>(Istream& is, CompactListList<T>& list)
|
||||
{
|
||||
return list.readList(is);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Ostream& operator<<(Ostream& os, const CompactListList<T>& list)
|
||||
{
|
||||
return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -29,316 +29,523 @@ License
|
||||
#include "ListOps.H"
|
||||
#include "SubList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::CompactListList<T, Container>::CompactListList()
|
||||
:
|
||||
size_(0)
|
||||
{}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
const label mRows,
|
||||
const label nData
|
||||
)
|
||||
:
|
||||
size_(mRows),
|
||||
offsets_(mRows+1, 0),
|
||||
m_(nData)
|
||||
{}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
const label mRows,
|
||||
const label nData,
|
||||
const T& val
|
||||
)
|
||||
:
|
||||
size_(mRows),
|
||||
offsets_(mRows+1, 0),
|
||||
m_(nData, val)
|
||||
{}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
const CompactListList<T, Container>& lst
|
||||
)
|
||||
:
|
||||
size_(lst.size()),
|
||||
offsets_(lst.offsets_),
|
||||
m_(lst.m_)
|
||||
{}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
CompactListList<T, Container>&& lst
|
||||
)
|
||||
template<class T>
|
||||
inline const Foam::CompactListList<T>& Foam::CompactListList<T>::null()
|
||||
{
|
||||
transfer(lst);
|
||||
return NullObjectRef<CompactListList<T>>();
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::CompactListList<T, Container>::CompactListList
|
||||
(
|
||||
CompactListList<T, Container>& list,
|
||||
bool reuse
|
||||
)
|
||||
:
|
||||
size_(list.size()),
|
||||
offsets_(list.offsets_, reuse),
|
||||
m_(list.m_, reuse)
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::enforceSizeSanity()
|
||||
{
|
||||
if (reuse)
|
||||
if (offsets_.size() == 1)
|
||||
{
|
||||
list.size_ = 0;
|
||||
offsets_.clear();
|
||||
}
|
||||
if (offsets_.empty())
|
||||
{
|
||||
values_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::autoPtr<Foam::CompactListList<T, Container>>
|
||||
Foam::CompactListList<T, Container>::clone() const
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
inline Foam::CompactListList<T>::CompactListList
|
||||
(
|
||||
const CompactListList<T>& list
|
||||
)
|
||||
:
|
||||
offsets_(list.offsets_),
|
||||
values_(list.values_)
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::CompactListList<T>::CompactListList
|
||||
(
|
||||
CompactListList<T>&& list
|
||||
)
|
||||
:
|
||||
offsets_(std::move(list.offsets_)),
|
||||
values_(std::move(list.values_))
|
||||
{}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::CompactListList<T>::CompactListList
|
||||
(
|
||||
CompactListList<T>& list,
|
||||
bool reuse
|
||||
)
|
||||
:
|
||||
offsets_(list.offsets_, reuse),
|
||||
values_(list.values_, reuse)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::CompactListList<T>::CompactListList
|
||||
(
|
||||
const label mRows,
|
||||
const label nVals
|
||||
)
|
||||
:
|
||||
offsets_(mRows+1, Zero),
|
||||
values_(nVals)
|
||||
{
|
||||
return autoPtr<CompactListList<T, Container>>::New(*this);
|
||||
// Optionally: enforceSizeSanity();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::CompactListList<T>::CompactListList
|
||||
(
|
||||
const label mRows,
|
||||
const label nVals,
|
||||
const Foam::zero
|
||||
)
|
||||
:
|
||||
offsets_(mRows+1, Zero),
|
||||
values_(nVals, Zero)
|
||||
{
|
||||
// Optionally: enforceSizeSanity();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::CompactListList<T>::CompactListList
|
||||
(
|
||||
const label mRows,
|
||||
const label nVals,
|
||||
const T& val
|
||||
)
|
||||
:
|
||||
offsets_(mRows+1, Zero),
|
||||
values_(nVals, val)
|
||||
{
|
||||
// Optionally: enforceSizeSanity();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::autoPtr<Foam::CompactListList<T>>
|
||||
Foam::CompactListList<T>::clone() const
|
||||
{
|
||||
return autoPtr<CompactListList<T>>::New(*this);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Container>
|
||||
inline const Foam::CompactListList<T, Container>&
|
||||
Foam::CompactListList<T, Container>::null()
|
||||
template<class T>
|
||||
inline const Foam::labelList& Foam::CompactListList<T>::offsets() const noexcept
|
||||
{
|
||||
return NullObjectRef<CompactListList<T, Container>>();
|
||||
return offsets_;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline bool Foam::CompactListList<T, Container>::empty() const noexcept
|
||||
template<class T>
|
||||
inline Foam::labelList& Foam::CompactListList<T>::offsets() noexcept
|
||||
{
|
||||
return !size_;
|
||||
return offsets_;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::label Foam::CompactListList<T, Container>::size() const noexcept
|
||||
template<class T>
|
||||
inline const Foam::List<T>& Foam::CompactListList<T>::values() const noexcept
|
||||
{
|
||||
return size_;
|
||||
return values_;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::label Foam::CompactListList<T, Container>::totalSize() const
|
||||
template<class T>
|
||||
inline Foam::List<T>& Foam::CompactListList<T>::values() noexcept
|
||||
{
|
||||
return values_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T* Foam::CompactListList<T>::cdata() const noexcept
|
||||
{
|
||||
return values_.cdata();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline T* Foam::CompactListList<T>::data() noexcept
|
||||
{
|
||||
return values_.data();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const char* Foam::CompactListList<T>::cdata_bytes() const noexcept
|
||||
{
|
||||
return values_.cdata_bytes();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline char* Foam::CompactListList<T>::data_bytes() noexcept
|
||||
{
|
||||
return values_.data_bytes();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline std::streamsize Foam::CompactListList<T>::size_bytes() const noexcept
|
||||
{
|
||||
return values_.size_bytes();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline bool Foam::CompactListList<T>::empty() const noexcept
|
||||
{
|
||||
return (offsets_.size() <= 1);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::size() const noexcept
|
||||
{
|
||||
const label len = (offsets_.size() - 1);
|
||||
return (len < 1) ? static_cast<label>(0) : len;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::labelList Foam::CompactListList<T>::sizes() const
|
||||
{
|
||||
return localSizes();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::totalSize() const
|
||||
{
|
||||
const label len = (offsets_.size() - 1);
|
||||
return (len < 1) ? static_cast<label>(0) : offsets_[len];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline const Foam::List<Foam::label>&
|
||||
Foam::CompactListList<T, Container>::offsets() const
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::maxSize() const
|
||||
{
|
||||
return offsets_;
|
||||
return this->maxNonLocalSize(-1);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::List<Foam::label>& Foam::CompactListList<T, Container>::offsets()
|
||||
template<class T>
|
||||
inline const Foam::labelUList
|
||||
Foam::CompactListList<T>::localStarts() const
|
||||
{
|
||||
return offsets_;
|
||||
const label len = (offsets_.size() - 1);
|
||||
|
||||
if (len < 1) return labelUList::null();
|
||||
|
||||
return labelList::subList(offsets_, len);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline const Foam::List<T>& Foam::CompactListList<T, Container>::m()
|
||||
const
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::localStart(const label i) const
|
||||
{
|
||||
return m_;
|
||||
return offsets_[i];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::List<T>& Foam::CompactListList<T, Container>::m()
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::localEnd(const label i) const
|
||||
{
|
||||
return m_;
|
||||
return offsets_[i+1];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::label Foam::CompactListList<T, Container>::index
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::localSize(const label i) const
|
||||
{
|
||||
return offsets_[i+1] - offsets_[i];
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::UList<T>
|
||||
Foam::CompactListList<T>::localList(const label i)
|
||||
{
|
||||
return SubList<T>(values_, (offsets_[i+1] - offsets_[i]), offsets_[i]);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const Foam::UList<T>
|
||||
Foam::CompactListList<T>::localList(const label i) const
|
||||
{
|
||||
return SubList<T>(values_, (offsets_[i+1] - offsets_[i]), offsets_[i]);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::toGlobal
|
||||
(
|
||||
const label i,
|
||||
const label j
|
||||
) const
|
||||
{
|
||||
return offsets_[i] + j;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::label Foam::CompactListList<T, Container>::whichRow(const label i)
|
||||
const
|
||||
{
|
||||
if (i < 0 || i >= m_.size())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Index " << i << " outside 0.." << m_.size()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
return findLower(offsets_, i+1);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::label Foam::CompactListList<T, Container>::whichColumn
|
||||
(
|
||||
const label row,
|
||||
const label rowi,
|
||||
const label i
|
||||
) const
|
||||
{
|
||||
return i - index(row, 0);
|
||||
return i + offsets_[rowi];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::resize(const label mRows)
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::toLocal
|
||||
(
|
||||
const label rowi,
|
||||
const label i
|
||||
) const
|
||||
{
|
||||
this->setSize(mRows);
|
||||
const label locali = i - offsets_[rowi];
|
||||
|
||||
if (locali < 0 || i >= offsets_[rowi+1])
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Index " << i << " does not belong on row "
|
||||
<< rowi << nl << "Offsets:" << offsets_
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
return locali;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::resize
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::findRow(const label i) const
|
||||
{
|
||||
return (i < 0 || i >= totalSize()) ? -1 : findLower(offsets_, i+1);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const
|
||||
{
|
||||
const label rowi = findRow(i);
|
||||
|
||||
if (rowi < 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Index " << i << " outside of range" << nl
|
||||
<< "Offsets:" << offsets_
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
return rowi;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::clear()
|
||||
{
|
||||
offsets_.clear();
|
||||
values_.clear();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::resize(const label mRows)
|
||||
{
|
||||
if (mRows == 0)
|
||||
{
|
||||
// Clear
|
||||
offsets_.clear();
|
||||
values_.clear();
|
||||
}
|
||||
else if (mRows < size())
|
||||
{
|
||||
// Shrink
|
||||
offsets_.resize(mRows+1);
|
||||
values_.resize(offsets_[mRows]);
|
||||
}
|
||||
else if (mRows > size())
|
||||
{
|
||||
// Grow
|
||||
FatalErrorInFunction
|
||||
<< "Cannot be used to extend the list from " << size()
|
||||
<< " to " << mRows << nl
|
||||
<< " Please use a different resize() function"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::resize
|
||||
(
|
||||
const label mRows,
|
||||
const label nData
|
||||
const label nVals
|
||||
)
|
||||
{
|
||||
this->setSize(mRows, nData);
|
||||
offsets_.resize(mRows+1, Zero);
|
||||
values_.resize(nVals);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::resize
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::resize_nocopy
|
||||
(
|
||||
const label mRows,
|
||||
const label nData,
|
||||
const T& t
|
||||
const label nVals
|
||||
)
|
||||
{
|
||||
this->setSize(mRows, nData, t);
|
||||
offsets_.resize(mRows+1, Zero);
|
||||
values_.resize_nocopy(nVals);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::resize
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::resize
|
||||
(
|
||||
const labelUList& rowSizes
|
||||
const label mRows,
|
||||
const label nVals,
|
||||
const T& val
|
||||
)
|
||||
{
|
||||
this->setSize(rowSizes);
|
||||
offsets_.resize(mRows+1, Zero);
|
||||
values_.resize(nVals, val);
|
||||
// Optionally: enforceSizeSanity();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::setSize(const label mRows)
|
||||
{
|
||||
this->resize(mRows);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::setSize
|
||||
(
|
||||
const label mRows,
|
||||
const label nVals
|
||||
)
|
||||
{
|
||||
this->resize(mRows+1, nVals);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::setSize
|
||||
(
|
||||
const label mRows,
|
||||
const label nVals,
|
||||
const T& val
|
||||
)
|
||||
{
|
||||
this->resize(mRows+1, nVals, val);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::setSize
|
||||
(
|
||||
const labelUList& listSizes
|
||||
)
|
||||
{
|
||||
this->resize(listSizes);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Container>
|
||||
inline Foam::UList<T> Foam::CompactListList<T, Container>::operator[]
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::operator=
|
||||
(
|
||||
const label i
|
||||
const CompactListList<T>& list
|
||||
)
|
||||
{
|
||||
const label start = offsets_[i];
|
||||
return UList<T>(m_.begin() + start, offsets_[i+1] - start);
|
||||
if (this == &list)
|
||||
{
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
offsets_ = list.offsets_,
|
||||
values_ = list.values_;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::operator=
|
||||
(
|
||||
CompactListList<T>&& list
|
||||
)
|
||||
{
|
||||
if (this == &list)
|
||||
{
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
offsets_.transfer(list.offsets_);
|
||||
values_.transfer(list.values_);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::operator=(const T& val)
|
||||
{
|
||||
values_ = val;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::CompactListList<T>::operator=(const Foam::zero)
|
||||
{
|
||||
values_ = Zero;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline Foam::UList<T>
|
||||
Foam::CompactListList<T>::operator[](const label i)
|
||||
{
|
||||
return this->localList(i);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const Foam::UList<T>
|
||||
Foam::CompactListList<T, Container>::operator[]
|
||||
(
|
||||
const label i
|
||||
) const
|
||||
Foam::CompactListList<T>::operator[](const label i) const
|
||||
{
|
||||
const label start = offsets_[i];
|
||||
return UList<T>
|
||||
(
|
||||
const_cast<T*>(m_.begin() + start),
|
||||
offsets_[i+1] - start
|
||||
);
|
||||
return this->localList(i);
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline T& Foam::CompactListList<T, Container>::operator()
|
||||
template<class T>
|
||||
inline T& Foam::CompactListList<T>::operator()
|
||||
(
|
||||
const label i,
|
||||
const label j
|
||||
)
|
||||
{
|
||||
return m_[index(i, j)];
|
||||
return values_[toGlobal(i, j)];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline const T& Foam::CompactListList<T, Container>::operator()
|
||||
template<class T>
|
||||
inline const T& Foam::CompactListList<T>::operator()
|
||||
(
|
||||
const label i,
|
||||
const label j
|
||||
) const
|
||||
{
|
||||
return m_[index(i, j)];
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::operator=(const T& val)
|
||||
{
|
||||
m_ = val;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::operator=
|
||||
(
|
||||
const CompactListList<T, Container>& lst
|
||||
)
|
||||
{
|
||||
if (this == &lst)
|
||||
{
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
size_ = lst.size_;
|
||||
offsets_ = lst.offsets_,
|
||||
m_ = lst.m_;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
inline void Foam::CompactListList<T, Container>::operator=
|
||||
(
|
||||
CompactListList<T, Container>&& lst
|
||||
)
|
||||
{
|
||||
if (this == &lst)
|
||||
{
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
transfer(lst);
|
||||
return values_[toGlobal(i, j)];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -30,40 +30,37 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Container>
|
||||
Foam::CompactListList<T, Container>::CompactListList(Istream& is)
|
||||
template<class T>
|
||||
Foam::CompactListList<T>::CompactListList(Istream& is)
|
||||
:
|
||||
offsets_(is),
|
||||
values_(is)
|
||||
{
|
||||
operator>>(is, *this);
|
||||
// Optionally: enforceSizeSanity();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Container>
|
||||
Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T, Container>& lst)
|
||||
template<class T>
|
||||
Foam::Istream& Foam::CompactListList<T>::readList(Istream& is)
|
||||
{
|
||||
is >> lst.offsets_ >> lst.m_;
|
||||
// Note: empty list gets output as two empty lists
|
||||
if (lst.offsets_.size())
|
||||
{
|
||||
lst.size_ = lst.offsets_.size()-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
lst.size_ = 0;
|
||||
}
|
||||
offsets_.readList(is);
|
||||
values_.readList(is);
|
||||
// Optionally: enforceSizeSanity();
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Container>
|
||||
Foam::Ostream& Foam::operator<<
|
||||
template<class T>
|
||||
Foam::Ostream& Foam::CompactListList<T>::writeList
|
||||
(
|
||||
Ostream& os,
|
||||
const CompactListList<T, Container>& lst
|
||||
)
|
||||
const label shortLen
|
||||
) const
|
||||
{
|
||||
os << lst.offsets_ << lst.m_;
|
||||
offsets_.writeList(os, shortLen);
|
||||
values_.writeList(os, shortLen);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
@ -128,28 +128,29 @@ Foam::globalIndex::globalIndex(Istream& is)
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::globalIndex::bin
|
||||
Foam::CompactListList<Foam::label>
|
||||
Foam::globalIndex::bin
|
||||
(
|
||||
const labelUList& offsets,
|
||||
const labelUList& globalIds,
|
||||
labelList& order,
|
||||
CompactListList<label>& bins,
|
||||
DynamicList<label>& validBins
|
||||
)
|
||||
{
|
||||
sortedOrder(globalIds, order);
|
||||
|
||||
bins.m() = UIndirectList<label>(globalIds, order);
|
||||
|
||||
labelList& binOffsets = bins.offsets();
|
||||
binOffsets.resize_nocopy(offsets.size());
|
||||
binOffsets = Zero;
|
||||
|
||||
validBins.clear();
|
||||
|
||||
CompactListList<label> bins;
|
||||
|
||||
if (globalIds.size())
|
||||
{
|
||||
const label id = bins.m()[0];
|
||||
labelList& binOffsets = bins.offsets();
|
||||
binOffsets.resize(offsets.size(), Zero);
|
||||
|
||||
labelList& binValues = bins.values();
|
||||
binValues = UIndirectList<label>(globalIds, order);
|
||||
|
||||
const label id = binValues[0];
|
||||
label proci = findLower(offsets, id+1);
|
||||
|
||||
validBins.append(proci);
|
||||
@ -157,7 +158,7 @@ void Foam::globalIndex::bin
|
||||
|
||||
for (label i = 1; i < order.size(); i++)
|
||||
{
|
||||
const label id = bins.m()[i];
|
||||
const label id = binValues[i];
|
||||
|
||||
if (id < offsets[proci+1])
|
||||
{
|
||||
@ -185,6 +186,8 @@ void Foam::globalIndex::bin
|
||||
binOffsets[j] = binOffsets[proci]+binSize;
|
||||
}
|
||||
}
|
||||
|
||||
return bins;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -76,12 +76,12 @@ class globalIndex
|
||||
// Private Member Functions
|
||||
|
||||
//- Sort and bin. validBins contains bins with non-zero size.
|
||||
static void bin
|
||||
static CompactListList<label>
|
||||
bin
|
||||
(
|
||||
const labelUList& offsets,
|
||||
const labelUList& globalIds,
|
||||
labelList& order,
|
||||
CompactListList<label>& sortedElems,
|
||||
DynamicList<label>& validBins
|
||||
);
|
||||
|
||||
|
||||
@ -840,19 +840,16 @@ void Foam::globalIndex::get
|
||||
) const
|
||||
{
|
||||
allFld.resize_nocopy(globalIds.size());
|
||||
|
||||
if (globalIds.size())
|
||||
{
|
||||
// Sort according to processor
|
||||
labelList order;
|
||||
CompactListList<label> bins;
|
||||
DynamicList<label> validBins(Pstream::nProcs());
|
||||
bin
|
||||
|
||||
CompactListList<label> bins
|
||||
(
|
||||
offsets(),
|
||||
globalIds,
|
||||
order,
|
||||
bins,
|
||||
validBins
|
||||
bin(offsets(), globalIds, order, validBins)
|
||||
);
|
||||
|
||||
// Send local indices to individual processors as local index
|
||||
@ -860,12 +857,11 @@ void Foam::globalIndex::get
|
||||
|
||||
for (const auto proci : validBins)
|
||||
{
|
||||
const labelUList& es = bins[proci];
|
||||
labelList localIDs(bins[proci]);
|
||||
|
||||
labelList localIDs(es.size());
|
||||
forAll(es, i)
|
||||
for (label& val : localIDs)
|
||||
{
|
||||
localIDs[i] = toLocal(proci, es[i]);
|
||||
val = toLocal(proci, val);
|
||||
}
|
||||
|
||||
UOPstream os(proci, sendBufs);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2018 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -1702,7 +1702,8 @@ void Foam::fvMeshDistribute::sendMesh
|
||||
// Send
|
||||
toDomain
|
||||
<< mesh.points()
|
||||
<< CompactListList<label, face>(mesh.faces())
|
||||
// Send as (offsets/values)
|
||||
<< CompactListList<label>::pack<face>(mesh.faces())
|
||||
<< mesh.faceOwner()
|
||||
<< mesh.faceNeighbour()
|
||||
<< mesh.boundaryMesh()
|
||||
@ -1744,7 +1745,8 @@ Foam::autoPtr<Foam::fvMesh> Foam::fvMeshDistribute::receiveMesh
|
||||
)
|
||||
{
|
||||
pointField domainPoints(fromNbr);
|
||||
faceList domainFaces = CompactListList<label, face>(fromNbr)();
|
||||
// Receive as (offsets/values), unpack to faceList
|
||||
faceList domainFaces = CompactListList<label>(fromNbr).unpack<face>();
|
||||
labelList domainAllOwner(fromNbr);
|
||||
labelList domainAllNeighbour(fromNbr);
|
||||
PtrList<entry> patchEntries(fromNbr);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -37,6 +37,7 @@ License
|
||||
#include "polyAddCell.H"
|
||||
#include "polyModifyCell.H"
|
||||
#include "polyRemoveCell.H"
|
||||
#include "CompactListList.H"
|
||||
#include "objectMap.H"
|
||||
#include "processorPolyPatch.H"
|
||||
#include "ListOps.H"
|
||||
@ -572,8 +573,8 @@ void Foam::polyTopoChange::makeCellCells
|
||||
if (nei >= 0)
|
||||
{
|
||||
label own = faceOwner_[facei];
|
||||
cellCells.m()[cellCells.index(own, nNbrs[own]++)] = nei;
|
||||
cellCells.m()[cellCells.index(nei, nNbrs[nei]++)] = own;
|
||||
cellCells(own, nNbrs[own]++) = nei;
|
||||
cellCells(nei, nNbrs[nei]++) = own;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -68,7 +68,6 @@ SourceFiles
|
||||
|
||||
#include "DynamicList.H"
|
||||
#include "labelList.H"
|
||||
#include "CompactListList.H"
|
||||
#include "pointField.H"
|
||||
#include "Map.H"
|
||||
#include "HashSet.H"
|
||||
@ -92,6 +91,7 @@ class topoAction;
|
||||
class objectMap;
|
||||
class IOobject;
|
||||
class mapPolyMesh;
|
||||
template<class T> class CompactListList;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class polyTopoChange Declaration
|
||||
|
||||
@ -143,7 +143,7 @@ Foam::decompositionInformation::decompositionInformation
|
||||
distrib_(),
|
||||
nDomains_(0)
|
||||
{
|
||||
populate(cellCells.m(), cellCells.offsets(), decomp, nDomains);
|
||||
populate(cellCells.values(), cellCells.offsets(), decomp, nDomains);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -120,20 +120,18 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
~decompositionInformation()
|
||||
{}
|
||||
~decompositionInformation() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
void clear();
|
||||
|
||||
label nDomains() const
|
||||
label nDomains() const noexcept
|
||||
{
|
||||
return nDomains_;
|
||||
}
|
||||
|
||||
|
||||
void printSummary(Ostream& os) const;
|
||||
|
||||
void printDetails(Ostream& os) const;
|
||||
|
||||
@ -414,7 +414,7 @@ Foam::labelList Foam::decompositionMethod::decompose
|
||||
(
|
||||
decompose
|
||||
(
|
||||
coarseCellCells(),
|
||||
coarseCellCells.unpack(),
|
||||
coarsePoints,
|
||||
coarseWeights
|
||||
)
|
||||
|
||||
@ -233,7 +233,13 @@ Foam::labelList Foam::metisLikeDecomp::decompose
|
||||
|
||||
// Decompose using default weights
|
||||
labelList decomp;
|
||||
decomposeGeneral(cellCells.m(), cellCells.offsets(), pointWeights, decomp);
|
||||
decomposeGeneral
|
||||
(
|
||||
cellCells.values(),
|
||||
cellCells.offsets(),
|
||||
pointWeights,
|
||||
decomp
|
||||
);
|
||||
|
||||
return decomp;
|
||||
}
|
||||
@ -271,7 +277,13 @@ Foam::labelList Foam::metisLikeDecomp::decompose
|
||||
|
||||
// Decompose using default weights
|
||||
labelList decomp;
|
||||
decomposeGeneral(cellCells.m(), cellCells.offsets(), agglomWeights, decomp);
|
||||
decomposeGeneral
|
||||
(
|
||||
cellCells.values(),
|
||||
cellCells.offsets(),
|
||||
agglomWeights,
|
||||
decomp
|
||||
);
|
||||
|
||||
|
||||
// Rework back into decomposition for original mesh
|
||||
@ -305,11 +317,18 @@ Foam::labelList Foam::metisLikeDecomp::decompose
|
||||
// adjncy : contains neighbours (= edges in graph)
|
||||
// xadj(celli) : start of information in adjncy for celli
|
||||
|
||||
CompactListList<label> cellCells(globalCellCells);
|
||||
|
||||
auto cellCells(CompactListList<label>::pack(globalCellCells));
|
||||
|
||||
// Decompose using default weights
|
||||
labelList decomp;
|
||||
decomposeGeneral(cellCells.m(), cellCells.offsets(), cellWeights, decomp);
|
||||
decomposeGeneral
|
||||
(
|
||||
cellCells.values(),
|
||||
cellCells.offsets(),
|
||||
cellWeights,
|
||||
decomp
|
||||
);
|
||||
|
||||
return decomp;
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -614,7 +614,7 @@ Foam::labelList Foam::multiLevelDecomp::decompose
|
||||
|
||||
decompose
|
||||
(
|
||||
cellCells(),
|
||||
cellCells.unpack(),
|
||||
cc,
|
||||
cWeights,
|
||||
cellMap, // map back to original cells
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -516,7 +516,7 @@ Foam::labelList Foam::ptscotchDecomp::decompose
|
||||
labelList decomp;
|
||||
decompose
|
||||
(
|
||||
cellCells.m(),
|
||||
cellCells.values(),
|
||||
cellCells.offsets(),
|
||||
pointWeights,
|
||||
decomp
|
||||
@ -563,7 +563,7 @@ Foam::labelList Foam::ptscotchDecomp::decompose
|
||||
labelList decomp;
|
||||
decompose
|
||||
(
|
||||
cellCells.m(),
|
||||
cellCells.values(),
|
||||
cellCells.offsets(),
|
||||
pointWeights,
|
||||
decomp
|
||||
@ -604,13 +604,13 @@ Foam::labelList Foam::ptscotchDecomp::decompose
|
||||
// adjncy : contains neighbours (= edges in graph)
|
||||
// xadj(celli) : start of information in adjncy for celli
|
||||
|
||||
CompactListList<label> cellCells(globalCellCells);
|
||||
auto cellCells(CompactListList<label>::pack(globalCellCells));
|
||||
|
||||
// Decompose using weights
|
||||
labelList decomp;
|
||||
decompose
|
||||
(
|
||||
cellCells.m(),
|
||||
cellCells.values(),
|
||||
cellCells.offsets(),
|
||||
cWeights,
|
||||
decomp
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -79,7 +79,7 @@ Foam::labelList Foam::CuthillMcKeeRenumber::renumber
|
||||
cellCells
|
||||
);
|
||||
|
||||
labelList orderedToOld = bandCompression(cellCells());
|
||||
labelList orderedToOld = bandCompression(cellCells.unpack());
|
||||
|
||||
if (reverse_)
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -85,7 +85,7 @@ Foam::labelList Foam::renumberMethod::renumber
|
||||
);
|
||||
|
||||
// Renumber based on agglomerated points
|
||||
return renumber(cellCells(), points);
|
||||
return renumber(cellCells.unpack(), points);
|
||||
}
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ Foam::labelList Foam::renumberMethod::renumber
|
||||
(
|
||||
renumber
|
||||
(
|
||||
coarseCellCells(),
|
||||
coarseCellCells.unpack(),
|
||||
coarsePoints
|
||||
)
|
||||
);
|
||||
|
||||
@ -50,16 +50,14 @@ namespace Foam
|
||||
|
||||
class renumberMethod
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
// Protected Data
|
||||
|
||||
const dictionary& renumberDict_;
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
// Protected Member Functions
|
||||
|
||||
//- No copy construct
|
||||
renumberMethod(const renumberMethod&) = delete;
|
||||
@ -118,7 +116,7 @@ public:
|
||||
virtual labelList renumber(const pointField&) const
|
||||
{
|
||||
NotImplemented;
|
||||
return labelList(0);
|
||||
return labelList();
|
||||
}
|
||||
|
||||
//- Return the order in which cells need to be visited, i.e.
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -75,7 +75,7 @@ Foam::labelList Foam::springRenumber::renumber
|
||||
cellCells
|
||||
);
|
||||
|
||||
return renumber(cellCells(), points);
|
||||
return renumber(cellCells.unpack(), points);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user