From c4c0f54fc65e7300aef28751f6db902462a4f664 Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 17 Sep 2008 11:53:14 +0100 Subject: [PATCH] dynamicList change --- .../refineWallLayer/refineWallLayer.C | 6 +- .../decomposePar/decomposeMesh.C | 5 +- .../decomposePar/domainDecomposition.C | 2 +- .../foamToFieldview9/foamToFieldview9.C | 1 - .../dataConversion/foamToVTK/internalWriter.C | 3 - .../foamToVTK/lagrangianWriter.C | 3 - .../dataConversion/foamToVTK/writePatchGeom.C | 1 + .../dataConversion/foamToVTK/writePointSet.C | 1 + .../Lists/DynamicList/DynamicList.C | 7 +- .../Lists/DynamicList/DynamicList.H | 43 ++++--- .../Lists/DynamicList/DynamicListI.H | 120 +++++++++++------- src/OpenFOAM/containers/Lists/List/List.C | 17 +++ src/OpenFOAM/containers/Lists/List/List.H | 7 + .../containers/Lists/PackedList/PackedListI.H | 2 +- .../polyMesh/globalMeshData/globalMeshData.C | 2 - .../PrimitivePatchExtraSearch.C | 5 +- .../meshes/primitiveMesh/primitiveMeshEdges.C | 3 +- .../meshCut/cellLooper/hexCellLooper.C | 1 - .../meshCutAndRemove/meshCutAndRemove.H | 1 - .../meshModifiers/meshCutter/meshCutter.H | 2 - .../refinementIterator/refinementIterator.C | 2 - .../polyTopoChange/edgeCollapser.C | 1 + .../polyTopoChange/faceCollapser.H | 1 - .../polyTopoChange/polyTopoChangeTemplates.C | 8 -- src/edgeMesh/edgeMesh.C | 2 +- src/meshTools/cellFeatures/cellFeatures.C | 2 +- src/meshTools/meshSearch/meshSearch.C | 9 +- .../distributedTriSurfaceMesh.C | 7 - .../searchableSurface/searchableBox.C | 1 - .../searchableSurface/triSurfaceMesh.C | 1 - .../intersectedSurface/edgeSurface.C | 3 - .../surfaceIntersectionTemplates.C | 1 - .../surfaceFeatures/surfaceFeatures.C | 1 - .../triSurfaceSearch/triSurfaceSearch.H | 1 - .../triSurfaceTools/triSurfaceTools.C | 8 +- src/sampling/cuttingPlane/cuttingPlane.C | 1 - .../sampledSet/midPoint/midPointSet.C | 1 - .../midPointAndFace/midPointAndFaceSet.C | 1 - .../foamChemistryReader/foamChemistryReader.H | 1 - .../triSurface/interfaces/AC3D/readAC.C | 6 +- .../triSurface/interfaces/NAS/readNAS.C | 2 +- .../triSurface/interfaces/OBJ/readOBJ.C | 7 +- 42 files changed, 147 insertions(+), 152 deletions(-) diff --git a/applications/utilities/mesh/advanced/refineWallLayer/refineWallLayer.C b/applications/utilities/mesh/advanced/refineWallLayer/refineWallLayer.C index 61a2f4d854..f4336bce92 100644 --- a/applications/utilities/mesh/advanced/refineWallLayer/refineWallLayer.C +++ b/applications/utilities/mesh/advanced/refineWallLayer/refineWallLayer.C @@ -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 ); diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposeMesh.C b/applications/utilities/parallelProcessing/decomposePar/decomposeMesh.C index 0d81b1aedd..55f5c96579 100644 --- a/applications/utilities/parallelProcessing/decomposePar/decomposeMesh.C +++ b/applications/utilities/parallelProcessing/decomposePar/decomposeMesh.C @@ -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 * * * * * * * * * * * // diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C index bee2d17b25..dd107c2f2f 100644 --- a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C +++ b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C @@ -33,7 +33,7 @@ License #include "OSspecific.H" #include "Map.H" #include "globalMeshData.H" - +#include "DynamicList.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/dataConversion/foamToFieldview9/foamToFieldview9.C b/applications/utilities/postProcessing/dataConversion/foamToFieldview9/foamToFieldview9.C index 3030a30316..7cf137cd0e 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToFieldview9/foamToFieldview9.C +++ b/applications/utilities/postProcessing/dataConversion/foamToFieldview9/foamToFieldview9.C @@ -45,7 +45,6 @@ Description #include "IOobjectList.H" #include "boolList.H" #include "stringList.H" -#include "DynamicList.H" #include "cellModeller.H" #include "floatScalar.H" diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/internalWriter.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/internalWriter.C index bf1fb3b775..1ac0d8b729 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/internalWriter.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/internalWriter.C @@ -27,9 +27,6 @@ License #include "internalWriter.H" #include "writeFuns.H" -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct from components diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriter.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriter.C index bbf24b1b17..ea7da50a40 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriter.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/lagrangianWriter.C @@ -29,9 +29,6 @@ License #include "Cloud.H" #include "passiveParticle.H" -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct from components diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writePatchGeom.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/writePatchGeom.C index 62b8661810..6ad993e0aa 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/writePatchGeom.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writePatchGeom.C @@ -78,6 +78,7 @@ void writePatchGeom writeFuns::write(pStream, binary, vertLabels); } + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writePointSet.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/writePointSet.C index ea7dbf4301..9e495e073d 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/writePointSet.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writePointSet.C @@ -103,6 +103,7 @@ void writePointSet writeFuns::write(pStream, binary, pointIDs); } + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.C b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.C index 8297002b82..24d1edea53 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.C +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.C @@ -33,7 +33,7 @@ template Foam::DynamicList::DynamicList(Istream& is) : List(is), - nextFree_(List::size()) + allocSize_(List::size()) {} @@ -44,9 +44,6 @@ Foam::Ostream& Foam::operator<< const Foam::DynamicList& DL ) { - const_cast&>(DL) - .setSize(DL.nextFree_); - os << static_cast&>(DL); return os; } @@ -60,7 +57,7 @@ Foam::Istream& Foam::operator>> ) { is >> static_cast&>(DL); - DL.nextFree_ = DL.List::size(); + DL.allocSize_ = DL.List::size(); return is; } diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index a98be44fef..684d393745 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -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; + // 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&); - //- 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 to the number of elements used inline DynamicList& 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&); + inline void transfer(List&); //- Transfer the contents of the argument DynamicList into this // DynamicList and annull the argument list. - void transfer(DynamicList&); + inline void transfer(DynamicList&); // Member Operators @@ -152,9 +159,15 @@ public: //- Assignment of all entries to the given value inline void operator=(const T&); - //- Assignment to List + //- Assignment from List inline void operator=(const List&); + //- Assignment from DynamicList + inline void operator= + ( + const DynamicList& + ); + // IOstream operators diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 8d451ccd7a..d9a14a1111 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -31,8 +31,10 @@ template inline Foam::DynamicList::DynamicList() : List(SizeInc), - nextFree_(0) -{} + allocSize_(SizeInc) +{ + List::size() = 0; +} //- Construct given size @@ -43,8 +45,10 @@ inline Foam::DynamicList::DynamicList ) : List(s), - nextFree_(0) -{} + allocSize_(s) +{ + List::size() = 0; +} //- Construct given size @@ -55,17 +59,17 @@ inline Foam::DynamicList::DynamicList ) : List(s), - nextFree_(s.size()) + allocSize_(s.size()) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -inline Foam::label Foam::DynamicList::size() +inline Foam::label Foam::DynamicList::allocSize() const { - return nextFree_; + return allocSize_; } @@ -75,13 +79,14 @@ inline void Foam::DynamicList::setSize const label s ) { - if (s < nextFree_) + if (s < List::size()) { - nextFree_ = s; + List::size() = s; } else { - List::setSize(s); + allocSize_ = s; + List::setSize(allocSize_); } } @@ -93,14 +98,14 @@ inline void Foam::DynamicList::setSize const T& t ) { - if (s < nextFree_) + if (s < List::size()) { - nextFree_ = s; + List::size() = s; } else { - List::setSize(s, t); - nextFree_ = s; + allocSize_ = s; + List::setSize(allocSize_, t); } } @@ -108,7 +113,16 @@ inline void Foam::DynamicList::setSize template inline void Foam::DynamicList::clear() { - nextFree_ = 0; + List::size() = 0; +} + + +template +inline void Foam::DynamicList::clearStorage() +{ + List::size() = allocSize_; // make List consistent + List::clear(); + allocSize_ = 0; } @@ -116,7 +130,8 @@ template inline Foam::DynamicList& Foam::DynamicList::shrink() { - List::setSize(nextFree_); + allocSize_ = List::size(); + List::setSize(allocSize_); return *this; } @@ -125,20 +140,20 @@ template inline void Foam::DynamicList::transfer(List& l) { - if (l.size() < nextFree_) + if (l.size() < List::size()) { FatalErrorIn ( "void DynamicList::transfer(List&)" ) << "Cannot replace the underlying storage of this DynamicList" - << " of which " << nextFree_ << " elements are used" << nl + << " of which " << List::size() << " elements are used" << nl << "with a List of size " << l.size() << abort(FatalError); } else { + allocSize_ = l.size(); List::transfer(l); // take over storage - l.clear(); // set nextFree of l to 0 } } @@ -150,40 +165,40 @@ Foam::DynamicList::transfer DynamicList& l ) { + allocSize_ = l.allocSize(); List::transfer(l); // take over storage - nextFree_ = l.size(); // take over used size - l.clear(); // set nextFree of l to 0 + l.allocSize_ = 0; } template -inline void Foam::DynamicList::append -( - const T& e -) +inline void Foam::DynamicList::append(const T& e) { - nextFree_++; + // Work on copy free index since gets overwritten by setSize + label nextFree = List::size(); - if (nextFree_ > List::size()) + nextFree++; + + if (nextFree > allocSize_) { - List::setSize + allocSize_ = max ( - max - ( - nextFree_, - label(SizeMult*List::size()/SizeDiv + SizeInc) - ) + nextFree, + label(SizeMult*allocSize_/SizeDiv + SizeInc) ); + List::setSize(allocSize_); } - this->operator[](nextFree_ - 1) = e; + this->operator[](nextFree - 1) = e; + + List::size() = nextFree; } template inline T Foam::DynamicList::remove() { - if (nextFree_ == 0) + if (List::size() == 0) { FatalErrorIn ( @@ -191,7 +206,7 @@ inline T Foam::DynamicList::remove() ) << "List is empty" << abort(FatalError); } - return List::operator[](--nextFree_); + return List::operator[](--List::size()); } @@ -203,20 +218,22 @@ inline T& Foam::DynamicList::operator() const label i ) { - nextFree_ = max(nextFree_, i + 1); + label nextFree = List::size(); - if (nextFree_ > List::size()) + nextFree = max(nextFree, i + 1); + + if (nextFree > allocSize_) { - List::setSize + allocSize_ = max ( - max - ( - nextFree_, - label(SizeMult*List::size()/SizeDiv + SizeInc) - ) + nextFree, + label(SizeMult*allocSize_/SizeDiv + SizeInc) ); + List::setSize(allocSize_); } + List::size() = nextFree; + return this->operator[](i); } @@ -228,7 +245,7 @@ inline void Foam::DynamicList::operator= ) { List::operator=(t); - nextFree_ = List::size(); + allocSize_ = List::size(); } @@ -239,7 +256,18 @@ inline void Foam::DynamicList::operator= ) { List::operator=(l); - nextFree_ = l.size(); + allocSize_ = List::size(); +} + + +template +inline void Foam::DynamicList::operator= +( + const DynamicList& l +) +{ + List::operator=(l); + allocSize_ = l.allocSize(); } diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 249d1fcf2b..21cc042050 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -420,6 +420,23 @@ void List::transfer(List& a) } +// Transfer the contents of the argument DynamicList into this List +// and anull the argument list +template +template +void List::transfer(DynamicList& 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 void sort(List& a) { diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 3ee814a0f6..7269159ef7 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -61,6 +61,8 @@ template Istream& operator>>(Istream&, List&); template class FixedList; template class PtrList; template class SLList; +template + class DynamicList; template class IndirectList; template class BiIndirectList; @@ -156,6 +158,11 @@ public: // and annull the argument list. void transfer(List&); + //- Transfer the contents of the argument List into this List + // and annull the argument list. + template + void transfer(DynamicList&); + //- Return subscript-checked element of UList. inline T& newElmt(const label); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H index 9cb2e6a29b..5ca70825cc 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H @@ -221,7 +221,7 @@ inline void PackedList::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); } diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C index df8d61fa21..8fdee370a0 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalMeshData.C @@ -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) { diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtraSearch.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtraSearch.C index 453cdd63c9..ffad4f005f 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtraSearch.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatchExtra/PrimitivePatchExtraSearch.C @@ -102,8 +102,9 @@ void Foam::PrimitivePatchExtra::markZone break; } - changedFaces.transfer(newChangedFaces.shrink()); - newChangedFaces.clear(); + // New dynamiclist: can leave dynamicList unshrunk + //changedFaces.transfer(newChangedFaces.shrink()); + changedFaces.transfer(newChangedFaces); } } diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C index b60b366079..b64eda7266 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshEdges.C @@ -441,11 +441,10 @@ void primitiveMesh::calcEdges(const bool doFaceEdges) const forAll(pe, pointI) { DynamicList