From d1b9dab50af3186236848783cc650e518f370ff1 Mon Sep 17 00:00:00 2001 From: graham Date: Mon, 20 Sep 2010 12:45:57 +0100 Subject: [PATCH] ENH: Moving cellOccupancy into KinematicCloud. --- .../Templates/KinematicCloud/KinematicCloud.C | 72 +++++++++++++++++++ .../Templates/KinematicCloud/KinematicCloud.H | 20 +++++- .../KinematicCloud/KinematicCloudI.H | 13 ++++ .../Templates/ReactingCloud/ReactingCloud.C | 25 ++++++- .../Templates/ReactingCloud/ReactingCloud.H | 3 + .../ReactingMultiphaseCloud.C | 25 ++++++- .../ReactingMultiphaseCloud.H | 3 + .../Templates/ThermoCloud/ThermoCloud.C | 25 ++++++- .../Templates/ThermoCloud/ThermoCloud.H | 3 + .../PairCollision/PairCollision.C | 45 +++++------- .../PairCollision/PairCollision.H | 6 -- 11 files changed, 203 insertions(+), 37 deletions(-) diff --git a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C index 10fccde371..9666d61719 100644 --- a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C +++ b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C @@ -43,6 +43,52 @@ void Foam::KinematicCloud::preEvolve() { this->dispersion().cacheFields(true); forces_.cacheFields(true, interpolationSchemes_); + updateCellOccupancy(); +} + + +template +void Foam::KinematicCloud::buildCellOccupancy() +{ + if (cellOccupancyPtr_.empty()) + { + cellOccupancyPtr_.reset + ( + new List >(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 >& cellOccupancy = cellOccupancyPtr_(); + + forAll(cellOccupancy, cO) + { + cellOccupancy[cO].clear(); + } + + forAllIter(typename KinematicCloud, *this, iter) + { + cellOccupancy[iter().cell()].append(&iter()); + } +} + + +template +void Foam::KinematicCloud::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::evolveCloud() g_.value() ); + label preInjectionSize = this->size(); + 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); if (coupled_) @@ -89,6 +146,18 @@ void Foam::KinematicCloud::evolveCloud() resetSourceTerms(); } + // Assume that motion will update the cellOccupancy as necessary + // before it is required. + motion(td); +} + + +template +void Foam::KinematicCloud::motion +( + typename ParcelType::trackData& td +) +{ // Sympletic leapfrog integration of particle forces: // + apply half deltaV with stored force // + move positions with new velocity @@ -136,6 +205,8 @@ void Foam::KinematicCloud::moveCollide // td.part() = ParcelType::trackData::tpRotationalTrack; // Cloud::move(td); + updateCellOccupancy(); + this->collision().collide(); td.part() = ParcelType::trackData::tpVelocityHalfStep; @@ -194,6 +265,7 @@ Foam::KinematicCloud::KinematicCloud particleProperties_.lookup("cellValueSourceCorrection") ), rndGen_(label(0)), + cellOccupancyPtr_(), rho_(rho), U_(U), mu_(mu), diff --git a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H index 5d36cb575e..ed5b5ae539 100644 --- a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H +++ b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H @@ -136,6 +136,9 @@ protected: //- Random number generator - used by some injection routines Random rndGen_; + //- Cell occupancy information for each parcel, (demand driven) + autoPtr > > cellOccupancyPtr_; + // References to the carrier gas fields @@ -209,10 +212,20 @@ protected: //- Pre-evolve void preEvolve(); + //- Build the cellOccupancy + void buildCellOccupancy(); + + //- Update (i.e. build) the cellOccupancy if it has + // already been used + void updateCellOccupancy(); + //- Evolve the cloud void evolveCloud(); - //- Move-collide + //- Particle motion + void motion(typename ParcelType::trackData& td); + + //- Move-collide particles void moveCollide(typename ParcelType::trackData& td); //- Post-evolve @@ -284,6 +297,11 @@ public: //- Return refernce to the random object 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 >& cellOccupancy(); + // References to the carrier gas fields diff --git a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloudI.H b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloudI.H index 9f9b441f43..536e4e6773 100644 --- a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloudI.H +++ b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloudI.H @@ -302,6 +302,19 @@ inline Foam::Random& Foam::KinematicCloud::rndGen() } +template +inline Foam::List >& +Foam::KinematicCloud::cellOccupancy() +{ + if (cellOccupancyPtr_.empty()) + { + buildCellOccupancy(); + } + + return cellOccupancyPtr_(); +} + + template inline Foam::DimensionedField& Foam::KinematicCloud::UTrans() diff --git a/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.C b/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.C index fec5e02ea3..f3fb165b0e 100644 --- a/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.C +++ b/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.C @@ -120,8 +120,19 @@ void Foam::ReactingCloud::evolveCloud() this->g().value() ); + label preInjectionSize = this->size(); + 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); if (this->coupled()) @@ -129,7 +140,19 @@ void Foam::ReactingCloud::evolveCloud() resetSourceTerms(); } - Cloud::move(td); + // Assume that motion will update the cellOccupancy as necessary + // before it is required. + motion(td); +} + + +template +void Foam::ReactingCloud::motion +( + typename ParcelType::trackData& td +) +{ + ThermoCloud::motion(td); } diff --git a/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.H b/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.H index 38b33eab48..def51f8955 100644 --- a/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.H +++ b/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.H @@ -130,6 +130,9 @@ protected: //- Evolve the cloud void evolveCloud(); + //- Particle motion + void motion(typename ParcelType::trackData& td); + //- Post-evolve void postEvolve(); diff --git a/src/lagrangian/intermediate/clouds/Templates/ReactingMultiphaseCloud/ReactingMultiphaseCloud.C b/src/lagrangian/intermediate/clouds/Templates/ReactingMultiphaseCloud/ReactingMultiphaseCloud.C index 954f048634..451e3716d4 100644 --- a/src/lagrangian/intermediate/clouds/Templates/ReactingMultiphaseCloud/ReactingMultiphaseCloud.C +++ b/src/lagrangian/intermediate/clouds/Templates/ReactingMultiphaseCloud/ReactingMultiphaseCloud.C @@ -93,8 +93,19 @@ void Foam::ReactingMultiphaseCloud::evolveCloud() this->g().value() ); + label preInjectionSize = this->size(); + 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); if (this->coupled()) @@ -102,7 +113,19 @@ void Foam::ReactingMultiphaseCloud::evolveCloud() resetSourceTerms(); } - Cloud::move(td); + // Assume that motion will update the cellOccupancy as necessary + // before it is required. + motion(td); +} + + +template +void Foam::ReactingMultiphaseCloud::motion +( + typename ParcelType::trackData& td +) +{ + ReactingCloud::motion(td); } diff --git a/src/lagrangian/intermediate/clouds/Templates/ReactingMultiphaseCloud/ReactingMultiphaseCloud.H b/src/lagrangian/intermediate/clouds/Templates/ReactingMultiphaseCloud/ReactingMultiphaseCloud.H index efd1eaab8e..af2199261e 100644 --- a/src/lagrangian/intermediate/clouds/Templates/ReactingMultiphaseCloud/ReactingMultiphaseCloud.H +++ b/src/lagrangian/intermediate/clouds/Templates/ReactingMultiphaseCloud/ReactingMultiphaseCloud.H @@ -121,6 +121,9 @@ protected: //- Evolve the cloud void evolveCloud(); + //- Particle motion + void motion(typename ParcelType::trackData& td); + //- Post-evolve void postEvolve(); diff --git a/src/lagrangian/intermediate/clouds/Templates/ThermoCloud/ThermoCloud.C b/src/lagrangian/intermediate/clouds/Templates/ThermoCloud/ThermoCloud.C index 96d6d59b8a..26cbeedcc6 100644 --- a/src/lagrangian/intermediate/clouds/Templates/ThermoCloud/ThermoCloud.C +++ b/src/lagrangian/intermediate/clouds/Templates/ThermoCloud/ThermoCloud.C @@ -86,8 +86,19 @@ void Foam::ThermoCloud::evolveCloud() 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); + if (preInjectionSize != this->size()) + { + this->updateCellOccupancy(); + + preInjectionSize = this->size(); + } + this->injection().inject(td); if (this->coupled()) @@ -95,7 +106,19 @@ void Foam::ThermoCloud::evolveCloud() resetSourceTerms(); } - Cloud::move(td); + // Assume that motion will update the cellOccupancy as necessary + // before it is required. + motion(td); +} + + +template +void Foam::ThermoCloud::motion +( + typename ParcelType::trackData& td +) +{ + KinematicCloud::motion(td); } diff --git a/src/lagrangian/intermediate/clouds/Templates/ThermoCloud/ThermoCloud.H b/src/lagrangian/intermediate/clouds/Templates/ThermoCloud/ThermoCloud.H index 0f7c8afb23..a476dcb6f7 100644 --- a/src/lagrangian/intermediate/clouds/Templates/ThermoCloud/ThermoCloud.H +++ b/src/lagrangian/intermediate/clouds/Templates/ThermoCloud/ThermoCloud.H @@ -121,6 +121,9 @@ protected: //- Evolve the cloud void evolveCloud(); + //- Particle motion + void motion(typename ParcelType::trackData& td); + //- Post-evolve void postEvolve(); diff --git a/src/lagrangian/intermediate/submodels/Kinematic/CollisionModel/PairCollision/PairCollision.C b/src/lagrangian/intermediate/submodels/Kinematic/CollisionModel/PairCollision/PairCollision.C index e1e1587c95..0afeb97578 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/CollisionModel/PairCollision/PairCollision.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/CollisionModel/PairCollision/PairCollision.C @@ -51,8 +51,6 @@ void Foam::PairCollision::preInteraction() p.torque() = vector::zero; } - - buildCellOccupancy(); } @@ -61,7 +59,7 @@ void Foam::PairCollision::parcelInteraction() { PstreamBuffers pBufs(Pstream::nonBlocking); - il_.sendReferredData(cellOccupancy_, pBufs); + il_.sendReferredData(this->owner().cellOccupancy(), pBufs); realRealInteraction(); @@ -80,17 +78,20 @@ void Foam::PairCollision::realRealInteraction() typename CloudType::parcelType* pA_ptr = NULL; typename CloudType::parcelType* pB_ptr = NULL; + List >& cellOccupancy = + this->owner().cellOccupancy(); + forAll(dil, realCellI) { // 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) { List cellBParcels = - cellOccupancy_[dil[realCellI][interactingCells]]; + cellOccupancy[dil[realCellI][interactingCells]]; // Loop over all Parcels in cell B (b) forAll(cellBParcels, b) @@ -102,9 +103,9 @@ void Foam::PairCollision::realRealInteraction() } // 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 // order @@ -127,6 +128,9 @@ void Foam::PairCollision::realReferredInteraction() List >& referredParticles = il_.referredParticles(); + List >& cellOccupancy = + this->owner().cellOccupancy(); + // Loop over all referred cells forAll(ril, refCellI) { @@ -150,7 +154,7 @@ void Foam::PairCollision::realReferredInteraction() forAll(realCells, realCellI) { List realCellParcels = - cellOccupancy_[realCells[realCellI]]; + cellOccupancy[realCells[realCellI]]; forAll(realCellParcels, realParcelI) { @@ -179,6 +183,9 @@ void Foam::PairCollision::wallInteraction() const volVectorField& U = mesh.lookupObject(il_.UName()); + List >& cellOccupancy = + this->owner().cellOccupancy(); + // Storage for the wall interaction sites DynamicList flatSitePoints; DynamicList flatSiteExclusionDistancesSqr; @@ -196,7 +203,7 @@ void Foam::PairCollision::wallInteraction() const labelList& realWallFaces = directWallFaces[realCellI]; // Loop over all Parcels in cell - forAll(cellOccupancy_[realCellI], cellParticleI) + forAll(cellOccupancy[realCellI], cellParticleI) { flatSitePoints.clear(); flatSiteExclusionDistancesSqr.clear(); @@ -209,7 +216,7 @@ void Foam::PairCollision::wallInteraction() sharpSiteData.clear(); typename CloudType::parcelType& p = - *cellOccupancy_[realCellI][cellParticleI]; + *cellOccupancy[realCellI][cellParticleI]; const point& pos = p.position(); @@ -482,21 +489,6 @@ void Foam::PairCollision::postInteraction() } -template -void Foam::PairCollision::buildCellOccupancy() -{ - forAll(cellOccupancy_, cO) - { - cellOccupancy_[cO].clear(); - } - - forAllIter(typename CloudType, this->owner(), iter) - { - cellOccupancy_[iter().cell()].append(&iter()); - } -} - - template void Foam::PairCollision::evaluatePair ( @@ -539,7 +531,6 @@ Foam::PairCollision::PairCollision ) : CollisionModel(dict, owner, typeName), - cellOccupancy_(owner.mesh().nCells()), pairModel_ ( PairModel::New diff --git a/src/lagrangian/intermediate/submodels/Kinematic/CollisionModel/PairCollision/PairCollision.H b/src/lagrangian/intermediate/submodels/Kinematic/CollisionModel/PairCollision/PairCollision.H index 8699d477cd..6ad4130e1c 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/CollisionModel/PairCollision/PairCollision.H +++ b/src/lagrangian/intermediate/submodels/Kinematic/CollisionModel/PairCollision/PairCollision.H @@ -76,9 +76,6 @@ class PairCollision // Private data - //- Cell occupancy information for each parcel - List > cellOccupancy_; - //- PairModel to calculate the interaction between two parcels autoPtr > pairModel_; @@ -124,9 +121,6 @@ class PairCollision //- Post collision tasks void postInteraction(); - //- Build the cell occupancy information for each parcel - void buildCellOccupancy(); - //- Calculate the pair force between parcels void evaluatePair (