diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C index 893a392b..27b07c6e 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C @@ -160,8 +160,7 @@ cfdemCloud::cfdemCloud turbulenceModelType_ ) ), - intParticleProperties(8), - doubleParticleProperties(8), + particlePropertyTable(32), dataExchangeModel_ ( dataExchangeModel::New @@ -407,21 +406,18 @@ cfdemCloud::~cfdemCloud() for ( - HashTable::iterator iter = intParticleProperties.begin(); - iter != intParticleProperties.end(); + HashTable::iterator iter = particlePropertyTable.begin(); + iter != particlePropertyTable.end(); ++iter ) { - dataExchangeM().destroy(*iter,-1); - } - for - ( - HashTable::iterator iter = doubleParticleProperties.begin(); - iter != doubleParticleProperties.end(); - ++iter - ) - { - dataExchangeM().destroy(*iter,-1); + if ((*(iter().ti)) == typeid(int**)) { + dataExchangeM().destroy(iter().ref(),-1); + } else if ((*(iter().ti)) == typeid(double**)) { + dataExchangeM().destroy(iter().ref(),-1); + } else { + FatalError << "Trying to destroy property of type " << iter().ti->name() << endl; + } } } diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H index 4bf11ab8..49762ced 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H @@ -45,6 +45,7 @@ SourceFiles // choose version #include "OFversion.H" #include +#include #include "fvCFD.H" #include "IFstream.H" @@ -188,8 +189,17 @@ protected: const turbulenceModel& turbulence_; - HashTable intParticleProperties; - HashTable doubleParticleProperties; + struct particleProperty { + void** property; + const std::type_info* ti; + template + T& ref() { + if (*ti == typeid(T)) return *reinterpret_cast(&property); + else throw std::bad_cast(); + } + }; + + HashTable particlePropertyTable; autoPtr dataExchangeModel_; @@ -448,12 +458,12 @@ public: bool checkPeriodicCells() const { return checkPeriodicCells_; } template - void registerParticleVectorProperty(const word& property); + void registerParticleProperty(const word& property); template - T**& getParticleVectorPropertyRef(const word& property); + T& getParticlePropertyRef(const word& property); protected: - virtual int**& getParticleVectorPropertyImpl(const word& property, int**); - virtual double**& getParticleVectorPropertyImpl(const word& property, double**); + virtual int**& getParticlePropertyImpl(const word& property, int**); + virtual double**& getParticlePropertyImpl(const word& property, double**); }; diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H index 169a7a9f..88a00208 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H @@ -403,39 +403,27 @@ 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) +void cfdemCloud::registerParticleProperty(const word& property) { - return getParticleVectorPropertyImpl(property, (T**)NULL); + particlePropertyTable.insert(property,{NULL,&typeid(T)}); } -inline int**& cfdemCloud::getParticleVectorPropertyImpl(const word& property, int**) +template +T& cfdemCloud::getParticlePropertyRef(const word& property) { - return intParticleProperties[property]; + return getParticlePropertyImpl(property, static_cast(0)); } -inline double**& cfdemCloud::getParticleVectorPropertyImpl(const word& property, double**) +inline int**& cfdemCloud::getParticlePropertyImpl(const word& property, int**) { - return doubleParticleProperties[property]; + return particlePropertyTable[property].ref(); +} + +inline double**& cfdemCloud::getParticlePropertyImpl(const word& property, double**) +{ + return particlePropertyTable[property].ref(); } } diff --git a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.C b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.C index 7cdafb8d..d333e26e 100644 --- a/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.C +++ b/src/lagrangian/cfdemParticle/subModels/voidFractionModel/voidFractionModel/voidFractionModel.C @@ -88,7 +88,7 @@ voidFractionModel::voidFractionModel weight_(1.), porosity_(1.) { - particleCloud_.registerParticleVectorProperty("cellsPerParticle"); + particleCloud_.registerParticleProperty("cellsPerParticle"); if (particleCloud_.getParticleEffVolFactors()) multiWeights_ = true; } @@ -131,7 +131,7 @@ voidFractionModel::voidFractionModel weight_(1.), porosity_(1.) { - particleCloud_.registerParticleVectorProperty("cellsPerParticle"); + particleCloud_.registerParticleProperty("cellsPerParticle"); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // @@ -159,7 +159,7 @@ void voidFractionModel::resetVoidFractions() int** const& voidFractionModel::cellsPerParticle() const { - return particleCloud_.getParticleVectorPropertyRef("cellsPerParticle"); + return particleCloud_.getParticlePropertyRef("cellsPerParticle"); } int voidFractionModel::maxCellsPerParticle() const @@ -172,8 +172,7 @@ void voidFractionModel::reAllocArrays() if(particleCloud_.numberOfParticlesChanged()) { // get arrays of new length - particleCloud_.dataExchangeM().allocateArray( - particleCloud_.getParticleVectorPropertyRef("cellsPerParticle"),1,1); + particleCloud_.dataExchangeM().allocateArray(particleCloud_.getParticlePropertyRef("cellsPerParticle"),1,1); } } @@ -182,8 +181,7 @@ void voidFractionModel::reAllocArrays(int nP) if(particleCloud_.numberOfParticlesChanged()) { // get arrays of new length - particleCloud_.dataExchangeM().allocateArray( - particleCloud_.getParticleVectorPropertyRef("cellsPerParticle"),1,1,nP); + particleCloud_.dataExchangeM().allocateArray(particleCloud_.getParticlePropertyRef("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 11fd735b..d3c57d81 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 maxCellsPerParticle_; scalar weight_;