DynamicList changes.

- setSize() adjusts the addressable length only.
  Changed setSize(label) usage to setCapacity(label) or reserve(label)
  throughout. The final name (capacity vs. storageSize() vs. whatever) can
  easily be decided at a later date.
- added setSize(label, const T&), which may still not be really useful, but
  is at least now meaningful
- made shrink() a bit more legible.
- added append(UList<T>&)
- copying from a UList avoids reallocations where possible

The following bits of code continue to use the DynamicList::setSize(), but
appear to be legitimate (or the corresponding code itself needs rethinking).

  src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointCells.C:167: error: within this context
  src/OpenFOAM/lnInclude/faceTemplates.C:44: error: within this context
  src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.C:178: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:737: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:741: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:745: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:749: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:754: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:935: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:940: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:1041: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:1046: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:2161: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:2162: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:2201: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:2205: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:2261: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:2262: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:2263: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:2264: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:2265: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:3011: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:3076: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:3244: error: within this context
  src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C:3371: error: within this context
  src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C:73: error: within this context
  src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C:91: error: within this context
  src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C:73: error: within this context
  src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C:91: error: within this context
This commit is contained in:
Mark Olesen
2008-11-24 17:22:37 +01:00
parent b7e349a727
commit 41bbcb6337
25 changed files with 263 additions and 237 deletions

View File

@ -43,11 +43,11 @@ int main(int argc, char *argv[])
ldl[0](3) = 3; ldl[0](3) = 3;
ldl[0](1) = 1; ldl[0](1) = 1;
ldl[0].allocSize(5); // increase allocated size ldl[0].setCapacity(5); // increase allocated size
ldl[1].allocSize(10); // increase allocated size ldl[1].setCapacity(10); // increase allocated size
ldl[0].reserve(15); // should increase allocated size ldl[0].reserve(15); // should increase allocated size
ldl[1].reserve(5); // should not decrease allocated size ldl[1].reserve(5); // should not decrease allocated size
ldl[1](3) = 2; // allocates space and sets value ldl[1](3) = 2; // allocates space and sets value
// this works without a segfault, but doesn't change the list size // this works without a segfault, but doesn't change the list size
ldl[0][4] = 4; ldl[0][4] = 4;
@ -57,7 +57,7 @@ int main(int argc, char *argv[])
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: "; Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
forAll(ldl, i) forAll(ldl, i)
{ {
Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize(); Info<< " " << ldl[i].size() << "/" << ldl[i].capacity();
} }
Info<< endl; Info<< endl;
@ -68,7 +68,7 @@ int main(int argc, char *argv[])
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: "; Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
forAll(ldl, i) forAll(ldl, i)
{ {
Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize(); Info<< " " << ldl[i].size() << "/" << ldl[i].capacity();
} }
Info<< endl; Info<< endl;
@ -83,10 +83,10 @@ int main(int argc, char *argv[])
{ {
dlA.append(i); dlA.append(i);
} }
dlA.allocSize(10); dlA.setCapacity(10);
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: " Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.allocSize() << endl; << " " << dlA.size() << "/" << dlA.capacity() << endl;
dlB.transfer(dlA); dlB.transfer(dlA);
@ -96,9 +96,9 @@ int main(int argc, char *argv[])
Info<< "Transferred to dlB" << endl; Info<< "Transferred to dlB" << endl;
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: " Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.allocSize() << endl; << " " << dlA.size() << "/" << dlA.capacity() << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: " Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.allocSize() << endl; << " " << dlB.size() << "/" << dlB.capacity() << endl;
// try with a normal list: // try with a normal list:
List<label> lstA; List<label> lstA;
@ -107,7 +107,34 @@ int main(int argc, char *argv[])
Info<< "<lstA>" << lstA << "</lstA>" << nl << "sizes: " Info<< "<lstA>" << lstA << "</lstA>" << nl << "sizes: "
<< " " << lstA.size() << endl; << " " << lstA.size() << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: " Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.allocSize() << endl; << " " << dlB.size() << "/" << dlB.capacity() << endl;
// Copy back and append a few time
for (label i=0; i < 3; i++)
{
dlB.append(lstA);
}
Info<< "appended list a few times" << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.capacity() << endl;
// assign the list (should maintain allocated space)
dlB = lstA;
Info<< "assigned list" << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.capacity() << endl;
// dlB.append(dlB);
// Info<< "appended to itself:" << endl;
// Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
// << " " << dlB.size() << "/" << dlB.capacity() << endl;
// dlB = dlB;
// Info<< "self assignment:" << endl;
// Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
// << " " << dlB.size() << "/" << dlB.capacity() << endl;
return 0; return 0;
} }

View File

@ -108,13 +108,13 @@ int main(int argc, char *argv[])
face f1(dl); face f1(dl);
face f2(xferCopy<labelList>(dl)); face f2(xferCopy<labelList>(dl));
Info<< "dl[" << dl.size() << "/" << dl.allocSize() << "] " << dl << endl; Info<< "dl[" << dl.size() << "/" << dl.capacity() << "] " << dl << endl;
Info<< "f1: " << f1 << endl; Info<< "f1: " << f1 << endl;
Info<< "f2: " << f2 << endl; Info<< "f2: " << f2 << endl;
// note: using xferMoveTo to ensure the correct transfer() method is called // note: using xferMoveTo to ensure the correct transfer() method is called
face f3( xferMoveTo<labelList>(dl) ); face f3( xferMoveTo<labelList>(dl) );
Info<< "dl[" << dl.size() << "/" << dl.allocSize() << "] " << dl << endl; Info<< "dl[" << dl.size() << "/" << dl.capacity() << "] " << dl << endl;
Info<< "f3: " << f3 << endl; Info<< "f3: " << f3 << endl;
return 0; return 0;

View File

@ -144,7 +144,7 @@ Foam::mergePolyMesh::mergePolyMesh(const IOobject& io)
wordList curPointZoneNames = pointZones().names(); wordList curPointZoneNames = pointZones().names();
if (curPointZoneNames.size() > 0) if (curPointZoneNames.size() > 0)
{ {
pointZoneNames_.setSize(2*curPointZoneNames.size()); pointZoneNames_.setCapacity(2*curPointZoneNames.size());
} }
forAll (curPointZoneNames, zoneI) forAll (curPointZoneNames, zoneI)
@ -157,7 +157,7 @@ Foam::mergePolyMesh::mergePolyMesh(const IOobject& io)
if (curFaceZoneNames.size() > 0) if (curFaceZoneNames.size() > 0)
{ {
faceZoneNames_.setSize(2*curFaceZoneNames.size()); faceZoneNames_.setCapacity(2*curFaceZoneNames.size());
} }
forAll (curFaceZoneNames, zoneI) forAll (curFaceZoneNames, zoneI)
{ {
@ -169,7 +169,7 @@ Foam::mergePolyMesh::mergePolyMesh(const IOobject& io)
if (curCellZoneNames.size() > 0) if (curCellZoneNames.size() > 0)
{ {
cellZoneNames_.setSize(2*curCellZoneNames.size()); cellZoneNames_.setCapacity(2*curCellZoneNames.size());
} }
forAll (curCellZoneNames, zoneI) forAll (curCellZoneNames, zoneI)
{ {

View File

@ -354,7 +354,7 @@ bool domainDecomposition::writeDecomposition()
// Estimate size // Estimate size
forAll(zonePoints, zoneI) forAll(zonePoints, zoneI)
{ {
zonePoints[zoneI].setSize(pz[zoneI].size() / nProcs_); zonePoints[zoneI].setCapacity(pz[zoneI].size() / nProcs_);
} }
// Use the pointToZone map to find out the single zone (if any), // Use the pointToZone map to find out the single zone (if any),
@ -423,8 +423,8 @@ bool domainDecomposition::writeDecomposition()
{ {
label procSize = fz[zoneI].size() / nProcs_; label procSize = fz[zoneI].size() / nProcs_;
zoneFaces[zoneI].setSize(procSize); zoneFaces[zoneI].setCapacity(procSize);
zoneFaceFlips[zoneI].setSize(procSize); zoneFaceFlips[zoneI].setCapacity(procSize);
} }
// Go through all the zoned faces and find out if they // Go through all the zoned faces and find out if they
@ -514,7 +514,7 @@ bool domainDecomposition::writeDecomposition()
// Estimate size // Estimate size
forAll(zoneCells, zoneI) forAll(zoneCells, zoneI)
{ {
zoneCells[zoneI].setSize(cz[zoneI].size() / nProcs_); zoneCells[zoneI].setCapacity(cz[zoneI].size() / nProcs_);
} }
forAll (curCellLabels, celli) forAll (curCellLabels, celli)

View File

@ -40,11 +40,11 @@ Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList(Istream& is)
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Foam::Ostream& Foam::operator<< Foam::Ostream& Foam::operator<<
( (
Foam::Ostream& os, Ostream& os,
const Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>& DL const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
) )
{ {
os << static_cast<const List<T>&>(DL); os << static_cast<const List<T>&>(lst);
return os; return os;
} }
@ -52,12 +52,12 @@ Foam::Ostream& Foam::operator<<
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Foam::Istream& Foam::operator>> Foam::Istream& Foam::operator>>
( (
Foam::Istream& is, Istream& is,
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>& DL DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
) )
{ {
is >> static_cast<List<T>&>(DL); is >> static_cast<List<T>&>(lst);
DL.allocSize_ = DL.List<T>::size(); lst.allocSize_ = lst.List<T>::size();
return is; return is;
} }

View File

@ -86,9 +86,6 @@ class DynamicList
// Private Member Functions // Private Member Functions
// Disabled, since the usefulness and semantics are not quite clear
void setSize(const label, const T&);
public: public:
// Related types // Related types
@ -116,29 +113,27 @@ public:
// Access // Access
//- Size of the underlying storage. //- Size of the underlying storage.
inline label allocSize() const; inline label capacity() const;
// Edit // Edit
//- Alter the size of the underlying storage. //- Alter the size of the underlying storage.
// The addressed size will be truncated if needed to fit, but will // The addressed size will be truncated if needed to fit, but will
// otherwise remain untouched. // remain otherwise untouched.
inline void allocSize(const label); // Use this or reserve() in combination with append().
inline void setCapacity(const label);
// CURRENT BEHAVIOUR
//- When the new size is greater than the addressed list size, the
// allocated list sizes is adjusted and the
// addressed size does not change.
// Otherwise the addressed list size is just reduced and the
// allocated size does not change.
//
// PROPOSED BEHAVIOUR
//- Alter the addressed list size. //- Alter the addressed list size.
// New space will be allocated if required. // New space will be allocated if required.
// Use this to resize the list prior to using the operator[] for
// setting values (as per List usage).
inline void setSize(const label); inline void setSize(const label);
//- Alter the addressed list size and fill new space with a constant.
inline void setSize(const label, const T&);
//- Reserve allocation space for at least this size. //- Reserve allocation space for at least this size.
// Never shrinks the allocated size, use allocSize() for that. // Never shrinks the allocated size, use setCapacity() for that.
inline void reserve(const label); inline void reserve(const label);
//- Clear the addressed list, i.e. set the size to zero. //- Clear the addressed list, i.e. set the size to zero.
@ -164,6 +159,9 @@ public:
//- Append an element at the end of the list //- Append an element at the end of the list
inline void append(const T& e); inline void append(const T& e);
//- Append a List at the end of this list
inline void append(const UList<T>&);
//- Remove and return the top element //- Remove and return the top element
inline T remove(); inline T remove();
@ -174,7 +172,7 @@ public:
inline void operator=(const T&); inline void operator=(const T&);
//- Assignment from List<T>. Also handles assignment from DynamicList. //- Assignment from List<T>. Also handles assignment from DynamicList.
inline void operator=(const List<T>&); inline void operator=(const UList<T>&);
// IOstream operators // IOstream operators

View File

@ -63,7 +63,7 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::label Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::allocSize() inline Foam::label Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::capacity()
const const
{ {
return allocSize_; return allocSize_;
@ -71,7 +71,7 @@ const
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::allocSize inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setCapacity
( (
const label s const label s
) )
@ -79,13 +79,12 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::allocSize
label nextFree = List<T>::size(); label nextFree = List<T>::size();
allocSize_ = s; allocSize_ = s;
// truncate addressed size too?
if (nextFree > allocSize_) if (nextFree > allocSize_)
{ {
// truncate both allocated and addressed sizes
nextFree = allocSize_; nextFree = allocSize_;
} }
// adjust allocated size, and addressed size if necessary
List<T>::setSize(allocSize_); List<T>::setSize(allocSize_);
List<T>::size(nextFree); List<T>::size(nextFree);
} }
@ -102,7 +101,7 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::reserve
allocSize_ = max allocSize_ = max
( (
s, s,
label(SizeMult*allocSize_/SizeDiv + SizeInc) label(SizeInc + allocSize_ * SizeMult / SizeDiv)
); );
// adjust allocated size, leave addressed size untouched // adjust allocated size, leave addressed size untouched
@ -119,33 +118,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
const label s const label s
) )
{ {
#if 1
// CURRENT BEHAVIOUR:
// slightly ambiguous about what size the list will actually get
// cannot increase the size of the addressed list (for compatibility
// with List), without automatically adjusting the allocated space!
label nextFree = List<T>::size();
if (s <= nextFree)
{
// adjust addressed size, leave allocated size untouched
nextFree = s;
}
else
{
// adjust allocated size, leave addressed size untouched
allocSize_ = s;
List<T>::setSize(allocSize_);
}
List<T>::size(nextFree);
#else
// allocate more space? // allocate more space?
if (s > allocSize_) if (s > allocSize_)
{ {
allocSize_ = max allocSize_ = max
( (
s, s,
label(SizeMult*allocSize_/SizeDiv + SizeInc) label(SizeInc + allocSize_ * SizeMult / SizeDiv)
); );
List<T>::setSize(allocSize_); List<T>::setSize(allocSize_);
@ -153,7 +132,24 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
// adjust addressed size // adjust addressed size
List<T>::size(s); List<T>::size(s);
#endif }
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::setSize
(
const label s,
const T& t
)
{
label nextFree = List<T>::size();
setSize(s);
// set new elements to constant value
while (nextFree < s)
{
this->operator[](nextFree++) = t;
}
} }
@ -176,13 +172,15 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>& inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>&
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::shrink() Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::shrink()
{ {
if (allocSize_ > List<T>::size()) label nextFree = List<T>::size();
if (allocSize_ > nextFree)
{ {
allocSize_ = List<T>::size(); // use the full list when resizing
// force re-allocation/copying in List<T>::setSize() by temporarily List<T>::size(allocSize_);
// faking a larger list size that will be truncated // the new size
List<T>::size(allocSize_+1); allocSize_ = nextFree;
List<T>::setSize(allocSize_); List<T>::setSize(allocSize_);
List<T>::size(nextFree);
} }
return *this; return *this;
} }
@ -213,9 +211,12 @@ Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 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
)
{ {
// Work on copy free index since gets overwritten by setSize // Work on copy free index since the size gets overwritten by setSize
label nextFree = List<T>::size(); label nextFree = List<T>::size();
reserve(nextFree+1); reserve(nextFree+1);
@ -225,6 +226,32 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append(const T& e)
} }
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
(
const UList<T>& lst
)
{
label nextFree = List<T>::size();
if (this == &lst)
{
FatalErrorIn
(
"DynamicList<T, SizeInc, SizeMult, SizeDiv>::append(UList<T>&)"
) << "attempted appending to self" << abort(FatalError);
}
reserve(nextFree + lst.size());
List<T>::size(nextFree + lst.size());
forAll(lst, elemI)
{
this->operator[](nextFree++) = lst[elemI];
}
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline T Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::remove() inline T Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::remove()
{ {
@ -270,21 +297,38 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
const T& t const T& t
) )
{ {
List<T>::operator=(t); UList<T>::operator=(t);
} }
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator= inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
( (
const List<T>& lst const UList<T>& lst
) )
{ {
// make the entire storage available for the copy operation: if (this == &lst)
List<T>::size(allocSize_); {
FatalErrorIn
(
"DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=(UList<T>&)"
) << "attempted assignment to self" << abort(FatalError);
}
List<T>::operator=(lst); if (allocSize_ >= lst.size())
allocSize_ = List<T>::size(); {
// can copy without reallocation, match sizes to avoid reallocation
List<T>::size(lst.size());
List<T>::operator=(lst);
}
else
{
// make the entire storage available for the copy operation
List<T>::size(allocSize_);
List<T>::operator=(lst);
allocSize_ = List<T>::size();
}
} }

View File

@ -50,14 +50,14 @@ inline Foam::UList<T>::UList(T* __restrict__ v, label size)
template<class T> template<class T>
inline Foam::label Foam::UList<T>::fcIndex(const label i) const inline Foam::label Foam::UList<T>::fcIndex(const label i) const
{ {
return (i == size()-1 ? 0 : i+1); return (i == size()-1 ? 0 : i+1);
} }
template<class T> template<class T>
inline Foam::label Foam::UList<T>::rcIndex(const label i) const inline Foam::label Foam::UList<T>::rcIndex(const label i) const
{ {
return (i == 0 ? size()-1 : i-1); return (i == 0 ? size()-1 : i-1);
} }

View File

@ -45,7 +45,7 @@ void Foam::UList<T>::writeEntry(Ostream& os) const
{ {
os << word("List<" + word(pTraits<T>::typeName) + '>') << " "; os << word("List<" + word(pTraits<T>::typeName) + '>') << " ";
} }
os << *this; os << *this;
} }

View File

@ -40,8 +40,8 @@ Foam::label Foam::face::triangles
label quadI = 0; label quadI = 0;
faceList quadFaces; faceList quadFaces;
// adjusts the addressable size (and allocate space if needed) // adjust the addressable size (and allocate space if needed)
triFaces(triI + nTriangles()); triFaces.setSize(triI + nTriangles());
return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces); return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces);
} }

View File

@ -27,14 +27,9 @@ License
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "ListOps.H" #include "ListOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const labelListList& primitiveMesh::cellPoints() const const Foam::labelListList& Foam::primitiveMesh::cellPoints() const
{ {
if (!cpPtr_) if (!cpPtr_)
{ {
@ -56,12 +51,12 @@ const labelListList& primitiveMesh::cellPoints() const
cpPtr_ = new labelListList(nCells()); cpPtr_ = new labelListList(nCells());
invertManyToMany(nCells(), pointCells(), *cpPtr_); invertManyToMany(nCells(), pointCells(), *cpPtr_);
} }
return *cpPtr_; return *cpPtr_;
} }
const labelList& primitiveMesh::cellPoints const Foam::labelList& Foam::primitiveMesh::cellPoints
( (
const label cellI, const label cellI,
DynamicList<label>& storage DynamicList<label>& storage
@ -84,14 +79,14 @@ const labelList& primitiveMesh::cellPoints
forAll(f, fp) forAll(f, fp)
{ {
labelSet_.insert(f[fp]); labelSet_.insert(f[fp]);
} }
} }
storage.clear(); storage.clear();
if (labelSet_.size() > storage.allocSize()) if (labelSet_.size() > storage.capacity())
{ {
storage.setSize(labelSet_.size()); storage.setCapacity(labelSet_.size());
} }
forAllConstIter(labelHashSet, labelSet_, iter) forAllConstIter(labelHashSet, labelSet_, iter)
@ -104,7 +99,7 @@ const labelList& primitiveMesh::cellPoints
} }
const labelList& primitiveMesh::cellPoints(const label cellI) const const Foam::labelList& Foam::primitiveMesh::cellPoints(const label cellI) const
{ {
return cellPoints(cellI, labels_); return cellPoints(cellI, labels_);
} }
@ -112,6 +107,4 @@ const labelList& primitiveMesh::cellPoints(const label cellI) const
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -30,15 +30,10 @@ License
#include "SortableList.H" #include "SortableList.H"
#include "ListOps.H" #include "ListOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Returns edgeI between two points. // Returns edgeI between two points.
Foam::label primitiveMesh::getEdge Foam::label Foam::primitiveMesh::getEdge
( (
List<DynamicList<label> >& pe, List<DynamicList<label> >& pe,
DynamicList<edge>& es, DynamicList<edge>& es,
@ -76,7 +71,7 @@ Foam::label primitiveMesh::getEdge
} }
void primitiveMesh::calcEdges(const bool doFaceEdges) const void Foam::primitiveMesh::calcEdges(const bool doFaceEdges) const
{ {
if (debug) if (debug)
{ {
@ -113,7 +108,7 @@ void primitiveMesh::calcEdges(const bool doFaceEdges) const
List<DynamicList<label> > pe(nPoints()); List<DynamicList<label> > pe(nPoints());
forAll(pe, pointI) forAll(pe, pointI)
{ {
pe[pointI].setSize(primitiveMesh::edgesPerPoint_); pe[pointI].setCapacity(primitiveMesh::edgesPerPoint_);
} }
// Estimate edges storage // Estimate edges storage
@ -337,7 +332,7 @@ void primitiveMesh::calcEdges(const bool doFaceEdges) const
oldToNew[edgeI] = internal0EdgeI++; oldToNew[edgeI] = internal0EdgeI++;
} }
} }
} }
else else
{ {
@ -460,8 +455,8 @@ void primitiveMesh::calcEdges(const bool doFaceEdges) const
} }
label primitiveMesh::findFirstCommonElementFromSortedLists Foam::label Foam::primitiveMesh::findFirstCommonElementFromSortedLists
( (
const labelList& list1, const labelList& list1,
const labelList& list2 const labelList& list2
) )
@ -494,7 +489,7 @@ label primitiveMesh::findFirstCommonElementFromSortedLists
"primitiveMesh::findFirstCommonElementFromSortedLists" "primitiveMesh::findFirstCommonElementFromSortedLists"
"(const labelList&, const labelList&)" "(const labelList&, const labelList&)"
) << "No common elements in lists " << list1 << " and " << list2 ) << "No common elements in lists " << list1 << " and " << list2
<< abort(FatalError); << abort(FatalError);
} }
return result; return result;
} }
@ -502,7 +497,7 @@ label primitiveMesh::findFirstCommonElementFromSortedLists
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const edgeList& primitiveMesh::edges() const const Foam::edgeList& Foam::primitiveMesh::edges() const
{ {
if (!edgesPtr_) if (!edgesPtr_)
{ {
@ -513,7 +508,7 @@ const edgeList& primitiveMesh::edges() const
return *edgesPtr_; return *edgesPtr_;
} }
const labelListList& primitiveMesh::pointEdges() const const Foam::labelListList& Foam::primitiveMesh::pointEdges() const
{ {
if (!pePtr_) if (!pePtr_)
{ {
@ -525,7 +520,7 @@ const labelListList& primitiveMesh::pointEdges() const
} }
const labelListList& primitiveMesh::faceEdges() const const Foam::labelListList& Foam::primitiveMesh::faceEdges() const
{ {
if (!fePtr_) if (!fePtr_)
{ {
@ -576,7 +571,7 @@ const labelListList& primitiveMesh::faceEdges() const
} }
void primitiveMesh::clearOutEdges() void Foam::primitiveMesh::clearOutEdges()
{ {
deleteDemandDrivenData(edgesPtr_); deleteDemandDrivenData(edgesPtr_);
deleteDemandDrivenData(pePtr_); deleteDemandDrivenData(pePtr_);
@ -586,7 +581,7 @@ void primitiveMesh::clearOutEdges()
} }
const labelList& primitiveMesh::faceEdges const Foam::labelList& Foam::primitiveMesh::faceEdges
( (
const label faceI, const label faceI,
DynamicList<label>& storage DynamicList<label>& storage
@ -602,9 +597,9 @@ const labelList& primitiveMesh::faceEdges
const face& f = faces()[faceI]; const face& f = faces()[faceI];
storage.clear(); storage.clear();
if (f.size() > storage.allocSize()) if (f.size() > storage.capacity())
{ {
storage.setSize(f.size()); storage.setCapacity(f.size());
} }
forAll(f, fp) forAll(f, fp)
@ -624,13 +619,13 @@ const labelList& primitiveMesh::faceEdges
} }
const labelList& primitiveMesh::faceEdges(const label faceI) const const Foam::labelList& Foam::primitiveMesh::faceEdges(const label faceI) const
{ {
return faceEdges(faceI, labels_); return faceEdges(faceI, labels_);
} }
const labelList& primitiveMesh::cellEdges const Foam::labelList& Foam::primitiveMesh::cellEdges
( (
const label cellI, const label cellI,
DynamicList<label>& storage DynamicList<label>& storage
@ -652,15 +647,15 @@ const labelList& primitiveMesh::cellEdges
forAll(fe, feI) forAll(fe, feI)
{ {
labelSet_.insert(fe[feI]); labelSet_.insert(fe[feI]);
} }
} }
storage.clear(); storage.clear();
if (labelSet_.size() > storage.allocSize()) if (labelSet_.size() > storage.capacity())
{ {
storage.setSize(labelSet_.size()); storage.setCapacity(labelSet_.size());
} }
forAllConstIter(labelHashSet, labelSet_, iter) forAllConstIter(labelHashSet, labelSet_, iter)
@ -673,7 +668,7 @@ const labelList& primitiveMesh::cellEdges
} }
const labelList& primitiveMesh::cellEdges(const label cellI) const const Foam::labelList& Foam::primitiveMesh::cellEdges(const label cellI) const
{ {
return cellEdges(cellI, labels_);; return cellEdges(cellI, labels_);;
} }
@ -681,6 +676,4 @@ const labelList& primitiveMesh::cellEdges(const label cellI) const
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -27,14 +27,9 @@ License
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "cell.H" #include "cell.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void primitiveMesh::calcPointCells() const void Foam::primitiveMesh::calcPointCells() const
{ {
// Loop through cells and mark up points // Loop through cells and mark up points
@ -111,7 +106,7 @@ void primitiveMesh::calcPointCells() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const labelListList& primitiveMesh::pointCells() const const Foam::labelListList& Foam::primitiveMesh::pointCells() const
{ {
if (!pcPtr_) if (!pcPtr_)
{ {
@ -122,7 +117,7 @@ const labelListList& primitiveMesh::pointCells() const
} }
const labelList& primitiveMesh::pointCells const Foam::labelList& Foam::primitiveMesh::pointCells
( (
const label pointI, const label pointI,
DynamicList<label>& storage DynamicList<label>& storage
@ -155,26 +150,29 @@ const labelList& primitiveMesh::pointCells
} }
// Filter duplicates // Filter duplicates
sort(storage); if (storage.size() > 1)
label n = 1;
for (label i = 1; i < storage.size(); i++)
{ {
if (storage[i] != storage[i-1]) sort(storage);
{
storage[n++] = storage[i];
}
}
storage.setSize(n); label n = 1;
for (label i = 1; i < storage.size(); i++)
{
if (storage[i-1] != storage[i])
{
storage[n++] = storage[i];
}
}
// truncate addressed list
storage.setSize(n);
}
return storage; return storage;
} }
} }
const labelList& primitiveMesh::pointCells(const label pointI) const const Foam::labelList& Foam::primitiveMesh::pointCells(const label pointI) const
{ {
return pointCells(pointI, labels_); return pointCells(pointI, labels_);
} }
@ -182,6 +180,4 @@ const labelList& primitiveMesh::pointCells(const label pointI) const
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -26,14 +26,9 @@ License
#include "primitiveMesh.H" #include "primitiveMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void primitiveMesh::calcPointPoints() const void Foam::primitiveMesh::calcPointPoints() const
{ {
if (debug) if (debug)
{ {
@ -94,7 +89,7 @@ void primitiveMesh::calcPointPoints() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const labelListList& primitiveMesh::pointPoints() const const Foam::labelListList& Foam::primitiveMesh::pointPoints() const
{ {
if (!ppPtr_) if (!ppPtr_)
{ {
@ -105,7 +100,7 @@ const labelListList& primitiveMesh::pointPoints() const
} }
const labelList& primitiveMesh::pointPoints const Foam::labelList& Foam::primitiveMesh::pointPoints
( (
const label pointI, const label pointI,
DynamicList<label>& storage DynamicList<label>& storage
@ -122,9 +117,9 @@ const labelList& primitiveMesh::pointPoints
storage.clear(); storage.clear();
if (pEdges.size() > storage.allocSize()) if (pEdges.size() > storage.capacity())
{ {
storage.setSize(pEdges.size()); storage.setCapacity(pEdges.size());
} }
forAll(pEdges, i) forAll(pEdges, i)
@ -137,7 +132,10 @@ const labelList& primitiveMesh::pointPoints
} }
const labelList& primitiveMesh::pointPoints(const label pointI) const const Foam::labelList& Foam::primitiveMesh::pointPoints
(
const label pointI
) const
{ {
return pointPoints(pointI, labels_); return pointPoints(pointI, labels_);
} }
@ -145,6 +143,4 @@ const labelList& primitiveMesh::pointPoints(const label pointI) const
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -236,13 +236,13 @@ Foam::labelList Foam::polyDualMesh::collectPatchSideFace
if (pointToDualPoint[meshPointI] >= 0) if (pointToDualPoint[meshPointI] >= 0)
{ {
// Number of pFaces + 2 boundary edge + feature point // Number of pFaces + 2 boundary edge + feature point
dualFace.setSize(pFaces.size()+2+1); dualFace.setCapacity(pFaces.size()+2+1);
// Store dualVertex for feature edge // Store dualVertex for feature edge
dualFace.append(pointToDualPoint[meshPointI]); dualFace.append(pointToDualPoint[meshPointI]);
} }
else else
{ {
dualFace.setSize(pFaces.size()+2); dualFace.setCapacity(pFaces.size()+2);
} }
// Store dual vertex for starting edge. // Store dual vertex for starting edge.
@ -958,13 +958,13 @@ void Foam::polyDualMesh::calcDual
if (edgeToDualPoint[edgeI] >= 0) if (edgeToDualPoint[edgeI] >= 0)
{ {
// Number of cells + 2 boundary faces + feature edge point // Number of cells + 2 boundary faces + feature edge point
dualFace.setSize(mesh.edgeCells()[edgeI].size()+2+1); dualFace.setCapacity(mesh.edgeCells()[edgeI].size()+2+1);
// Store dualVertex for feature edge // Store dualVertex for feature edge
dualFace.append(edgeToDualPoint[edgeI]); dualFace.append(edgeToDualPoint[edgeI]);
} }
else else
{ {
dualFace.setSize(mesh.edgeCells()[edgeI].size()+2); dualFace.setCapacity(mesh.edgeCells()[edgeI].size()+2);
} }
// Store dual vertex for starting face. // Store dual vertex for starting face.

View File

@ -1250,7 +1250,7 @@ void Foam::boundaryMesh::patchify
forAll(patchFaces, newPatchI) forAll(patchFaces, newPatchI)
{ {
patchFaces[newPatchI].setSize(nAvgFaces); patchFaces[newPatchI].setCapacity(nAvgFaces);
} }
// //

View File

@ -37,16 +37,11 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(topoCellLooper, 0);
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // addToRunTimeSelectionTable(cellLooper, topoCellLooper, word);
defineTypeNameAndDebug(topoCellLooper, 0);
addToRunTimeSelectionTable(cellLooper, topoCellLooper, word);
} }
// Angle for polys to be considered splitHexes. // Angle for polys to be considered splitHexes.
@ -67,7 +62,7 @@ void Foam::topoCellLooper::subsetList
{ {
if (startI == 0) if (startI == 0)
{ {
// Truncate (setsize decides itself not to do anything if nothing // Truncate (setSize decides itself not to do anything if nothing
// changed) // changed)
if (freeI < 0) if (freeI < 0)
{ {
@ -228,7 +223,7 @@ Foam::labelList Foam::topoCellLooper::getSuperEdge
do do
{ {
vertI = mesh().edges()[edgeI].otherVertex(vertI); vertI = mesh().edges()[edgeI].otherVertex(vertI);
superVerts[superVertI++] = vertI; superVerts[superVertI++] = vertI;
@ -237,7 +232,7 @@ Foam::labelList Foam::topoCellLooper::getSuperEdge
edgeI = meshTools::otherEdge(mesh(), fEdges, edgeI, vertI); edgeI = meshTools::otherEdge(mesh(), fEdges, edgeI, vertI);
} }
while (!features.isFeaturePoint(prevEdgeI, edgeI)); while (!features.isFeaturePoint(prevEdgeI, edgeI));
superVerts.setSize(superVertI); superVerts.setSize(superVertI);
return superVerts; return superVerts;
@ -500,7 +495,7 @@ void Foam::topoCellLooper::walkSplitHex
nextEdgeI, nextEdgeI,
nextVertI nextVertI
); );
edgeI = nextEdgeI; edgeI = nextEdgeI;
vertI = nextVertI; vertI = nextVertI;
} }
@ -615,7 +610,7 @@ void Foam::topoCellLooper::walkSplitHex
labelList nextFaces = labelList nextFaces =
getVertFacesNonEdge getVertFacesNonEdge
( (
cellI, cellI,
edgeI, edgeI,
vertI vertI
); );
@ -720,7 +715,7 @@ bool Foam::topoCellLooper::cut
if (mesh().cellShapes()[cellI].model() == hex_) if (mesh().cellShapes()[cellI].model() == hex_)
{ {
// Let parent handle hex case. // Let parent handle hex case.
return return
hexCellLooper::cut hexCellLooper::cut
( (
refDir, refDir,
@ -752,7 +747,7 @@ bool Foam::topoCellLooper::cut
if (edgeI != -1) if (edgeI != -1)
{ {
// Found non-feature edge. Start walking from vertex on edge. // Found non-feature edge. Start walking from vertex on edge.
vertI = mesh().edges()[edgeI].start(); vertI = mesh().edges()[edgeI].start();
} }
else else

View File

@ -47,7 +47,7 @@ void Foam::polyMeshAdder::append
DynamicList<label>& dynLst DynamicList<label>& dynLst
) )
{ {
dynLst.setSize(dynLst.size() + lst.size()); dynLst.setCapacity(dynLst.size() + lst.size());
forAll(lst, i) forAll(lst, i)
{ {
@ -902,7 +902,7 @@ void Foam::polyMeshAdder::mergePointZones
List<DynamicList<label> >& pzPoints List<DynamicList<label> >& pzPoints
) )
{ {
zoneNames.setSize(pz0.size() + pz1.size()); zoneNames.setCapacity(pz0.size() + pz1.size());
// Names // Names
append(pz0.names(), zoneNames); append(pz0.names(), zoneNames);
@ -922,7 +922,7 @@ void Foam::polyMeshAdder::mergePointZones
{ {
DynamicList<label>& newZone = pzPoints[zoneI]; DynamicList<label>& newZone = pzPoints[zoneI];
newZone.setSize(pz0[zoneI].size()); newZone.setCapacity(pz0[zoneI].size());
append(from0ToAllPoints, pz0[zoneI], newZone); append(from0ToAllPoints, pz0[zoneI], newZone);
} }
@ -933,7 +933,7 @@ void Foam::polyMeshAdder::mergePointZones
// Relabel all points of zone and add to correct pzPoints. // Relabel all points of zone and add to correct pzPoints.
DynamicList<label>& newZone = pzPoints[from1ToAll[zoneI]]; DynamicList<label>& newZone = pzPoints[from1ToAll[zoneI]];
newZone.setSize(newZone.size() + pz1[zoneI].size()); newZone.setCapacity(newZone.size() + pz1[zoneI].size());
append(from1ToAllPoints, pz1[zoneI], newZone); append(from1ToAllPoints, pz1[zoneI], newZone);
} }
@ -958,7 +958,7 @@ void Foam::polyMeshAdder::mergeFaceZones
List<DynamicList<bool> >& fzFlips List<DynamicList<bool> >& fzFlips
) )
{ {
zoneNames.setSize(fz0.size() + fz1.size()); zoneNames.setCapacity(fz0.size() + fz1.size());
append(fz0.names(), zoneNames); append(fz0.names(), zoneNames);
@ -979,8 +979,8 @@ void Foam::polyMeshAdder::mergeFaceZones
DynamicList<label>& newZone = fzFaces[zoneI]; DynamicList<label>& newZone = fzFaces[zoneI];
DynamicList<bool>& newFlip = fzFlips[zoneI]; DynamicList<bool>& newFlip = fzFlips[zoneI];
newZone.setSize(fz0[zoneI].size()); newZone.setCapacity(fz0[zoneI].size());
newFlip.setSize(newZone.size()); newFlip.setCapacity(newZone.size());
const labelList& addressing = fz0[zoneI]; const labelList& addressing = fz0[zoneI];
const boolList& flipMap = fz0[zoneI].flipMap(); const boolList& flipMap = fz0[zoneI].flipMap();
@ -1003,8 +1003,8 @@ void Foam::polyMeshAdder::mergeFaceZones
DynamicList<label>& newZone = fzFaces[from1ToAll[zoneI]]; DynamicList<label>& newZone = fzFaces[from1ToAll[zoneI]];
DynamicList<bool>& newFlip = fzFlips[from1ToAll[zoneI]]; DynamicList<bool>& newFlip = fzFlips[from1ToAll[zoneI]];
newZone.setSize(newZone.size() + fz1[zoneI].size()); newZone.setCapacity(newZone.size() + fz1[zoneI].size());
newFlip.setSize(newZone.size()); newFlip.setCapacity(newZone.size());
const labelList& addressing = fz1[zoneI]; const labelList& addressing = fz1[zoneI];
const boolList& flipMap = fz1[zoneI].flipMap(); const boolList& flipMap = fz1[zoneI].flipMap();
@ -1040,7 +1040,7 @@ void Foam::polyMeshAdder::mergeCellZones
List<DynamicList<label> >& czCells List<DynamicList<label> >& czCells
) )
{ {
zoneNames.setSize(cz0.size() + cz1.size()); zoneNames.setCapacity(cz0.size() + cz1.size());
append(cz0.names(), zoneNames); append(cz0.names(), zoneNames);
@ -1056,7 +1056,7 @@ void Foam::polyMeshAdder::mergeCellZones
czCells.setSize(zoneNames.size()); czCells.setSize(zoneNames.size());
forAll(cz0, zoneI) forAll(cz0, zoneI)
{ {
czCells[zoneI].setSize(cz0[zoneI].size()); czCells[zoneI].setCapacity(cz0[zoneI].size());
// Insert mesh0 cells // Insert mesh0 cells
append(cz0[zoneI], czCells[zoneI]); append(cz0[zoneI], czCells[zoneI]);
} }
@ -1067,7 +1067,7 @@ void Foam::polyMeshAdder::mergeCellZones
{ {
DynamicList<label>& newZone = czCells[from1ToAll[zoneI]]; DynamicList<label>& newZone = czCells[from1ToAll[zoneI]];
newZone.setSize(newZone.size() + cz1[zoneI].size()); newZone.setCapacity(newZone.size() + cz1[zoneI].size());
append(from1ToAllCells, cz1[zoneI], newZone); append(from1ToAllCells, cz1[zoneI], newZone);
} }

View File

@ -31,7 +31,7 @@ License
template<class T> template<class T>
void Foam::polyMeshAdder::append(const List<T>& lst, DynamicList<T>& dynLst) void Foam::polyMeshAdder::append(const List<T>& lst, DynamicList<T>& dynLst)
{ {
dynLst.setSize(dynLst.size() + lst.size()); dynLst.setCapacity(dynLst.size() + lst.size());
forAll(lst, i) forAll(lst, i)
{ {

View File

@ -2432,8 +2432,8 @@ Foam::labelList Foam::hexRef8::consistentSlowRefinement
// Transfer into seedFaces, seedFacesInfo // Transfer into seedFaces, seedFacesInfo
seedFaces.setSize(changedFacesInfo.size()); seedFaces.setCapacity(changedFacesInfo.size());
seedFacesInfo.setSize(changedFacesInfo.size()); seedFacesInfo.setCapacity(changedFacesInfo.size());
forAllConstIter(Map<refinementData>, changedFacesInfo, iter) forAllConstIter(Map<refinementData>, changedFacesInfo, iter)
{ {

View File

@ -726,7 +726,7 @@ void Foam::polyTopoChange::getFaceOrder
} }
// Compact and reorder faces according to map. // Reorder and compact faces according to map.
void Foam::polyTopoChange::reorderCompactFaces void Foam::polyTopoChange::reorderCompactFaces
( (
const label newSize, const label newSize,
@ -2999,9 +2999,6 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::changeMesh
patchStarts, patchStarts,
syncParallel syncParallel
); );
// Invalidate new points to go into map.
newPoints.clear();
mesh.changing(true); mesh.changing(true);
} }
@ -3010,14 +3007,8 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::changeMesh
retiredPoints_.clear(); retiredPoints_.clear();
retiredPoints_.resize(0); retiredPoints_.resize(0);
faces_.clear();
faces_.setSize(0);
region_.clear(); region_.clear();
region_.setSize(0); region_.setSize(0);
faceOwner_.clear();
faceOwner_.setSize(0);
faceNeighbour_.clear();
faceNeighbour_.setSize(0);
} }
@ -3237,27 +3228,20 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::makeMesh
new fvMesh new fvMesh
( (
io, io,
xferMove<pointField>(newPoints), xferMove(newPoints),
xferMove<faceList>(faces_), xferMoveTo<faceList>(faces_),
xferMove<labelList>(faceOwner_), xferMoveTo<labelList>(faceOwner_),
xferMove<labelList>(faceNeighbour_) xferMoveTo<labelList>(faceNeighbour_)
) )
); );
fvMesh& newMesh = newMeshPtr(); fvMesh& newMesh = newMeshPtr();
// Clear out primitives // Clear out primitives
{ {
newPoints.clear();
retiredPoints_.clear(); retiredPoints_.clear();
retiredPoints_.resize(0); retiredPoints_.resize(0);
faces_.clear();
faces_.setSize(0);
region_.clear(); region_.clear();
region_.setSize(0); region_.setSize(0);
faceOwner_.clear();
faceOwner_.setSize(0);
faceNeighbour_.clear();
faceNeighbour_.setSize(0);
} }

View File

@ -411,7 +411,7 @@ Foam::refinementHistory::refinementHistory
else else
{ {
visibleCells_.setSize(nCells); visibleCells_.setSize(nCells);
splitCells_.setSize(nCells); splitCells_.setCapacity(nCells);
for (label cellI = 0; cellI < nCells; cellI++) for (label cellI = 0; cellI < nCells; cellI++)
{ {

View File

@ -157,7 +157,7 @@ void indexedOctree<Type>::divide
List<DynamicList<label> > subIndices(8); List<DynamicList<label> > subIndices(8);
for (direction octant = 0; octant < subIndices.size(); octant++) for (direction octant = 0; octant < subIndices.size(); octant++)
{ {
subIndices[octant].setSize(indices.size()/8); subIndices[octant].setCapacity(indices.size()/8);
} }
// Precalculate bounding boxes. // Precalculate bounding boxes.

View File

@ -247,7 +247,7 @@ Foam::label Foam::surfaceFeatures::nextFeatEdge
// prevPointI. Marks feature edges visited in featVisited by assigning them // prevPointI. Marks feature edges visited in featVisited by assigning them
// the current feature line number. Returns cumulative length of edges walked. // the current feature line number. Returns cumulative length of edges walked.
// Works in one of two modes: // Works in one of two modes:
// - mark : step to edges with featVisited = -1. // - mark : step to edges with featVisited = -1.
// Mark edges visited with currentFeatI. // Mark edges visited with currentFeatI.
// - clear : step to edges with featVisited = currentFeatI // - clear : step to edges with featVisited = currentFeatI
// Mark edges visited with -2 and erase from feature edges. // Mark edges visited with -2 and erase from feature edges.
@ -257,7 +257,7 @@ Foam::surfaceFeatures::labelScalar Foam::surfaceFeatures::walkSegment
const List<edgeStatus>& edgeStat, const List<edgeStatus>& edgeStat,
const label startEdgeI, const label startEdgeI,
const label startPointI, const label startPointI,
const label currentFeatI, const label currentFeatI,
labelList& featVisited labelList& featVisited
) )
{ {
@ -360,7 +360,7 @@ Foam::surfaceFeatures::surfaceFeatures
const labelList& featureEdges, const labelList& featureEdges,
const label externalStart, const label externalStart,
const label internalStart const label internalStart
) )
: :
surf_(surf), surf_(surf),
featurePoints_(featurePoints), featurePoints_(featurePoints),
@ -457,7 +457,7 @@ Foam::labelList Foam::surfaceFeatures::selectFeatureEdges
if (regionEdges) if (regionEdges)
{ {
selectedEdges.setSize(selectedEdges.size() + nRegionEdges()); selectedEdges.setCapacity(selectedEdges.size() + nRegionEdges());
for (label i = 0; i < externalStart_; i++) for (label i = 0; i < externalStart_; i++)
{ {
@ -467,7 +467,7 @@ Foam::labelList Foam::surfaceFeatures::selectFeatureEdges
if (externalEdges) if (externalEdges)
{ {
selectedEdges.setSize(selectedEdges.size() + nExternalEdges()); selectedEdges.setCapacity(selectedEdges.size() + nExternalEdges());
for (label i = externalStart_; i < internalStart_; i++) for (label i = externalStart_; i < internalStart_; i++)
{ {
@ -477,7 +477,7 @@ Foam::labelList Foam::surfaceFeatures::selectFeatureEdges
if (internalEdges) if (internalEdges)
{ {
selectedEdges.setSize(selectedEdges.size() + nInternalEdges()); selectedEdges.setCapacity(selectedEdges.size() + nInternalEdges());
for (label i = internalStart_; i < featureEdges_.size(); i++) for (label i = internalStart_; i < featureEdges_.size(); i++)
{ {
@ -530,8 +530,8 @@ void Foam::surfaceFeatures::findFeatures(const scalar includedAngle)
// Check if convex or concave by looking at angle // Check if convex or concave by looking at angle
// between face centres and normal // between face centres and normal
vector f0Tof1 = vector f0Tof1 =
surf_[face1].centre(points) surf_[face1].centre(points)
- surf_[face0].centre(points); - surf_[face0].centre(points);
if ((f0Tof1 & faceNormals[face0]) > 0.0) if ((f0Tof1 & faceNormals[face0]) > 0.0)
@ -683,11 +683,11 @@ void Foam::surfaceFeatures::writeDict(Ostream& writeFile) const
{ {
dictionary featInfoDict; dictionary featInfoDict;
featInfoDict.add("externalStart", externalStart_); featInfoDict.add("externalStart", externalStart_);
featInfoDict.add("internalStart", internalStart_); featInfoDict.add("internalStart", internalStart_);
featInfoDict.add("featureEdges", featureEdges_); featInfoDict.add("featureEdges", featureEdges_);
featInfoDict.add("featurePoints", featurePoints_); featInfoDict.add("featurePoints", featurePoints_);
featInfoDict.write(writeFile); featInfoDict.write(writeFile);
} }
@ -1152,7 +1152,7 @@ void Foam::surfaceFeatures::nearestSurfEdge
( (
const labelList& selectedEdges, const labelList& selectedEdges,
const pointField& samples, const pointField& samples,
const vector& searchSpan, // Search span const vector& searchSpan, // Search span
labelList& edgeLabel, labelList& edgeLabel,
labelList& edgeEndPoint, labelList& edgeEndPoint,
pointField& edgePoint pointField& edgePoint
@ -1163,7 +1163,7 @@ void Foam::surfaceFeatures::nearestSurfEdge
edgePoint.setSize(samples.size()); edgePoint.setSize(samples.size());
const pointField& localPoints = surf_.localPoints(); const pointField& localPoints = surf_.localPoints();
octree<octreeDataEdges> ppTree octree<octreeDataEdges> ppTree
( (
treeBoundBox(localPoints), // overall search domain treeBoundBox(localPoints), // overall search domain
@ -1232,7 +1232,7 @@ void Foam::surfaceFeatures::nearestSurfEdge
const labelList& selectedSampleEdges, const labelList& selectedSampleEdges,
const pointField& samplePoints, const pointField& samplePoints,
const vector& searchSpan, // Search span const vector& searchSpan, // Search span
labelList& edgeLabel, // label of surface edge or -1 labelList& edgeLabel, // label of surface edge or -1
pointField& pointOnEdge, // point on above edge pointField& pointOnEdge, // point on above edge
pointField& pointOnFeature // point on sample edge pointField& pointOnFeature // point on sample edge
@ -1242,7 +1242,6 @@ void Foam::surfaceFeatures::nearestSurfEdge
pointOnEdge.setSize(selectedSampleEdges.size()); pointOnEdge.setSize(selectedSampleEdges.size());
pointOnFeature.setSize(selectedSampleEdges.size()); pointOnFeature.setSize(selectedSampleEdges.size());
octree<octreeDataEdges> ppTree octree<octreeDataEdges> ppTree
( (

View File

@ -174,6 +174,7 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
nPatch++; nPatch++;
} }
} }
// truncate addressed size
dynSizes.setSize(nPatch); dynSizes.setSize(nPatch);
// transfer to normal lists // transfer to normal lists