mirror of
https://github.com/ParticulateFlow/CFDEMcoupling-PFM.git
synced 2025-12-08 06:37:44 +00:00
streamline particle property registration
This commit is contained in:
@ -160,8 +160,7 @@ cfdemCloud::cfdemCloud
|
||||
turbulenceModelType_
|
||||
)
|
||||
),
|
||||
intParticleProperties(8),
|
||||
doubleParticleProperties(8),
|
||||
particlePropertyTable(32),
|
||||
dataExchangeModel_
|
||||
(
|
||||
dataExchangeModel::New
|
||||
@ -407,21 +406,18 @@ cfdemCloud::~cfdemCloud()
|
||||
|
||||
for
|
||||
(
|
||||
HashTable<int**>::iterator iter = intParticleProperties.begin();
|
||||
iter != intParticleProperties.end();
|
||||
HashTable<particleProperty>::iterator iter = particlePropertyTable.begin();
|
||||
iter != particlePropertyTable.end();
|
||||
++iter
|
||||
)
|
||||
{
|
||||
dataExchangeM().destroy(*iter,-1);
|
||||
}
|
||||
for
|
||||
(
|
||||
HashTable<double**>::iterator iter = doubleParticleProperties.begin();
|
||||
iter != doubleParticleProperties.end();
|
||||
++iter
|
||||
)
|
||||
{
|
||||
dataExchangeM().destroy(*iter,-1);
|
||||
if ((*(iter().ti)) == typeid(int**)) {
|
||||
dataExchangeM().destroy(iter().ref<int**>(),-1);
|
||||
} else if ((*(iter().ti)) == typeid(double**)) {
|
||||
dataExchangeM().destroy(iter().ref<double**>(),-1);
|
||||
} else {
|
||||
FatalError << "Trying to destroy property of type " << iter().ti->name() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -45,6 +45,7 @@ SourceFiles
|
||||
// choose version
|
||||
#include "OFversion.H"
|
||||
#include <vector>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "fvCFD.H"
|
||||
#include "IFstream.H"
|
||||
@ -188,8 +189,17 @@ protected:
|
||||
|
||||
const turbulenceModel& turbulence_;
|
||||
|
||||
HashTable<int**> intParticleProperties;
|
||||
HashTable<double**> doubleParticleProperties;
|
||||
struct particleProperty {
|
||||
void** property;
|
||||
const std::type_info* ti;
|
||||
template<typename T>
|
||||
T& ref() {
|
||||
if (*ti == typeid(T)) return *reinterpret_cast<T*>(&property);
|
||||
else throw std::bad_cast();
|
||||
}
|
||||
};
|
||||
|
||||
HashTable<particleProperty> particlePropertyTable;
|
||||
|
||||
autoPtr<dataExchangeModel> dataExchangeModel_;
|
||||
|
||||
@ -448,12 +458,12 @@ public:
|
||||
bool checkPeriodicCells() const { return checkPeriodicCells_; }
|
||||
|
||||
template<typename T>
|
||||
void registerParticleVectorProperty(const word& property);
|
||||
void registerParticleProperty(const word& property);
|
||||
template<typename T>
|
||||
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**);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -403,39 +403,27 @@ inline const turbulenceModel& cfdemCloud::turbulence() const
|
||||
return turbulence_;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void cfdemCloud::registerParticleVectorProperty(const word& property)
|
||||
{
|
||||
FatalError << "Trying to register particle vector property of unsupported type" << endl;
|
||||
}
|
||||
|
||||
template<> inline
|
||||
void cfdemCloud::registerParticleVectorProperty<int>(const word& property)
|
||||
{
|
||||
intParticleProperties.insert(property, (int**)NULL);
|
||||
}
|
||||
|
||||
template<> inline
|
||||
void cfdemCloud::registerParticleVectorProperty<double>(const word& property)
|
||||
{
|
||||
doubleParticleProperties.insert(property, (double**)NULL);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
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<typename T>
|
||||
T& cfdemCloud::getParticlePropertyRef(const word& property)
|
||||
{
|
||||
return intParticleProperties[property];
|
||||
return getParticlePropertyImpl(property, static_cast<T>(0));
|
||||
}
|
||||
|
||||
inline double**& cfdemCloud::getParticleVectorPropertyImpl(const word& property, double**)
|
||||
inline int**& cfdemCloud::getParticlePropertyImpl(const word& property, int**)
|
||||
{
|
||||
return doubleParticleProperties[property];
|
||||
return particlePropertyTable[property].ref<int**>();
|
||||
}
|
||||
|
||||
inline double**& cfdemCloud::getParticlePropertyImpl(const word& property, double**)
|
||||
{
|
||||
return particlePropertyTable[property].ref<double**>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ voidFractionModel::voidFractionModel
|
||||
weight_(1.),
|
||||
porosity_(1.)
|
||||
{
|
||||
particleCloud_.registerParticleVectorProperty<int>("cellsPerParticle");
|
||||
particleCloud_.registerParticleProperty<int**>("cellsPerParticle");
|
||||
if (particleCloud_.getParticleEffVolFactors()) multiWeights_ = true;
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ voidFractionModel::voidFractionModel
|
||||
weight_(1.),
|
||||
porosity_(1.)
|
||||
{
|
||||
particleCloud_.registerParticleVectorProperty<int>("cellsPerParticle");
|
||||
particleCloud_.registerParticleProperty<int**>("cellsPerParticle");
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
@ -159,7 +159,7 @@ void voidFractionModel::resetVoidFractions()
|
||||
|
||||
int** const& voidFractionModel::cellsPerParticle() const
|
||||
{
|
||||
return particleCloud_.getParticleVectorPropertyRef<int>("cellsPerParticle");
|
||||
return particleCloud_.getParticlePropertyRef<int**>("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<int>("cellsPerParticle"),1,1);
|
||||
particleCloud_.dataExchangeM().allocateArray(particleCloud_.getParticlePropertyRef<int**>("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<int>("cellsPerParticle"),1,1,nP);
|
||||
particleCloud_.dataExchangeM().allocateArray(particleCloud_.getParticlePropertyRef<int**>("cellsPerParticle"),1,1,nP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +69,6 @@ protected:
|
||||
|
||||
volScalarField voidfractionNext_;
|
||||
|
||||
|
||||
int maxCellsPerParticle_;
|
||||
|
||||
scalar weight_;
|
||||
|
||||
Reference in New Issue
Block a user