From 3ea5bf774a54ca208f52a94545a1be37cac62b1a Mon Sep 17 00:00:00 2001 From: danielque Date: Wed, 5 Aug 2020 17:02:09 +0200 Subject: [PATCH] test concept for centralized per-particle properties register any per-particle properties (here: cellsPerParticle_ of voidFractionModel) in hashtables in cfdemCloud class and in further consequence handle access to per-particle data pointers centrally --- .../cfdemParticle/cfdemCloud/cfdemCloud.C | 21 +++++++++++ .../cfdemParticle/cfdemCloud/cfdemCloud.H | 11 ++++++ .../cfdemParticle/cfdemCloud/cfdemCloudI.H | 35 +++++++++++++++++++ .../GaussVoidFraction/GaussVoidFraction.C | 8 ++--- .../IBVoidFraction/IBVoidFraction.C | 8 ++--- .../bigParticleVoidFraction.C | 8 ++--- .../centreVoidFraction/centreVoidFraction.C | 6 ++-- .../dividedVoidFraction/dividedVoidFraction.C | 6 ++-- .../dividedVoidFraction/setWeightedSource.H | 12 +++---- .../trilinearVoidFraction.C | 2 +- .../voidFractionModel/voidFractionModel.C | 15 ++++---- .../voidFractionModel/voidFractionModel.H | 1 - 12 files changed, 99 insertions(+), 34 deletions(-) diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C index df719b60..893a392b 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C @@ -160,6 +160,8 @@ cfdemCloud::cfdemCloud turbulenceModelType_ ) ), + intParticleProperties(8), + doubleParticleProperties(8), dataExchangeModel_ ( dataExchangeModel::New @@ -402,6 +404,25 @@ cfdemCloud::~cfdemCloud() if(getParticleDensities_) dataExchangeM().destroy(particleDensities_,1); if(getParticleEffVolFactors_) dataExchangeM().destroy(particleEffVolFactors_,1); if(getParticleTypes_) dataExchangeM().destroy(particleTypes_,1); + + for + ( + HashTable::iterator iter = intParticleProperties.begin(); + iter != intParticleProperties.end(); + ++iter + ) + { + dataExchangeM().destroy(*iter,-1); + } + for + ( + HashTable::iterator iter = doubleParticleProperties.begin(); + iter != doubleParticleProperties.end(); + ++iter + ) + { + dataExchangeM().destroy(*iter,-1); + } } // * * * * * * * * * * * * * * * private Member Functions * * * * * * * * * * * * * // diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H index 0b0d02ee..4bf11ab8 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H @@ -188,6 +188,9 @@ protected: const turbulenceModel& turbulence_; + HashTable intParticleProperties; + HashTable doubleParticleProperties; + autoPtr dataExchangeModel_; PtrList forceModel_; @@ -443,6 +446,14 @@ public: void otherForces(volVectorField&); bool checkPeriodicCells() const { return checkPeriodicCells_; } + + template + void registerParticleVectorProperty(const word& property); + template + T**& getParticleVectorPropertyRef(const word& property); +protected: + virtual int**& getParticleVectorPropertyImpl(const word& property, int**); + virtual double**& getParticleVectorPropertyImpl(const word& property, double**); }; diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H index 5c9d426f..169a7a9f 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H @@ -403,5 +403,40 @@ inline const turbulenceModel& cfdemCloud::turbulence() const return turbulence_; } +template +void cfdemCloud::registerParticleVectorProperty(const word& property) +{ + FatalError << "Trying to register particle vector property of unsupported type" << endl; +} + +template<> inline +void cfdemCloud::registerParticleVectorProperty(const word& property) +{ + intParticleProperties.insert(property, (int**)NULL); +} + +template<> inline +void cfdemCloud::registerParticleVectorProperty(const word& property) +{ + doubleParticleProperties.insert(property, (double**)NULL); +} + + +template +T**& cfdemCloud::getParticleVectorPropertyRef(const word& property) +{ + return getParticleVectorPropertyImpl(property, (T**)NULL); +} + +inline int**& cfdemCloud::getParticleVectorPropertyImpl(const word& property, int**) +{ + return intParticleProperties[property]; +} + +inline double**& cfdemCloud::getParticleVectorPropertyImpl(const word& property, double**) +{ + return doubleParticleProperties[property]; +} + } // ************************************************************************* // diff --git a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/GaussVoidFraction/GaussVoidFraction.C b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/GaussVoidFraction/GaussVoidFraction.C index 9a8c5a22..9ea66ad1 100644 --- a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/GaussVoidFraction/GaussVoidFraction.C +++ b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/GaussVoidFraction/GaussVoidFraction.C @@ -103,12 +103,12 @@ void GaussVoidFraction::setvoidFraction(double** const& mask,double**& voidfract //if(mask[index][0]) //{ //reset - for(int subcell=0;subcell 0) { - cellsPerParticle_[index][0]=hashSetLength; + cellsPerParticle()[index][0]=hashSetLength; //making sure that the cell containing the center is the first subcell particleCloud_.cellIDs()[index][0]=particleCenterCellID; @@ -200,7 +200,7 @@ void GaussVoidFraction::setvoidFraction(double** const& mask,double**& voidfract //bringing eulerian field to particle array for(label index=0; index< particleCloud_.numberOfParticles(); index++) { - for(label subcell=0;subcell 0) { - cellsPerParticle_[index][0]=hashSetLength; + cellsPerParticle()[index][0]=hashSetLength; hashSett.erase(particleCenterCellID); for (label i=0; i < hashSetLength-1; i++) @@ -281,7 +281,7 @@ void IBVoidFraction::setvoidFraction(double** const& mask,double**& voidfraction for (label index=0; index < particleCloud_.numberOfParticles(); index++) { - for (label subcell=0; subcell < cellsPerParticle_[index][0]; subcell++) + for (label subcell=0; subcell < cellsPerParticle()[index][0]; subcell++) { label cellID = particleCloud_.cellIDs()[index][subcell]; diff --git a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/bigParticleVoidFraction/bigParticleVoidFraction.C b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/bigParticleVoidFraction/bigParticleVoidFraction.C index 4d254b42..3a6f263a 100644 --- a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/bigParticleVoidFraction/bigParticleVoidFraction.C +++ b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/bigParticleVoidFraction/bigParticleVoidFraction.C @@ -102,12 +102,12 @@ void bigParticleVoidFraction::setvoidFraction(double** const& mask,double**& voi //if(mask[index][0]) //{ //reset - for(int subcell=0;subcell 0) { - cellsPerParticle_[index][0]=hashSetLength; + cellsPerParticle()[index][0]=hashSetLength; //making sure that the cell containing the center is the first subcell particleCloud_.cellIDs()[index][0]=particleCenterCellID; @@ -190,7 +190,7 @@ void bigParticleVoidFraction::setvoidFraction(double** const& mask,double**& voi //bringing eulerian field to particle array for(label index=0; index< particleCloud_.numberOfParticles(); index++) { - for(label subcell=0;subcellscreen,"cellID=%d, partCellId=%d\n",static_cast(cellID),static_cast(partCellId)); if(partCellId!=cellID) @@ -35,7 +35,7 @@ scalar partCellVol = particleCloud_.mesh().V()[partCellId]; scalar particleVolume = volume/static_cast(nPoints); scalar newAlpha = voidfractionNext_[partCellId]- particleVolume / partCellVol; - + if(newAlpha > alphaMin_) voidfractionNext_[partCellId] = newAlpha; else { @@ -49,9 +49,9 @@ // add sub particle representation bool createNew = true; label storeInIndex=0; - for(int i=0; i < cellsPerParticle_[index][0] ; i++) + for(int i=0; i < cellsPerParticle()[index][0] ; i++) { - if(partCellId == particleCloud_.cellIDs()[index][i]) + if(partCellId == particleCloud_.cellIDs()[index][i]) { storeInIndex = i; createNew = false; @@ -61,8 +61,8 @@ if(createNew) { - cellsPerParticle_[index][0] ++; - storeInIndex = cellsPerParticle_[index][0]-1; + cellsPerParticle()[index][0] ++; + storeInIndex = cellsPerParticle()[index][0]-1; particleCloud_.cellIDs()[index][storeInIndex] = partCellId; } diff --git a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/trilinearVoidFraction/trilinearVoidFraction.C b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/trilinearVoidFraction/trilinearVoidFraction.C index 7cbc8bbd..e47d1def 100644 --- a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/trilinearVoidFraction/trilinearVoidFraction.C +++ b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/trilinearVoidFraction/trilinearVoidFraction.C @@ -131,7 +131,7 @@ void trilinearVoidFraction::setvoidFraction(double** const& mask,double**& voidf for(int index = 0; index < particleCloud_.numberOfParticles(); ++index) { // reset - cellsPerParticle_[index][0] = 8; + cellsPerParticle()[index][0] = 8; //TODO do we need to set particleVolumes, particleV? // === diff --git a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.C b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.C index b07d9667..7cdafb8d 100644 --- a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.C +++ b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.C @@ -84,12 +84,11 @@ voidFractionModel::voidFractionModel /*sm.mesh(), dimensionedScalar("zero", dimensionSet(0,0,0,0,0), 1)*/ ), - cellsPerParticle_(NULL), maxCellsPerParticle_(1), weight_(1.), porosity_(1.) { - particleCloud_.dataExchangeM().allocateArray(cellsPerParticle_,1,1); + particleCloud_.registerParticleVectorProperty("cellsPerParticle"); if (particleCloud_.getParticleEffVolFactors()) multiWeights_ = true; } @@ -128,19 +127,17 @@ voidFractionModel::voidFractionModel sm.mesh(), dimensionedScalar("zero", dimensionSet(0,0,0,0,0), initVoidfraction) ), - cellsPerParticle_(NULL), maxCellsPerParticle_(1), weight_(1.), porosity_(1.) { - particleCloud_.dataExchangeM().allocateArray(cellsPerParticle_,1,1); + particleCloud_.registerParticleVectorProperty("cellsPerParticle"); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // voidFractionModel::~voidFractionModel() { - particleCloud_.dataExchangeM().destroy(cellsPerParticle_,1); } // * * * * * * * * * * * * * * public Member Functions * * * * * * * * * * * * * // @@ -162,7 +159,7 @@ void voidFractionModel::resetVoidFractions() int** const& voidFractionModel::cellsPerParticle() const { - return cellsPerParticle_; + return particleCloud_.getParticleVectorPropertyRef("cellsPerParticle"); } int voidFractionModel::maxCellsPerParticle() const @@ -175,7 +172,8 @@ void voidFractionModel::reAllocArrays() if(particleCloud_.numberOfParticlesChanged()) { // get arrays of new length - particleCloud_.dataExchangeM().allocateArray(cellsPerParticle_,1,1); + particleCloud_.dataExchangeM().allocateArray( + particleCloud_.getParticleVectorPropertyRef("cellsPerParticle"),1,1); } } @@ -184,7 +182,8 @@ void voidFractionModel::reAllocArrays(int nP) if(particleCloud_.numberOfParticlesChanged()) { // get arrays of new length - particleCloud_.dataExchangeM().allocateArray(cellsPerParticle_,1,1,nP); + particleCloud_.dataExchangeM().allocateArray( + particleCloud_.getParticleVectorPropertyRef("cellsPerParticle"),1,1,nP); } } diff --git a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.H b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.H index 5e148fb2..11fd735b 100644 --- a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.H +++ b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.H @@ -69,7 +69,6 @@ protected: volScalarField voidfractionNext_; - int ** cellsPerParticle_; int maxCellsPerParticle_;