CompactListList: Removed unnecessary templating and create unallocated base

This commit is contained in:
Will Bainbridge
2022-02-04 12:16:18 +00:00
parent 05bb716bf8
commit a7030ee97e
17 changed files with 690 additions and 462 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -88,7 +88,7 @@ int main(int argc, char *argv[])
cll2(2, 3) = 999;
Info<< "cll2(2, 3) = " << cll2(2, 3) << nl << endl;
Info<< "cll2 as List<List<label >> " << cll2()
Info<< "cll2 as List<List<label >> " << cll2.list()
<< endl;
cll2.setSize(3);
@ -144,10 +144,10 @@ int main(int argc, char *argv[])
fcs[0] = face(labelList(1, 111));
fcs[1] = face(labelList(2, 222));
CompactListList<label, face> compactFcs(fcs);
CompactListList<label> compactFcs(fcs);
Info<< "compactFcs:" << compactFcs << endl;
faceList fcs2 = compactFcs();
faceList fcs2 = compactFcs.list<face>();
Info<< "fcs2:" << fcs2 << endl;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -27,11 +27,13 @@ License
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList(const List<Container>& ll)
template<class T>
template<class Container>
Foam::CompactListList<T>::CompactListList(const List<Container>& ll)
:
size_(ll.size()),
offsets_(ll.size()+1)
UCompactListList<T>(),
offsets_(ll.size() + 1),
m_()
{
label sumSize = 0;
offsets_[0] = 0;
@ -46,46 +48,26 @@ Foam::CompactListList<T, Container>::CompactListList(const List<Container>& ll)
label k = 0;
forAll(ll, i)
{
const Container& lli = ll[i];
forAll(lli, j)
forAll(ll[i], j)
{
m_[k++] = lli[j];
m_[k++] = ll[i][j];
}
}
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
template<class T, class Container>
Foam::CompactListList<T, Container>::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
template<class T>
Foam::CompactListList<T>::CompactListList
(
const labelUList& rowSizes,
const T& t
)
:
size_(rowSizes.size()),
offsets_(rowSizes.size()+1)
UCompactListList<T>(),
offsets_(rowSizes.size() + 1),
m_()
{
label sumSize = 0;
offsets_[0] = 0;
@ -96,48 +78,28 @@ Foam::CompactListList<T, Container>::CompactListList
}
m_.setSize(sumSize, t);
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
CompactListList<T, Container>&& lst
)
{
transfer(lst);
}
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList
(
CompactListList<T, Container>& lst,
bool reuse
)
:
size_(lst.size()),
offsets_(lst.offsets_, reuse),
m_(lst.m_, reuse)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize(const label mRows)
template<class T>
void Foam::CompactListList<T>::setSize(const label mRows)
{
if (mRows == 0)
{
clear();
}
if (mRows < size())
if (mRows < this->size())
{
size_ = mRows;
offsets_.setSize(mRows+1);
offsets_.setSize(mRows + 1);
m_.setSize(offsets_[mRows]);
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
else if (mRows > size())
else if (mRows > this->size())
{
FatalErrorInFunction
<< "Cannot be used to extend the list from " << offsets_.size()
@ -148,38 +110,39 @@ void Foam::CompactListList<T, Container>::setSize(const label mRows)
}
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize
template<class T>
void Foam::CompactListList<T>::setSize
(
const label mRows,
const label nData
)
{
size_ = mRows;
offsets_.setSize(mRows+1);
offsets_.setSize(mRows + 1);
m_.setSize(nData);
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize
template<class T>
void Foam::CompactListList<T>::setSize
(
const label mRows,
const label nData,
const T& t
)
{
size_ = mRows;
offsets_.setSize(mRows+1);
offsets_.setSize(mRows + 1);
m_.setSize(nData, t);
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
template<class T, class Container>
void Foam::CompactListList<T, Container>::setSize(const labelUList& rowSizes)
template<class T>
void Foam::CompactListList<T>::setSize(const labelUList& rowSizes)
{
size_ = rowSizes.size();
offsets_.setSize(rowSizes.size()+1);
offsets_.setSize(rowSizes.size() + 1);
label sumSize = 0;
offsets_[0] = 0;
@ -190,62 +153,30 @@ void Foam::CompactListList<T, Container>::setSize(const labelUList& rowSizes)
}
m_.setSize(sumSize);
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
template<class T, class Container>
Foam::labelList Foam::CompactListList<T, Container>::sizes() const
template<class T>
void Foam::CompactListList<T>::clear()
{
labelList rowSizes(size());
if (rowSizes.size() > 0)
{
forAll(rowSizes, i)
{
rowSizes[i] = offsets_[i+1] - offsets_[i];
}
}
return rowSizes;
}
template<class T, class Container>
void Foam::CompactListList<T, Container>::clear()
{
size_ = 0;
offsets_.clear();
offsets_ = List<label>(1, 0);
m_.clear();
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
template<class T, class Container>
void Foam::CompactListList<T, Container>::transfer
(
CompactListList<T, Container>& a
)
template<class T>
void Foam::CompactListList<T>::transfer(CompactListList<T>& a)
{
size_ = a.size_;
offsets_.transfer(a.offsets_);
m_.transfer(a.m_);
a.size_ = 0;
}
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Container>
Foam::List<Container> Foam::CompactListList<T, Container>::operator()()
const
{
List<Container> ll(size());
forAll(ll, i)
{
ll[i] = Container(operator[](i));
}
return ll;
a.clear();
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -36,9 +36,6 @@ Description
Storage is allocated on free-store during construction.
As a special case a null-constructed CompactListList has an empty
offsets_ (instead of size 1).
SourceFiles
CompactListList.C
CompactListListI.H
@ -49,7 +46,7 @@ SourceFiles
#ifndef CompactListList_H
#define CompactListList_H
#include "labelList.H"
#include "UCompactListList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,31 +55,22 @@ namespace Foam
// Forward declaration of friend functions and operators
template<class T, class Container> class CompactListList;
template<class T> 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>&);
/*---------------------------------------------------------------------------*\
Class CompactListList Declaration
\*---------------------------------------------------------------------------*/
template<class T, class Container = List<T>>
template<class T>
class CompactListList
:
public UCompactListList<T>
{
// Private Data
label size_;
//- Offset table
List<label> offsets_;
@ -95,7 +83,7 @@ public:
// Static Member Functions
//- Return a null CompactListList
inline static const CompactListList<T, Container>& null();
inline static const CompactListList<T>& null();
// Constructors
@ -103,59 +91,35 @@ public:
//- Null constructor.
inline CompactListList();
//- Construct from components
inline CompactListList(const UList<label>& offsets, const UList<T>& m);
//- Construct as copy or re-use as specified.
inline CompactListList(CompactListList<T>&, bool reuse);
//- Move constructor
CompactListList(CompactListList<T, Container>&&);
//- 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);
inline CompactListList(CompactListList<T>&&);
//- 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 by converting given List<Container>
template<class Container>
CompactListList(const List<Container>&);
//- Construct given list of row-sizes
//- Construct given list of row-sizes and a value for all elements
CompactListList(const labelUList& rowSizes, const T&);
//- Construct as copy or re-use as specified.
CompactListList(CompactListList<T, Container>&, bool reuse);
//- Construct from Istream.
CompactListList(Istream&);
//- Clone
inline autoPtr<CompactListList<T, Container>> clone() const;
inline autoPtr<CompactListList<T>> clone() const;
// Member Functions
// Access
//- Return the primary size, i.e. the number of rows
inline label size() const;
//- Return true if the number of rows is zero
inline bool empty() const;
//- Return the offset table (= size()+1)
inline const List<label>& offsets() const;
//- Return non-const access to the offset table
inline List<label>& offsets();
//- Return the packed matrix of data
inline const List<T>& m() const;
//- Return non-const access to the packed matrix of data
inline List<T>& m();
// Edit
//- Reset size of CompactListList.
@ -187,65 +151,23 @@ public:
//- Clear the CompactListList, i.e. set sizes to zero.
void clear();
//- Return sizes (to be used e.g. for construction)
labelList sizes() const;
//- Transfer the contents of the argument CompactListList
// into this CompactListList and annul the argument list.
void transfer(CompactListList<T, Container>&);
void transfer(CompactListList<T>&);
// Other
//- Return index into m
inline label index(const label row, const label col) const;
//- Get row for index into m.
inline label whichRow(const label index) const;
//- Get column index (j) given above row
inline label whichColumn(const label row, const label index) const;
// Member Operators
//- Return subscript-checked row as UList.
inline UList<T> operator[](const label i);
//- Return const subscript-checked row as UList.
inline const UList<T> operator[](const label i) const;
//- 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;
//- Move assignment operator
inline void operator=(CompactListList<T, Container>&&);
//- Assignment of all entries to the given value
inline void operator=(const T&);
//- Disallow shallowCopy
void shallowCopy(const UCompactListList<T>&) = delete;
// Istream operator
//- Read CompactListList from Istream, discarding contents
// of existing CompactListList.
friend Istream& operator>> <T, Container>
friend Istream& operator>> <T>
(
Istream&,
CompactListList<T, Container>&
);
// Write CompactListList to Ostream.
friend Ostream& operator<< <T, Container>
(
Ostream&,
const CompactListList<T, Container>&
CompactListList<T>&
);
};
@ -256,7 +178,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "CompactListListI.H"
#include "CompactListListI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,156 +23,99 @@ License
\*---------------------------------------------------------------------------*/
#include "CompactListList.H"
#include "ListOps.H"
#include "SubList.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList()
template<class T>
inline Foam::CompactListList<T>::CompactListList()
:
size_(0)
{}
UCompactListList<T>(),
offsets_(1, 0),
m_()
{
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList
template<class T>
inline Foam::CompactListList<T>::CompactListList
(
const label mRows,
const label nData
const UList<label>& offsets,
const UList<T>& m
)
:
size_(mRows),
offsets_(mRows+1, 0),
m_(nData)
UCompactListList<T>(offsets, m),
offsets_(offsets),
m_(m)
{}
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList
template<class T>
Foam::CompactListList<T>::CompactListList(CompactListList<T>& lst, bool reuse)
:
UCompactListList<T>(),
offsets_(lst.offsets_, reuse),
m_(lst.m_, reuse)
{
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
template<class T>
Foam::CompactListList<T>::CompactListList(CompactListList<T>&& lst)
{
transfer(lst);
}
template<class T>
inline Foam::CompactListList<T>::CompactListList
(
const label mRows,
const label nData,
const T& t
)
:
size_(mRows),
offsets_(mRows+1, 0),
UCompactListList<T>(),
offsets_(mRows + 1, 0),
m_(nData, t)
{}
template<class T, class Container>
inline Foam::autoPtr<Foam::CompactListList<T, Container>>
Foam::CompactListList<T, Container>::clone() const
{
return autoPtr<CompactListList<T, Container>>
UCompactListList<T>::shallowCopy(UCompactListList<T>(offsets_, m_));
}
template<class T>
inline Foam::autoPtr<Foam::CompactListList<T>>
Foam::CompactListList<T>::clone() const
{
return autoPtr<CompactListList<T>>
(
new CompactListList<T, Container>(*this)
new CompactListList<T>(*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::CompactListList<T>&
Foam::CompactListList<T>::null()
{
return NullObjectRef<CompactListList<T, Container>>();
return NullObjectRef<CompactListList<T>>();
}
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::size() const
{
return size_;
}
template<class T, class Container>
inline bool Foam::CompactListList<T, Container>::empty() const
{
return !size_;
}
template<class T, class Container>
inline const Foam::List<Foam::label>&
Foam::CompactListList<T, Container>::offsets() const
{
return offsets_;
}
template<class T, class Container>
inline Foam::List<Foam::label>& Foam::CompactListList<T, Container>::offsets()
{
return offsets_;
}
template<class T, class Container>
inline const Foam::List<T>& Foam::CompactListList<T, Container>::m()
const
{
return m_;
}
template<class T, class Container>
inline Foam::List<T>& Foam::CompactListList<T, Container>::m()
{
return m_;
}
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::index
(
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 i
) const
{
return i - index(row, 0);
}
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize(const label mRows)
template<class T>
inline void Foam::CompactListList<T>::resize(const label mRows)
{
this->setSize(mRows);
}
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
template<class T>
inline void Foam::CompactListList<T>::resize
(
const label mRows,
const label nData
@ -182,8 +125,8 @@ inline void Foam::CompactListList<T, Container>::resize
}
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
template<class T>
inline void Foam::CompactListList<T>::resize
(
const label mRows,
const label nData,
@ -194,8 +137,8 @@ inline void Foam::CompactListList<T, Container>::resize
}
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
template<class T>
inline void Foam::CompactListList<T>::resize
(
const labelUList& rowSizes
)
@ -204,72 +147,4 @@ inline void Foam::CompactListList<T, Container>::resize
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Container>
inline Foam::UList<T> Foam::CompactListList<T, Container>::operator[]
(
const label i
)
{
label start = offsets_[i];
return UList<T>(m_.begin() + start, offsets_[i+1] - start);
}
template<class T, class Container>
inline const Foam::UList<T>
Foam::CompactListList<T, Container>::operator[]
(
const label i
) const
{
label start = offsets_[i];
return UList<T>
(
const_cast<T*>(m_.begin() + start),
offsets_[i+1] - start
);
}
template<class T, class Container>
inline T& Foam::CompactListList<T, Container>::operator()
(
const label i,
const label j
)
{
return m_[index(i, j)];
}
template<class T, class Container>
inline const T& Foam::CompactListList<T, Container>::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=
(
CompactListList<T, Container>&& cll
)
{
transfer(cll);
}
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::operator=(const T& t)
{
m_ = t;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -28,8 +28,8 @@ License
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T, class Container>
Foam::CompactListList<T, Container>::CompactListList(Istream& is)
template<class T>
Foam::CompactListList<T>::CompactListList(Istream& is)
{
operator>>(is, *this);
}
@ -37,33 +37,24 @@ Foam::CompactListList<T, Container>::CompactListList(Istream& is)
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T, class Container>
Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T, Container>& lst)
template<class T>
Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T>& lst)
{
is >> lst.offsets_ >> lst.m_;
// Note: empty list gets output as two empty lists
if (lst.offsets_.size() == 0)
// An empty compact list list gets output as two empty lists
if (lst.offsets_.empty())
{
lst.size_ = 0;
}
else
{
lst.size_ = lst.offsets_.size()-1;
lst.clear();
}
lst.UCompactListList<T>::shallowCopy
(
UCompactListList<T>(lst.offsets_, lst.m_)
);
return is;
}
template<class T, class Container>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const CompactListList<T, Container>& lst
)
{
os << lst.offsets_ << lst.m_;
return os;
}
// ************************************************************************* //

View File

@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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/>.
\*---------------------------------------------------------------------------*/
#include "UCompactListList.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
Foam::labelList Foam::UCompactListList<T>::sizes() const
{
labelList rowSizes(size());
if (rowSizes.size() > 0)
{
forAll(rowSizes, i)
{
rowSizes[i] = offsets_[i+1] - offsets_[i];
}
}
return rowSizes;
}
template<class T>
template<class Container>
Foam::List<Container> Foam::UCompactListList<T>::list() const
{
List<Container> ll(size());
forAll(ll, i)
{
ll[i] = Container(operator[](i));
}
return ll;
}
// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
#include "UCompactListListIO.C"
// ************************************************************************* //

View File

@ -0,0 +1,179 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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::UCompactListList
Description
Unallocated base class of CompactListList
SourceFiles
UCompactListList.C
UCompactListListI.H
UCompactListListIO.C
\*---------------------------------------------------------------------------*/
#ifndef UCompactListList_H
#define UCompactListList_H
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
template<class T> class UCompactListList;
template<class T> Ostream& operator<<(Ostream&, const UCompactListList<T>&);
/*---------------------------------------------------------------------------*\
Class UCompactListList Declaration
\*---------------------------------------------------------------------------*/
template<class T>
class UCompactListList
{
// Private Data
//- Offset table
UList<label> offsets_;
//- Packed matrix of data
UList<T> m_;
public:
// Static Member Functions
//- Return a null UCompactListList
inline static const UCompactListList<T>& null();
// Constructors
//- Null constructor.
inline UCompactListList();
//- Construct from components
inline UCompactListList(const UList<label>& offsets, const UList<T>& m);
// Member Functions
// Access
//- Return the primary size, i.e. the number of rows
inline label size() const;
//- Return true if the number of rows is zero
inline bool empty() const;
//- Return the offset table (= size()+1)
inline const UList<label>& offsets() const;
//- Return non-const access to the offset table
inline UList<label>& offsets();
//- Return the packed matrix of data
inline const UList<T>& m() const;
//- Return non-const access to the packed matrix of data
inline UList<T>& m();
//- Copy the ULists, but not the underlying data
inline void shallowCopy(const UCompactListList<T>&);
//- Copy the underlying data
inline void deepCopy(const UCompactListList<T>&);
//- Return index into m
inline label index(const label row, const label col) const;
//- Get row for index into m.
inline label whichRow(const label index) const;
//- Get column index (j) given above row
inline label whichColumn(const label row, const label index) const;
//- Return sizes (to be used e.g. for construction)
labelList sizes() const;
//- Convert to List<Container>
template<class Container = List<T>>
List<Container> list() const;
// Member Operators
//- Return subscript-checked row as UList.
inline UList<T> operator[](const label i);
//- Return const subscript-checked row as UList.
inline const UList<T> operator[](const label i) const;
//- 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;
//- Assignment of all entries to the given value
inline void operator=(const T&);
// Istream operator
// Write UCompactListList to Ostream.
friend Ostream& operator<< <T>
(
Ostream&,
const UCompactListList<T>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "UCompactListListI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "UCompactListList.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,221 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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/>.
\*---------------------------------------------------------------------------*/
#include "UCompactListList.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline Foam::UCompactListList<T>::UCompactListList()
:
offsets_(nullptr, 1),
m_()
{}
template<class T>
inline Foam::UCompactListList<T>::UCompactListList
(
const UList<label>& offsets,
const UList<T>& m
)
:
offsets_(offsets),
m_(m)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline const Foam::UCompactListList<T>&
Foam::UCompactListList<T>::null()
{
return NullObjectRef<UCompactListList<T>>();
}
template<class T>
inline Foam::label Foam::UCompactListList<T>::size() const
{
return offsets_.size() - 1;
}
template<class T>
inline bool Foam::UCompactListList<T>::empty() const
{
return !size();
}
template<class T>
inline const Foam::UList<Foam::label>&
Foam::UCompactListList<T>::offsets() const
{
return offsets_;
}
template<class T>
inline Foam::UList<Foam::label>& Foam::UCompactListList<T>::offsets()
{
return offsets_;
}
template<class T>
inline const Foam::UList<T>& Foam::UCompactListList<T>::m()
const
{
return m_;
}
template<class T>
inline Foam::UList<T>& Foam::UCompactListList<T>::m()
{
return m_;
}
template<class T>
inline void Foam::UCompactListList<T>::shallowCopy
(
const UCompactListList<T>& l
)
{
offsets_.shallowCopy(l.offsets_);
m_.shallowCopy(l.m_);
}
template<class T>
inline void Foam::UCompactListList<T>::deepCopy
(
const UCompactListList<T>& l
)
{
offsets_.deepCopy(l.offsets_);
m_.deepCopy(l.m_);
}
template<class T>
inline Foam::label Foam::UCompactListList<T>::index
(
const label i,
const label j
) const
{
return offsets_[i] + j;
}
template<class T>
inline Foam::label Foam::UCompactListList<T>::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>
inline Foam::label Foam::UCompactListList<T>::whichColumn
(
const label row,
const label i
) const
{
return i - index(row, 0);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline Foam::UList<T> Foam::UCompactListList<T>::operator[]
(
const label i
)
{
label start = offsets_[i];
return UList<T>(m_.begin() + start, offsets_[i+1] - start);
}
template<class T>
inline const Foam::UList<T>
Foam::UCompactListList<T>::operator[]
(
const label i
) const
{
label start = offsets_[i];
return UList<T>
(
const_cast<T*>(m_.begin() + start),
offsets_[i+1] - start
);
}
template<class T>
inline T& Foam::UCompactListList<T>::operator()
(
const label i,
const label j
)
{
return m_[index(i, j)];
}
template<class T>
inline const T& Foam::UCompactListList<T>::operator()
(
const label i,
const label j
) const
{
return m_[index(i, j)];
}
template<class T>
inline void Foam::UCompactListList<T>::operator=(const T& t)
{
m_ = t;
}
// ************************************************************************* //

View File

@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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/>.
\*---------------------------------------------------------------------------*/
#include "UCompactListList.H"
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const UCompactListList<T>& lst
)
{
// An empty compact list list gets output as two empty lists
os << (lst.size() ? lst.offsets_ : labelUList()) << lst.m_;
return os;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -1594,7 +1594,7 @@ void Foam::fvMeshDistribute::sendMesh
// Send
toDomain
<< mesh.points()
<< CompactListList<label, face>(mesh.faces())
<< CompactListList<label>(mesh.faces())
<< mesh.faceOwner()
<< mesh.faceNeighbour()
<< mesh.boundaryMesh()
@ -1641,7 +1641,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::fvMeshDistribute::receiveMesh
)
{
pointField domainPoints(fromNbr);
faceList domainFaces = CompactListList<label, face>(fromNbr)();
faceList domainFaces = CompactListList<label>(fromNbr).list<face>();
labelList domainAllOwner(fromNbr);
labelList domainAllNeighbour(fromNbr);
PtrList<entry> patchEntries(fromNbr);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -89,7 +89,7 @@ class dictionary;
class topoAction;
class objectMap;
class IOobject;
template<class T, class Container> class CompactListList;
template<class T> class CompactListList;
/*---------------------------------------------------------------------------*\
Class polyTopoChange Declaration
@ -272,13 +272,13 @@ class polyTopoChange
void makeCellCells
(
const label nActiveFaces,
CompactListList<label, labelList>& cellCells
CompactListList<label>& cellCells
) const;
//- Cell ordering (bandCompression). Returns number of remaining cells.
label getCellOrder
(
const CompactListList<label, labelList>&,
const CompactListList<label>&,
labelList&
) const;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -51,7 +51,7 @@ void Foam::ORourkeCollision<CloudType>::collide
}
// Initialise the sizes of the lists of parcels in each cell
CompactListList<parcelType*> pInCell(occupancy);
CompactListList<parcelType*> pInCell(occupancy, nullptr);
// Reset the occupancy to use as a counter
occupancy = 0;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -224,7 +224,7 @@ Foam::labelList Foam::decompositionMethod::decompose
(
decompose
(
coarseCellCells(),
coarseCellCells.list(),
coarsePoints,
coarseWeights
)
@ -382,7 +382,7 @@ void Foam::decompositionMethod::calcCellCells
nFacesPerCell = 0;
labelList& m = cellCells.m();
labelUList& m = cellCells.m();
const labelList& offsets = cellCells.offsets();
// For internal faces is just offsetted owner and neighbour
@ -459,7 +459,7 @@ void Foam::decompositionMethod::calcCellCells
cellCells.offsets()[celli+1] = newIndex;
}
cellCells.m().setSize(newIndex);
cellCells.setSize(cellCells.size(), newIndex);
}
@ -574,8 +574,8 @@ void Foam::decompositionMethod::calcCellCells
nFacesPerCell = 0;
labelList& m = cellCells.m();
scalarList& w = cellCellWeights.m();
labelUList& m = cellCells.m();
scalarUList& w = cellCellWeights.m();
const labelList& offsets = cellCells.offsets();
// For internal faces is just offsetted owner and neighbour
@ -662,8 +662,8 @@ void Foam::decompositionMethod::calcCellCells
cellCellWeights.offsets()[cellI+1] = newIndex;
}
cellCells.m().setSize(newIndex);
cellCellWeights.m().setSize(newIndex);
cellCells.setSize(cellCells.size(), newIndex);
cellCellWeights.setSize(cellCells.size(), newIndex);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -386,7 +386,7 @@ Foam::labelList Foam::multiLevelDecomp::decompose
decompose
(
cellCells(),
cellCells.list(),
cc,
cWeights,
cellMap, // map back to original cells

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -76,7 +76,7 @@ Foam::labelList Foam::CuthillMcKeeRenumber::renumber
cellCells
);
labelList orderedToOld = bandCompression(cellCells());
labelList orderedToOld = bandCompression(cellCells.list());
if (reverse_)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -90,7 +90,7 @@ Foam::labelList Foam::renumberMethod::renumber
);
// Renumber based on agglomerated points
return renumber(cellCells(), points);
return renumber(cellCells.list(), points);
}
@ -128,7 +128,7 @@ Foam::labelList Foam::renumberMethod::renumber
(
renumber
(
coarseCellCells(),
coarseCellCells.list(),
coarsePoints
)
);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -72,7 +72,7 @@ Foam::labelList Foam::springRenumber::renumber
cellCells
);
return renumber(cellCells(), points);
return renumber(cellCells.list(), points);
}