diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C index df719b60..36db2d47 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C @@ -160,6 +160,7 @@ cfdemCloud::cfdemCloud turbulenceModelType_ ) ), + particlePropertyTable(32), dataExchangeModel_ ( dataExchangeModel::New @@ -402,6 +403,22 @@ cfdemCloud::~cfdemCloud() if(getParticleDensities_) dataExchangeM().destroy(particleDensities_,1); if(getParticleEffVolFactors_) dataExchangeM().destroy(particleEffVolFactors_,1); if(getParticleTypes_) dataExchangeM().destroy(particleTypes_,1); + + for + ( + HashTable::iterator iter = particlePropertyTable.begin(); + iter != particlePropertyTable.end(); + ++iter + ) + { + 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; + } + } } // * * * * * * * * * * * * * * * private Member Functions * * * * * * * * * * * * * // @@ -780,9 +797,60 @@ bool cfdemCloud::reAllocArrays() if(getParticleDensities_) dataExchangeM().allocateArray(particleDensities_,0.,1); if(getParticleEffVolFactors_) dataExchangeM().allocateArray(particleEffVolFactors_,0.,1); if(getParticleTypes_) dataExchangeM().allocateArray(particleTypes_,0,1); + + for + ( + HashTable::iterator iter = particlePropertyTable.begin(); + iter != particlePropertyTable.end(); + ++iter + ) + { + if (iter().size > 0) { + ///Info << "!! about to realloc property of type " << iter().ti->name() << endl; + if ((*(iter().ti)) == typeid(int**)) { + dataExchangeM().allocateArray(iter().ref(),iter().initVal,iter().size); + } else if ((*(iter().ti)) == typeid(double**)) { + dataExchangeM().allocateArray(iter().ref(),iter().initVal,iter().size); + } else { + FatalError << "Trying to realloc property of type " << iter().ti->name() << endl; + } + } + } + arraysReallocated_ = true; return true; } + else + { + for + ( + HashTable::iterator iter = particlePropertyTable.begin(); + iter != particlePropertyTable.end(); + ++iter + ) + { + if (iter().size > 0 && iter().reset) { + if ((*(iter().ti)) == typeid(int**)) { + int**& property = iter().ref(); + for (int index=0; index(); + for (int index=0; indexname() << endl; + } + } + } + } + return false; } diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.H index 0b0d02ee..636c2c18 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,6 +189,21 @@ protected: const turbulenceModel& turbulence_; + struct particleProperty { + void** property; // pointer to per-particle data; memory deallocation by cfdemCloud + const std::type_info* ti; // type of particle data (int**, double**) + int size; // size of single particle data; memory allocation by cfdemCloud if size > 0 + double initVal; // initial property value + bool reset; // if true, data is reset to initial value every coupling step + template + T& ref() { + if (*ti == typeid(T)) return *reinterpret_cast(&property); + else throw std::bad_cast(); + } + }; + + HashTable particlePropertyTable; // table of registered per-particle properties + autoPtr dataExchangeModel_; PtrList forceModel_; @@ -443,6 +459,14 @@ public: void otherForces(volVectorField&); bool checkPeriodicCells() const { return checkPeriodicCells_; } + + template + void registerParticleProperty(const word& property, int size=0, double initVal=0.0, bool reset=true); + template + T& getParticlePropertyRef(const word& property); +protected: + 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 5c9d426f..dc3a4125 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H @@ -403,5 +403,28 @@ inline const turbulenceModel& cfdemCloud::turbulence() const return turbulence_; } + +template +void cfdemCloud::registerParticleProperty(const word& property, int size, double initVal, bool reset) +{ + particlePropertyTable.insert(property,{NULL,&typeid(T),size,initVal,reset}); +} + +template +T& cfdemCloud::getParticlePropertyRef(const word& property) +{ + return getParticlePropertyImpl(property, static_cast(0)); +} + +inline int**& cfdemCloud::getParticlePropertyImpl(const word& property, int**) +{ + return particlePropertyTable[property].ref(); +} + +inline double**& cfdemCloud::getParticlePropertyImpl(const word& property, double**) +{ + return particlePropertyTable[property].ref(); +} + } // ************************************************************************* // diff --git a/src/lagrangian/cfdemParticle/subModels/chemistryModel/diffusionCoefficients/diffusionCoefficients.C b/src/lagrangian/cfdemParticle/subModels/chemistryModel/diffusionCoefficients/diffusionCoefficients.C index 9ce61c26..3ad1a38b 100644 --- a/src/lagrangian/cfdemParticle/subModels/chemistryModel/diffusionCoefficients/diffusionCoefficients.C +++ b/src/lagrangian/cfdemParticle/subModels/chemistryModel/diffusionCoefficients/diffusionCoefficients.C @@ -71,15 +71,17 @@ diffusionCoefficient::diffusionCoefficient pressureFieldName_(propsDict_.lookupOrDefault("pressureFieldName","p")), P_(sm.mesh().lookupObject(pressureFieldName_)), partPressureName_(propsDict_.lookupOrDefault("partPressureName","partP")), - partPressure_(NULL), X_(speciesNames_.size()), diffusantGasNames_(propsDict_.lookup("diffusantGasNames")), - diffusionCoefficients_(diffusantGasNames_.size(),NULL), Xdiffusant_(diffusantGasNames_.size()), initialized_(false) { particleCloud_.checkCG(false); - allocateMyArrays(); + particleCloud_.registerParticleProperty(partPressureName_,1); + for (int i=0; i(diffusantGasNames_[i],1); + } createCoeffs(); molWeightTable(); } @@ -88,37 +90,10 @@ diffusionCoefficient::diffusionCoefficient diffusionCoefficient::~diffusionCoefficient() { - particleCloud_.dataExchangeM().destroy(partPressure_,1); - for (int i=0; i 0) - { - particleCloud_.dataExchangeM().allocateArray(partPressure_,initVal,1,"nparticles"); - for (int i=0; i TInterpolator_(tempField_); interpolationCellPoint PInterpolator_(P_); + double**& partPressure_ = particleCloud_.getParticlePropertyRef(partPressureName_); + for (int index=0; index(diffusantGasNames_[j]); TotalFraction_[j] = 0.0; dBinary_ = 0.0; @@ -243,9 +218,9 @@ void diffusionCoefficient::execute() // pass on dCoeff values to array if (TotalFraction_[j] < VSMALL) - diffusionCoefficients_[j][index][0] = VSMALL; + diffusionCoefficients_[index][0] = VSMALL; else - diffusionCoefficients_[j][index][0] = (1.0 - Xdiffusant_[j][cellI]) / TotalFraction_[j]; + diffusionCoefficients_[index][0] = (1.0 - Xdiffusant_[j][cellI]) / TotalFraction_[j]; } else { @@ -258,7 +233,7 @@ void diffusionCoefficient::execute() } if(verbose_) - Info << "diffusionCoefficient of species " << diffusantGasNames_[j] << " = " << diffusionCoefficients_[j][index][0] << endl; + Info << "diffusionCoefficient of species " << diffusantGasNames_[j] << " = " << diffusionCoefficients_[index][0] << endl; } } } @@ -268,7 +243,8 @@ void diffusionCoefficient::execute() for (int j=0; j(diffusantGasNames_[j]); + particleCloud_.dataExchangeM().giveData(pushName,"scalar-atom",diffusionCoefficients_); } Info << "give data done" << endl; diff --git a/src/lagrangian/cfdemParticle/subModels/chemistryModel/diffusionCoefficients/diffusionCoefficients.H b/src/lagrangian/cfdemParticle/subModels/chemistryModel/diffusionCoefficients/diffusionCoefficients.H index c8e9b1cf..72ad8a68 100644 --- a/src/lagrangian/cfdemParticle/subModels/chemistryModel/diffusionCoefficients/diffusionCoefficients.H +++ b/src/lagrangian/cfdemParticle/subModels/chemistryModel/diffusionCoefficients/diffusionCoefficients.H @@ -76,19 +76,15 @@ private: word partPressureName_; - mutable double **partPressure_; - UPtrList X_; wordList diffusantGasNames_; - mutable List diffusionCoefficients_; - UPtrList Xdiffusant_; - HashTable coeffs; + HashTable coeffs; - HashTable molWeight; + HashTable molWeight; void createCoeffs(); @@ -100,8 +96,6 @@ private: // calculate denominator part diffusion volume equation double calcDiffVol(int, int); - void allocateMyArrays() const; - bool initialized_; void init(); @@ -126,8 +120,6 @@ private: // Member Functions void execute(); - - void reAllocMyArrays() const; }; diff --git a/src/lagrangian/cfdemParticle/subModels/chemistryModel/massTransferCoeff/massTransferCoeff.C b/src/lagrangian/cfdemParticle/subModels/chemistryModel/massTransferCoeff/massTransferCoeff.C index 2f49a729..2293e7bf 100644 --- a/src/lagrangian/cfdemParticle/subModels/chemistryModel/massTransferCoeff/massTransferCoeff.C +++ b/src/lagrangian/cfdemParticle/subModels/chemistryModel/massTransferCoeff/massTransferCoeff.C @@ -63,51 +63,26 @@ massTransferCoeff::massTransferCoeff densityFieldName_(propsDict_.lookupOrDefault("densityFieldName","rho")), rho_(sm.mesh().lookupObject (densityFieldName_)), partNuName_(propsDict_.lookupOrDefault("partViscos","partNu")), - partNu_(NULL), - partReynolds_(propsDict_.lookupOrDefault("partReynolds","partRe")), - partRe_(NULL), + partReName_(propsDict_.lookupOrDefault("partReynolds","partRe")), scaleDia_(1) { particleCloud_.checkCG(true); - allocateMyArrays(); + particleCloud_.registerParticleProperty(partNuName_,1); + particleCloud_.registerParticleProperty(partReName_,1); } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // massTransferCoeff::~massTransferCoeff() { - int nP_ = particleCloud_.numberOfParticles(); - - particleCloud_.dataExchangeM().destroy(partNu_,nP_); - particleCloud_.dataExchangeM().destroy(partRe_,nP_); } // * * * * * * * * * * * * * * * private Member Functions * * * * * * * * * * * * * // -void massTransferCoeff::allocateMyArrays() const -{ - double initVal=0.0; - if (particleCloud_.dataExchangeM().maxNumberOfParticles() > 0) - { - // get memory for 2d arrays - particleCloud_.dataExchangeM().allocateArray(partNu_,initVal,1,"nparticles"); - particleCloud_.dataExchangeM().allocateArray(partRe_,initVal,1,"nparticles"); - } -} - -void massTransferCoeff::reAllocMyArrays() const -{ - double initVal=0.0; - particleCloud_.dataExchangeM().allocateArray(partNu_,initVal,1); - particleCloud_.dataExchangeM().allocateArray(partRe_,initVal,1); -} // * * * * * * * * * * * * * * * * Member Fct * * * * * * * * * * * * * * * // void massTransferCoeff::execute() { - // realloc the arrays - reAllocMyArrays(); - #ifdef compre const volScalarField nufField = particleCloud_.turbulence().mu()/rho_; #else @@ -139,6 +114,9 @@ void massTransferCoeff::execute() interpolationCellPoint UluidInterpolator_(U_); interpolationCellPoint voidfractionInterpolator_(voidfraction_); + double**& partNu_ = particleCloud_.getParticlePropertyRef(partNuName_); + double**& partRe_ = particleCloud_.getParticlePropertyRef(partReName_); + for (int index=0; index("verbose",false)), - reactantPerParticle_(NULL), + partReactantName_("reactantPerParticle"), voidfractionFieldName_(propsDict_.lookupOrDefault("voidfractionFieldName","voidfraction")), voidfraction_(sm.mesh().lookupObject(voidfractionFieldName_)), particlesPerCell_ @@ -76,32 +76,16 @@ reactantPerParticle::reactantPerParticle Nevery_(propsDict_.lookupOrDefault