Commit c4c0f54f authored by mattijs's avatar mattijs
Browse files

dynamicList change

parent ecf18da9
......@@ -184,10 +184,6 @@ int main(int argc, char *argv[])
<< endl;
// Transfer DynamicLists to straight ones.
labelList cutEdges;
cutEdges.transfer(allCutEdges);
allCutEdges.clear();
scalarField cutEdgeWeights;
cutEdgeWeights.transfer(allCutEdgeWeights);
allCutEdgeWeights.clear();
......@@ -199,7 +195,7 @@ int main(int argc, char *argv[])
mesh,
cutCells.toc(), // cells candidate for cutting
labelList(0), // cut vertices
cutEdges, // cut edges
allCutEdges, // cut edges
cutEdgeWeights // weight on cut edges
);
......
......@@ -35,11 +35,8 @@ Description
#include "IOstreams.H"
#include "SLPtrList.H"
#include "boolList.H"
#include "cellList.H"
#include "primitiveMesh.H"
#include "cyclicFvPatch.H"
#include "fvPatchList.H"
#include "DynamicList.H"
#include "cyclicPolyPatch.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......
......@@ -33,7 +33,7 @@ License
#include "OSspecific.H"
#include "Map.H"
#include "globalMeshData.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......
......@@ -45,7 +45,6 @@ Description
#include "IOobjectList.H"
#include "boolList.H"
#include "stringList.H"
#include "DynamicList.H"
#include "cellModeller.H"
#include "floatScalar.H"
......
......@@ -27,9 +27,6 @@ License
#include "internalWriter.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
......
......@@ -29,9 +29,6 @@ License
#include "Cloud.H"
#include "passiveParticle.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
......
......@@ -78,6 +78,7 @@ void writePatchGeom
writeFuns::write(pStream, binary, vertLabels);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......
......@@ -103,6 +103,7 @@ void writePointSet
writeFuns::write(pStream, binary, pointIDs);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......
......@@ -33,7 +33,7 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList(Istream& is)
:
List<T>(is),
nextFree_(List<T>::size())
allocSize_(List<T>::size())
{}
......@@ -44,9 +44,6 @@ Foam::Ostream& Foam::operator<<
const Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>& DL
)
{
const_cast<DynamicList<T, SizeInc, SizeMult, SizeDiv>&>(DL)
.setSize(DL.nextFree_);
os << static_cast<const List<T>&>(DL);
return os;
}
......@@ -60,7 +57,7 @@ Foam::Istream& Foam::operator>>
)
{
is >> static_cast<List<T>&>(DL);
DL.nextFree_ = DL.List<T>::size();
DL.allocSize_ = DL.List<T>::size();
return is;
}
......
......@@ -81,24 +81,29 @@ class DynamicList
{
// Private data
//- Number of next free element
label nextFree_;
//- Allocated size for underlying List.
label allocSize_;
public:
// Related types
//- Declare friendship with the List class
friend class List<T>;
// Constructors
//- Construct null
inline DynamicList();
//- Construct given size
//- Construct given size.
explicit inline DynamicList(const label);
//- Construct from UList. nextFree_ set to size().
//- Construct from UList. Size set to UList size.
explicit inline DynamicList(const UList<T>&);
//- Construct from Istream. nextFree_ set to size().
//- Construct from Istream. Size set to size of read list.
explicit DynamicList(Istream&);
......@@ -106,22 +111,24 @@ public:
// Access
//- Size of the active part of the list.
// Direct over-ride of list size member function
inline label size() const;
//- Size of the underlying storage.
inline label allocSize() const;
// Edit
//- Reset size of List.
void setSize(const label);
inline void setSize(const label);
//- Reset size of List and value for new elements.
void setSize(const label, const T&);
inline void setSize(const label, const T&);
//- Clear the list, i.e. set next free to zero.
//- Clear the list, i.e. set the size to zero.
// Allocated size does not change
void clear();
inline void clear();
//- Clear the list and delete storage.
inline void clearStorage();
//- Shrink the List<T> to the number of elements used
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink();
......@@ -130,11 +137,11 @@ public:
// and annull the argument list. Is same as List::transfer except
// checks that you're not changing the underlying list to something
// smaller than nextFree_.
void transfer(List<T>&);
inline void transfer(List<T>&);
//- Transfer the contents of the argument DynamicList into this
// DynamicList and annull the argument list.
void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
// Member Operators
......@@ -152,9 +159,15 @@ public:
//- Assignment of all entries to the given value
inline void operator=(const T&);
//- Assignment to List<T>
//- Assignment from List<T>
inline void operator=(const List<T>&);
//- Assignment from DynamicList<T>
inline void operator=
(
const DynamicList<T, SizeInc, SizeMult, SizeDiv>&
);
// IOstream operators
......
......@@ -31,8 +31,10 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
:
List<T>(SizeInc),
nextFree_(0)
{}
allocSize_(SizeInc)
{
List<T>::size() = 0;
}
//- Construct given size
......@@ -43,8 +45,10 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
)
:
List<T>(s),
nextFree_(0)
{}
allocSize_(s)
{
List<T>::size() = 0;
}
//- Construct given size
......@@ -55,17 +59,17 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
)
:
List<T>(s),
nextFree_(s.size())
allocSize_(s.size())
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::label Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::size()
inline Foam::label Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::allocSize()
const
{
return nextFree_;
return allocSize_;
}
......@@ -75,13 +79,14 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
const label s
)
{
if (s < nextFree_)
if (s < List<T>::size())
{
nextFree_ = s;
List<T>::size() = s;
}
else
{
List<T>::setSize(s);
allocSize_ = s;
List<T>::setSize(allocSize_);
}
}
......@@ -93,14 +98,14 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
const T& t
)
{
if (s < nextFree_)
if (s < List<T>::size())
{
nextFree_ = s;
List<T>::size() = s;
}
else
{
List<T>::setSize(s, t);
nextFree_ = s;
allocSize_ = s;
List<T>::setSize(allocSize_, t);
}
}
......@@ -108,7 +113,16 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::clear()
{
nextFree_ = 0;
List<T>::size() = 0;
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::clearStorage()
{
List<T>::size() = allocSize_; // make List<T> consistent
List<T>::clear();
allocSize_ = 0;
}
......@@ -116,7 +130,8 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>&
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::shrink()
{
List<T>::setSize(nextFree_);
allocSize_ = List<T>::size();
List<T>::setSize(allocSize_);
return *this;
}
......@@ -125,20 +140,20 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer(List<T>& l)
{
if (l.size() < nextFree_)
if (l.size() < List<T>::size())
{
FatalErrorIn
(
"void DynamicList<T, SizeInc, SizeMult"
", SizeDiv>::transfer(List<T>&)"
) << "Cannot replace the underlying storage of this DynamicList"
<< " of which " << nextFree_ << " elements are used" << nl
<< " of which " << List<T>::size() << " elements are used" << nl
<< "with a List of size " << l.size() << abort(FatalError);
}
else
{
allocSize_ = l.size();
List<T>::transfer(l); // take over storage
l.clear(); // set nextFree of l to 0
}
}
......@@ -150,40 +165,40 @@ Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer
DynamicList<T, SizeInc, SizeMult, SizeDiv>& l
)
{
allocSize_ = l.allocSize();
List<T>::transfer(l); // take over storage
nextFree_ = l.size(); // take over used size
l.clear(); // set nextFree of l to 0
l.allocSize_ = 0;
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
(
const T& e
)
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append(const T& e)
{
nextFree_++;
// Work on copy free index since gets overwritten by setSize
label nextFree = List<T>::size();
if (nextFree_ > List<T>::size())
nextFree++;
if (nextFree > allocSize_)
{
List<T>::setSize
allocSize_ = max
(
max
(
nextFree_,
label(SizeMult*List<T>::size()/SizeDiv + SizeInc)
)
nextFree,
label(SizeMult*allocSize_/SizeDiv + SizeInc)
);
List<T>::setSize(allocSize_);
}
this->operator[](nextFree_ - 1) = e;
this->operator[](nextFree - 1) = e;
List<T>::size() = nextFree;
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline T Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::remove()
{
if (nextFree_ == 0)
if (List<T>::size() == 0)
{
FatalErrorIn
(
......@@ -191,7 +206,7 @@ inline T Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::remove()
) << "List is empty" << abort(FatalError);
}
return List<T>::operator[](--nextFree_);
return List<T>::operator[](--List<T>::size());
}
......@@ -203,20 +218,22 @@ inline T& Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator()
const label i
)
{
nextFree_ = max(nextFree_, i + 1);
label nextFree = List<T>::size();
if (nextFree_ > List<T>::size())
nextFree = max(nextFree, i + 1);
if (nextFree > allocSize_)
{
List<T>::setSize
allocSize_ = max
(
max
(
nextFree_,
label(SizeMult*List<T>::size()/SizeDiv + SizeInc)
)
nextFree,
label(SizeMult*allocSize_/SizeDiv + SizeInc)
);
List<T>::setSize(allocSize_);
}
List<T>::size() = nextFree;
return this->operator[](i);
}
......@@ -228,7 +245,7 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
)
{
List<T>::operator=(t);
nextFree_ = List<T>::size();
allocSize_ = List<T>::size();
}
......@@ -239,7 +256,18 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
)
{
List<T>::operator=(l);
nextFree_ = l.size();
allocSize_ = List<T>::size();
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
(
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& l
)
{
List<T>::operator=(l);
allocSize_ = l.allocSize();
}
......
......@@ -420,6 +420,23 @@ void List<T>::transfer(List<T>& a)
}
// Transfer the contents of the argument DynamicList into this List
// and anull the argument list
template<class T>
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
void List<T>::transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a)
{
if (this->v_) delete[] this->v_;
this->size_ = a.size_;
this->v_ = a.v_;
a.size_ = 0;
a.allocSize_ = 0;
a.v_ = 0;
}
template<class T>
void sort(List<T>& a)
{
......
......@@ -61,6 +61,8 @@ template<class T> Istream& operator>>(Istream&, List<T>&);
template<class T, label Size> class FixedList;
template<class T> class PtrList;
template<class T> class SLList;
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
class DynamicList;
template<class T> class IndirectList;
template<class T> class BiIndirectList;
......@@ -156,6 +158,11 @@ public:
// and annull the argument list.
void transfer(List<T>&);
//- Transfer the contents of the argument List into this List
// and annull the argument list.
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
//- Return subscript-checked element of UList.
inline T& newElmt(const label);
......
......@@ -221,7 +221,7 @@ inline void PackedList<nBits>::operator=(const unsigned int val)
checkValue(val);
# endif
for (label i = 0; i < size; i++)
for (label i = 0; i < size_; i++)
{
set(i, val);
}
......
......@@ -397,13 +397,11 @@ void Foam::globalMeshData::calcSharedEdges() const
sharedEdgeLabelsPtr_ = new labelList();
labelList& sharedEdgeLabels = *sharedEdgeLabelsPtr_;
sharedEdgeLabels.transfer(dynSharedEdgeLabels);
dynSharedEdgeLabels.clear();
dynSharedEdgeAddr.shrink();
sharedEdgeAddrPtr_ = new labelList();
labelList& sharedEdgeAddr = *sharedEdgeAddrPtr_;
sharedEdgeAddr.transfer(dynSharedEdgeAddr);
dynSharedEdgeAddr.clear();
if (debug)
{
......
......@@ -102,8 +102,9 @@ void Foam::PrimitivePatchExtra<Face, ListType, PointField, PointType>::markZone
break;
}
changedFaces.transfer(newChangedFaces.shrink());
newChangedFaces.clear();
// New dynamiclist: can leave dynamicList unshrunk
//changedFaces.transfer(newChangedFaces.shrink());
changedFaces.transfer(newChangedFaces);
}
}
......
......@@ -441,11 +441,10 @@ void primitiveMesh::calcEdges(const bool doFaceEdges) const
forAll(pe, pointI)
{
DynamicList<label>& pEdges = pe[pointI];
inplaceRenumber(oldToNew, pEdges);
pEdges.shrink();
inplaceRenumber(oldToNew, pEdges);
pointEdges[pointI].transfer(pEdges);
Foam::sort(pointEdges[pointI]);
pEdges.clear();
}
// faceEdges
......
......@@ -29,7 +29,6 @@ License
#include "polyMesh.H"
#include "cellModeller.H"
#include "mathematicalConstants.H"
#include "DynamicList.H"
#include "plane.H"
#include "ListOps.H"
#include "meshTools.H"
......
......@@ -40,7 +40,6 @@ SourceFiles
#include "boolList.H"
#include "labelList.H"
#include "typeInfo.H"
#include "DynamicList.H"
#include "Map.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -113,10 +113,8 @@ SourceFiles
#define meshCutter_H
#include "edgeVertex.H"
#include "boolList.H"
#include "labelList.H"
#include "typeInfo.H"
#include "DynamicList.H"
#include "Map.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......