ENH: Moving cellOccupancy into KinematicCloud.

This commit is contained in:
graham
2010-09-20 12:45:57 +01:00
parent ebb9a9e1ac
commit d1b9dab50a
11 changed files with 203 additions and 37 deletions

View File

@ -43,6 +43,52 @@ void Foam::KinematicCloud<ParcelType>::preEvolve()
{ {
this->dispersion().cacheFields(true); this->dispersion().cacheFields(true);
forces_.cacheFields(true, interpolationSchemes_); forces_.cacheFields(true, interpolationSchemes_);
updateCellOccupancy();
}
template<class ParcelType>
void Foam::KinematicCloud<ParcelType>::buildCellOccupancy()
{
if (cellOccupancyPtr_.empty())
{
cellOccupancyPtr_.reset
(
new List<DynamicList<ParcelType*> >(mesh_.nCells())
);
}
else if (cellOccupancyPtr_().size() != mesh_.nCells())
{
// If the size of the mesh has changed, reset the
// cellOccupancy size
cellOccupancyPtr_().setSize(mesh_.nCells());
}
List<DynamicList<ParcelType*> >& cellOccupancy = cellOccupancyPtr_();
forAll(cellOccupancy, cO)
{
cellOccupancy[cO].clear();
}
forAllIter(typename KinematicCloud<ParcelType>, *this, iter)
{
cellOccupancy[iter().cell()].append(&iter());
}
}
template<class ParcelType>
void Foam::KinematicCloud<ParcelType>::updateCellOccupancy()
{
// Only build the cellOccupancy if the pointer is set, i.e. it has
// been requested before.
if (cellOccupancyPtr_.valid())
{
buildCellOccupancy();
}
} }
@ -80,8 +126,19 @@ void Foam::KinematicCloud<ParcelType>::evolveCloud()
g_.value() g_.value()
); );
label preInjectionSize = this->size();
this->surfaceFilm().inject(td); this->surfaceFilm().inject(td);
// Update the cellOccupancy if the size of the cloud has changed
// during the injection.
if (preInjectionSize != this->size())
{
updateCellOccupancy();
preInjectionSize = this->size();
}
this->injection().inject(td); this->injection().inject(td);
if (coupled_) if (coupled_)
@ -89,6 +146,18 @@ void Foam::KinematicCloud<ParcelType>::evolveCloud()
resetSourceTerms(); resetSourceTerms();
} }
// Assume that motion will update the cellOccupancy as necessary
// before it is required.
motion(td);
}
template<class ParcelType>
void Foam::KinematicCloud<ParcelType>::motion
(
typename ParcelType::trackData& td
)
{
// Sympletic leapfrog integration of particle forces: // Sympletic leapfrog integration of particle forces:
// + apply half deltaV with stored force // + apply half deltaV with stored force
// + move positions with new velocity // + move positions with new velocity
@ -136,6 +205,8 @@ void Foam::KinematicCloud<ParcelType>::moveCollide
// td.part() = ParcelType::trackData::tpRotationalTrack; // td.part() = ParcelType::trackData::tpRotationalTrack;
// Cloud<ParcelType>::move(td); // Cloud<ParcelType>::move(td);
updateCellOccupancy();
this->collision().collide(); this->collision().collide();
td.part() = ParcelType::trackData::tpVelocityHalfStep; td.part() = ParcelType::trackData::tpVelocityHalfStep;
@ -194,6 +265,7 @@ Foam::KinematicCloud<ParcelType>::KinematicCloud
particleProperties_.lookup("cellValueSourceCorrection") particleProperties_.lookup("cellValueSourceCorrection")
), ),
rndGen_(label(0)), rndGen_(label(0)),
cellOccupancyPtr_(),
rho_(rho), rho_(rho),
U_(U), U_(U),
mu_(mu), mu_(mu),

View File

@ -136,6 +136,9 @@ protected:
//- Random number generator - used by some injection routines //- Random number generator - used by some injection routines
Random rndGen_; Random rndGen_;
//- Cell occupancy information for each parcel, (demand driven)
autoPtr<List<DynamicList<ParcelType*> > > cellOccupancyPtr_;
// References to the carrier gas fields // References to the carrier gas fields
@ -209,10 +212,20 @@ protected:
//- Pre-evolve //- Pre-evolve
void preEvolve(); void preEvolve();
//- Build the cellOccupancy
void buildCellOccupancy();
//- Update (i.e. build) the cellOccupancy if it has
// already been used
void updateCellOccupancy();
//- Evolve the cloud //- Evolve the cloud
void evolveCloud(); void evolveCloud();
//- Move-collide //- Particle motion
void motion(typename ParcelType::trackData& td);
//- Move-collide particles
void moveCollide(typename ParcelType::trackData& td); void moveCollide(typename ParcelType::trackData& td);
//- Post-evolve //- Post-evolve
@ -284,6 +297,11 @@ public:
//- Return refernce to the random object //- Return refernce to the random object
inline Random& rndGen(); inline Random& rndGen();
//- Return the cell occupancy information for each parcel,
// non-const access, the caller is responsible for updating
// it if particles are removed or created.
inline List<DynamicList<ParcelType*> >& cellOccupancy();
// References to the carrier gas fields // References to the carrier gas fields

View File

@ -302,6 +302,19 @@ inline Foam::Random& Foam::KinematicCloud<ParcelType>::rndGen()
} }
template<class ParcelType>
inline Foam::List<Foam::DynamicList<ParcelType*> >&
Foam::KinematicCloud<ParcelType>::cellOccupancy()
{
if (cellOccupancyPtr_.empty())
{
buildCellOccupancy();
}
return cellOccupancyPtr_();
}
template<class ParcelType> template<class ParcelType>
inline Foam::DimensionedField<Foam::vector, Foam::volMesh>& inline Foam::DimensionedField<Foam::vector, Foam::volMesh>&
Foam::KinematicCloud<ParcelType>::UTrans() Foam::KinematicCloud<ParcelType>::UTrans()

View File

@ -120,8 +120,19 @@ void Foam::ReactingCloud<ParcelType>::evolveCloud()
this->g().value() this->g().value()
); );
label preInjectionSize = this->size();
this->surfaceFilm().inject(td); this->surfaceFilm().inject(td);
// Update the cellOccupancy if the size of the cloud has changed
// during the injection.
if (preInjectionSize != this->size())
{
this->updateCellOccupancy();
preInjectionSize = this->size();
}
this->injection().inject(td); this->injection().inject(td);
if (this->coupled()) if (this->coupled())
@ -129,7 +140,19 @@ void Foam::ReactingCloud<ParcelType>::evolveCloud()
resetSourceTerms(); resetSourceTerms();
} }
Cloud<ParcelType>::move(td); // Assume that motion will update the cellOccupancy as necessary
// before it is required.
motion(td);
}
template<class ParcelType>
void Foam::ReactingCloud<ParcelType>::motion
(
typename ParcelType::trackData& td
)
{
ThermoCloud<ParcelType>::motion(td);
} }

View File

@ -130,6 +130,9 @@ protected:
//- Evolve the cloud //- Evolve the cloud
void evolveCloud(); void evolveCloud();
//- Particle motion
void motion(typename ParcelType::trackData& td);
//- Post-evolve //- Post-evolve
void postEvolve(); void postEvolve();

View File

@ -93,8 +93,19 @@ void Foam::ReactingMultiphaseCloud<ParcelType>::evolveCloud()
this->g().value() this->g().value()
); );
label preInjectionSize = this->size();
this->surfaceFilm().inject(td); this->surfaceFilm().inject(td);
// Update the cellOccupancy if the size of the cloud has changed
// during the injection.
if (preInjectionSize != this->size())
{
this->updateCellOccupancy();
preInjectionSize = this->size();
}
this->injection().inject(td); this->injection().inject(td);
if (this->coupled()) if (this->coupled())
@ -102,7 +113,19 @@ void Foam::ReactingMultiphaseCloud<ParcelType>::evolveCloud()
resetSourceTerms(); resetSourceTerms();
} }
Cloud<ParcelType>::move(td); // Assume that motion will update the cellOccupancy as necessary
// before it is required.
motion(td);
}
template<class ParcelType>
void Foam::ReactingMultiphaseCloud<ParcelType>::motion
(
typename ParcelType::trackData& td
)
{
ReactingCloud<ParcelType>::motion(td);
} }

View File

@ -121,6 +121,9 @@ protected:
//- Evolve the cloud //- Evolve the cloud
void evolveCloud(); void evolveCloud();
//- Particle motion
void motion(typename ParcelType::trackData& td);
//- Post-evolve //- Post-evolve
void postEvolve(); void postEvolve();

View File

@ -86,8 +86,19 @@ void Foam::ThermoCloud<ParcelType>::evolveCloud()
this->g().value() this->g().value()
); );
label preInjectionSize = this->size();
// Update the cellOccupancy if the size of the cloud has changed
// during the injection.
this->surfaceFilm().inject(td); this->surfaceFilm().inject(td);
if (preInjectionSize != this->size())
{
this->updateCellOccupancy();
preInjectionSize = this->size();
}
this->injection().inject(td); this->injection().inject(td);
if (this->coupled()) if (this->coupled())
@ -95,7 +106,19 @@ void Foam::ThermoCloud<ParcelType>::evolveCloud()
resetSourceTerms(); resetSourceTerms();
} }
Cloud<ParcelType>::move(td); // Assume that motion will update the cellOccupancy as necessary
// before it is required.
motion(td);
}
template<class ParcelType>
void Foam::ThermoCloud<ParcelType>::motion
(
typename ParcelType::trackData& td
)
{
KinematicCloud<ParcelType>::motion(td);
} }

View File

@ -121,6 +121,9 @@ protected:
//- Evolve the cloud //- Evolve the cloud
void evolveCloud(); void evolveCloud();
//- Particle motion
void motion(typename ParcelType::trackData& td);
//- Post-evolve //- Post-evolve
void postEvolve(); void postEvolve();

View File

@ -51,8 +51,6 @@ void Foam::PairCollision<CloudType>::preInteraction()
p.torque() = vector::zero; p.torque() = vector::zero;
} }
buildCellOccupancy();
} }
@ -61,7 +59,7 @@ void Foam::PairCollision<CloudType>::parcelInteraction()
{ {
PstreamBuffers pBufs(Pstream::nonBlocking); PstreamBuffers pBufs(Pstream::nonBlocking);
il_.sendReferredData(cellOccupancy_, pBufs); il_.sendReferredData(this->owner().cellOccupancy(), pBufs);
realRealInteraction(); realRealInteraction();
@ -80,17 +78,20 @@ void Foam::PairCollision<CloudType>::realRealInteraction()
typename CloudType::parcelType* pA_ptr = NULL; typename CloudType::parcelType* pA_ptr = NULL;
typename CloudType::parcelType* pB_ptr = NULL; typename CloudType::parcelType* pB_ptr = NULL;
List<DynamicList<typename CloudType::parcelType*> >& cellOccupancy =
this->owner().cellOccupancy();
forAll(dil, realCellI) forAll(dil, realCellI)
{ {
// Loop over all Parcels in cell A (a) // Loop over all Parcels in cell A (a)
forAll(cellOccupancy_[realCellI], a) forAll(cellOccupancy[realCellI], a)
{ {
pA_ptr = cellOccupancy_[realCellI][a]; pA_ptr = cellOccupancy[realCellI][a];
forAll(dil[realCellI], interactingCells) forAll(dil[realCellI], interactingCells)
{ {
List<typename CloudType::parcelType*> cellBParcels = List<typename CloudType::parcelType*> cellBParcels =
cellOccupancy_[dil[realCellI][interactingCells]]; cellOccupancy[dil[realCellI][interactingCells]];
// Loop over all Parcels in cell B (b) // Loop over all Parcels in cell B (b)
forAll(cellBParcels, b) forAll(cellBParcels, b)
@ -102,9 +103,9 @@ void Foam::PairCollision<CloudType>::realRealInteraction()
} }
// Loop over the other Parcels in cell A (aO) // Loop over the other Parcels in cell A (aO)
forAll(cellOccupancy_[realCellI], aO) forAll(cellOccupancy[realCellI], aO)
{ {
pB_ptr = cellOccupancy_[realCellI][aO]; pB_ptr = cellOccupancy[realCellI][aO];
// Do not double-evaluate, compare pointers, arbitrary // Do not double-evaluate, compare pointers, arbitrary
// order // order
@ -127,6 +128,9 @@ void Foam::PairCollision<CloudType>::realReferredInteraction()
List<IDLList<typename CloudType::parcelType> >& referredParticles = List<IDLList<typename CloudType::parcelType> >& referredParticles =
il_.referredParticles(); il_.referredParticles();
List<DynamicList<typename CloudType::parcelType*> >& cellOccupancy =
this->owner().cellOccupancy();
// Loop over all referred cells // Loop over all referred cells
forAll(ril, refCellI) forAll(ril, refCellI)
{ {
@ -150,7 +154,7 @@ void Foam::PairCollision<CloudType>::realReferredInteraction()
forAll(realCells, realCellI) forAll(realCells, realCellI)
{ {
List<typename CloudType::parcelType*> realCellParcels = List<typename CloudType::parcelType*> realCellParcels =
cellOccupancy_[realCells[realCellI]]; cellOccupancy[realCells[realCellI]];
forAll(realCellParcels, realParcelI) forAll(realCellParcels, realParcelI)
{ {
@ -179,6 +183,9 @@ void Foam::PairCollision<CloudType>::wallInteraction()
const volVectorField& U = mesh.lookupObject<volVectorField>(il_.UName()); const volVectorField& U = mesh.lookupObject<volVectorField>(il_.UName());
List<DynamicList<typename CloudType::parcelType*> >& cellOccupancy =
this->owner().cellOccupancy();
// Storage for the wall interaction sites // Storage for the wall interaction sites
DynamicList<point> flatSitePoints; DynamicList<point> flatSitePoints;
DynamicList<scalar> flatSiteExclusionDistancesSqr; DynamicList<scalar> flatSiteExclusionDistancesSqr;
@ -196,7 +203,7 @@ void Foam::PairCollision<CloudType>::wallInteraction()
const labelList& realWallFaces = directWallFaces[realCellI]; const labelList& realWallFaces = directWallFaces[realCellI];
// Loop over all Parcels in cell // Loop over all Parcels in cell
forAll(cellOccupancy_[realCellI], cellParticleI) forAll(cellOccupancy[realCellI], cellParticleI)
{ {
flatSitePoints.clear(); flatSitePoints.clear();
flatSiteExclusionDistancesSqr.clear(); flatSiteExclusionDistancesSqr.clear();
@ -209,7 +216,7 @@ void Foam::PairCollision<CloudType>::wallInteraction()
sharpSiteData.clear(); sharpSiteData.clear();
typename CloudType::parcelType& p = typename CloudType::parcelType& p =
*cellOccupancy_[realCellI][cellParticleI]; *cellOccupancy[realCellI][cellParticleI];
const point& pos = p.position(); const point& pos = p.position();
@ -482,21 +489,6 @@ void Foam::PairCollision<CloudType>::postInteraction()
} }
template<class CloudType>
void Foam::PairCollision<CloudType>::buildCellOccupancy()
{
forAll(cellOccupancy_, cO)
{
cellOccupancy_[cO].clear();
}
forAllIter(typename CloudType, this->owner(), iter)
{
cellOccupancy_[iter().cell()].append(&iter());
}
}
template<class CloudType> template<class CloudType>
void Foam::PairCollision<CloudType>::evaluatePair void Foam::PairCollision<CloudType>::evaluatePair
( (
@ -539,7 +531,6 @@ Foam::PairCollision<CloudType>::PairCollision
) )
: :
CollisionModel<CloudType>(dict, owner, typeName), CollisionModel<CloudType>(dict, owner, typeName),
cellOccupancy_(owner.mesh().nCells()),
pairModel_ pairModel_
( (
PairModel<CloudType>::New PairModel<CloudType>::New

View File

@ -76,9 +76,6 @@ class PairCollision
// Private data // Private data
//- Cell occupancy information for each parcel
List<DynamicList<typename CloudType::parcelType*> > cellOccupancy_;
//- PairModel to calculate the interaction between two parcels //- PairModel to calculate the interaction between two parcels
autoPtr<PairModel<CloudType> > pairModel_; autoPtr<PairModel<CloudType> > pairModel_;
@ -124,9 +121,6 @@ class PairCollision
//- Post collision tasks //- Post collision tasks
void postInteraction(); void postInteraction();
//- Build the cell occupancy information for each parcel
void buildCellOccupancy();
//- Calculate the pair force between parcels //- Calculate the pair force between parcels
void evaluatePair void evaluatePair
( (