findFaces without allocation

This commit is contained in:
mattijs
2009-06-19 12:01:29 +01:00
parent 0dcd37351b
commit a64dfb526c
4 changed files with 25 additions and 23 deletions

View File

@ -78,6 +78,9 @@ class Cloud
const unallocLabelList& owner_; const unallocLabelList& owner_;
const unallocLabelList& neighbour_; const unallocLabelList& neighbour_;
//- Temporary storage for addressing. Used in findFaces.
mutable DynamicList<label> labels_;
// Private member functions // Private member functions

View File

@ -36,16 +36,17 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParticleType> template<class ParticleType>
Foam::labelList Foam::Particle<ParticleType>::findFaces void Foam::Particle<ParticleType>::findFaces
( (
const vector& position const vector& position,
DynamicList<label>& faceList
) const ) const
{ {
const polyMesh& mesh = cloud_.polyMesh_; const polyMesh& mesh = cloud_.polyMesh_;
const labelList& faces = mesh.cells()[celli_]; const labelList& faces = mesh.cells()[celli_];
const vector& C = mesh.cellCentres()[celli_]; const vector& C = mesh.cellCentres()[celli_];
DynamicList<label> faceList(10); faceList.clear();
forAll(faces, i) forAll(faces, i)
{ {
label facei = faces[i]; label facei = faces[i];
@ -56,26 +57,23 @@ Foam::labelList Foam::Particle<ParticleType>::findFaces
faceList.append(facei); faceList.append(facei);
} }
} }
faceList.shrink();
return faceList;
} }
template<class ParticleType> template<class ParticleType>
Foam::labelList Foam::Particle<ParticleType>::findFaces void Foam::Particle<ParticleType>::findFaces
( (
const vector& position, const vector& position,
const label celli, const label celli,
const scalar stepFraction const scalar stepFraction,
DynamicList<label>& faceList
) const ) const
{ {
const polyMesh& mesh = cloud_.polyMesh_; const polyMesh& mesh = cloud_.polyMesh_;
const labelList& faces = mesh.cells()[celli]; const labelList& faces = mesh.cells()[celli];
const vector& C = mesh.cellCentres()[celli]; const vector& C = mesh.cellCentres()[celli];
DynamicList<label> faceList(10); faceList.clear();
forAll(faces, i) forAll(faces, i)
{ {
label facei = faces[i]; label facei = faces[i];
@ -86,10 +84,6 @@ Foam::labelList Foam::Particle<ParticleType>::findFaces
faceList.append(facei); faceList.append(facei);
} }
} }
faceList.shrink();
return faceList;
} }
@ -237,7 +231,8 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
{ {
const polyMesh& mesh = cloud_.polyMesh_; const polyMesh& mesh = cloud_.polyMesh_;
labelList faces = findFaces(endPosition); DynamicList<label>& faces = cloud_.labels_;
findFaces(endPosition, faces);
facei_ = -1; facei_ = -1;
scalar trackFraction = 0.0; scalar trackFraction = 0.0;

View File

@ -151,18 +151,20 @@ protected:
const label facei const label facei
) const; ) const;
//- Return the faces between position and cell centre //- Find the faces between position and cell centre
labelList findFaces void findFaces
( (
const vector& position const vector& position,
DynamicList<label>& faceList
) const; ) const;
//- Return the faces between position and cell centre //- Find the faces between position and cell centre
labelList findFaces void findFaces
( (
const vector& position, const vector& position,
const label celli, const label celli,
const scalar stepFraction const scalar stepFraction,
DynamicList<label>& faceList
) const; ) const;

View File

@ -236,7 +236,8 @@ inline scalar Particle<ParticleType>::lambda
template<class ParticleType> template<class ParticleType>
inline bool Particle<ParticleType>::inCell() const inline bool Particle<ParticleType>::inCell() const
{ {
labelList faces = findFaces(position_); DynamicList<label>& faces = cloud_.labels_;
findFaces(position_, faces);
return (!faces.size()); return (!faces.size());
} }
@ -250,7 +251,8 @@ inline bool Particle<ParticleType>::inCell
const scalar stepFraction const scalar stepFraction
) const ) const
{ {
labelList faces = findFaces(position, celli, stepFraction); DynamicList<label>& faces = cloud_.labels_;
findFaces(position, celli, stepFraction, faces);
return (!faces.size()); return (!faces.size());
} }