ORourkeCollision: use a CompactListList to avoid memory allocation overhead

This commit is contained in:
Henry Weller
2016-06-04 17:45:35 +01:00
parent 76f6236bbe
commit d60ae9a496

View File

@ -24,8 +24,9 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ORourkeCollision.H" #include "ORourkeCollision.H"
#include "mathematicalConstants.H"
#include "SLGThermo.H" #include "SLGThermo.H"
#include "CompactListList.H"
#include "mathematicalConstants.H"
using namespace Foam::constant::mathematical; using namespace Foam::constant::mathematical;
@ -34,12 +35,23 @@ using namespace Foam::constant::mathematical;
template<class CloudType> template<class CloudType>
void Foam::ORourkeCollision<CloudType>::collide(const scalar dt) void Foam::ORourkeCollision<CloudType>::collide(const scalar dt)
{ {
// Create a list of parcels in each cell // Create the occupancy list for the cells
List<DynamicList<parcelType*>> pInCell(this->owner().mesh().nCells()); labelList occupancy(this->owner().mesh().nCells(), 0);
forAllIter(typename CloudType, this->owner(), iter) forAllIter(typename CloudType, this->owner(), iter)
{ {
pInCell[iter().cell()].append(&iter()); occupancy[iter().cell()]++;
}
// Initialize the sizes of the lists of parcels in each cell
CompactListList<parcelType*> pInCell(occupancy);
// Reset the occupancy to use as a counter
occupancy = 0;
// Set the parcel pointer lists for each cell
forAllIter(typename CloudType, this->owner(), iter)
{
pInCell(iter().cell(), occupancy[iter().cell()]++) = &iter();
} }
for (label celli=0; celli<this->owner().mesh().nCells(); celli++) for (label celli=0; celli<this->owner().mesh().nCells(); celli++)