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_
|
turbulenceModelType_
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
intParticleProperties(8),
|
particlePropertyTable(32),
|
||||||
doubleParticleProperties(8),
|
|
||||||
dataExchangeModel_
|
dataExchangeModel_
|
||||||
(
|
(
|
||||||
dataExchangeModel::New
|
dataExchangeModel::New
|
||||||
@ -407,21 +406,18 @@ cfdemCloud::~cfdemCloud()
|
|||||||
|
|
||||||
for
|
for
|
||||||
(
|
(
|
||||||
HashTable<int**>::iterator iter = intParticleProperties.begin();
|
HashTable<particleProperty>::iterator iter = particlePropertyTable.begin();
|
||||||
iter != intParticleProperties.end();
|
iter != particlePropertyTable.end();
|
||||||
++iter
|
++iter
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
dataExchangeM().destroy(*iter,-1);
|
if ((*(iter().ti)) == typeid(int**)) {
|
||||||
}
|
dataExchangeM().destroy(iter().ref<int**>(),-1);
|
||||||
for
|
} else if ((*(iter().ti)) == typeid(double**)) {
|
||||||
(
|
dataExchangeM().destroy(iter().ref<double**>(),-1);
|
||||||
HashTable<double**>::iterator iter = doubleParticleProperties.begin();
|
} else {
|
||||||
iter != doubleParticleProperties.end();
|
FatalError << "Trying to destroy property of type " << iter().ti->name() << endl;
|
||||||
++iter
|
}
|
||||||
)
|
|
||||||
{
|
|
||||||
dataExchangeM().destroy(*iter,-1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,6 +45,7 @@ SourceFiles
|
|||||||
// choose version
|
// choose version
|
||||||
#include "OFversion.H"
|
#include "OFversion.H"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
#include "fvCFD.H"
|
#include "fvCFD.H"
|
||||||
#include "IFstream.H"
|
#include "IFstream.H"
|
||||||
@ -188,8 +189,17 @@ protected:
|
|||||||
|
|
||||||
const turbulenceModel& turbulence_;
|
const turbulenceModel& turbulence_;
|
||||||
|
|
||||||
HashTable<int**> intParticleProperties;
|
struct particleProperty {
|
||||||
HashTable<double**> doubleParticleProperties;
|
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_;
|
autoPtr<dataExchangeModel> dataExchangeModel_;
|
||||||
|
|
||||||
@ -448,12 +458,12 @@ public:
|
|||||||
bool checkPeriodicCells() const { return checkPeriodicCells_; }
|
bool checkPeriodicCells() const { return checkPeriodicCells_; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void registerParticleVectorProperty(const word& property);
|
void registerParticleProperty(const word& property);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T**& getParticleVectorPropertyRef(const word& property);
|
T& getParticlePropertyRef(const word& property);
|
||||||
protected:
|
protected:
|
||||||
virtual int**& getParticleVectorPropertyImpl(const word& property, int**);
|
virtual int**& getParticlePropertyImpl(const word& property, int**);
|
||||||
virtual double**& getParticleVectorPropertyImpl(const word& property, double**);
|
virtual double**& getParticlePropertyImpl(const word& property, double**);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -403,39 +403,27 @@ inline const turbulenceModel& cfdemCloud::turbulence() const
|
|||||||
return turbulence_;
|
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>
|
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.),
|
weight_(1.),
|
||||||
porosity_(1.)
|
porosity_(1.)
|
||||||
{
|
{
|
||||||
particleCloud_.registerParticleVectorProperty<int>("cellsPerParticle");
|
particleCloud_.registerParticleProperty<int**>("cellsPerParticle");
|
||||||
if (particleCloud_.getParticleEffVolFactors()) multiWeights_ = true;
|
if (particleCloud_.getParticleEffVolFactors()) multiWeights_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ voidFractionModel::voidFractionModel
|
|||||||
weight_(1.),
|
weight_(1.),
|
||||||
porosity_(1.)
|
porosity_(1.)
|
||||||
{
|
{
|
||||||
particleCloud_.registerParticleVectorProperty<int>("cellsPerParticle");
|
particleCloud_.registerParticleProperty<int**>("cellsPerParticle");
|
||||||
}
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
@ -159,7 +159,7 @@ void voidFractionModel::resetVoidFractions()
|
|||||||
|
|
||||||
int** const& voidFractionModel::cellsPerParticle() const
|
int** const& voidFractionModel::cellsPerParticle() const
|
||||||
{
|
{
|
||||||
return particleCloud_.getParticleVectorPropertyRef<int>("cellsPerParticle");
|
return particleCloud_.getParticlePropertyRef<int**>("cellsPerParticle");
|
||||||
}
|
}
|
||||||
|
|
||||||
int voidFractionModel::maxCellsPerParticle() const
|
int voidFractionModel::maxCellsPerParticle() const
|
||||||
@ -172,8 +172,7 @@ void voidFractionModel::reAllocArrays()
|
|||||||
if(particleCloud_.numberOfParticlesChanged())
|
if(particleCloud_.numberOfParticlesChanged())
|
||||||
{
|
{
|
||||||
// get arrays of new length
|
// get arrays of new length
|
||||||
particleCloud_.dataExchangeM().allocateArray(
|
particleCloud_.dataExchangeM().allocateArray(particleCloud_.getParticlePropertyRef<int**>("cellsPerParticle"),1,1);
|
||||||
particleCloud_.getParticleVectorPropertyRef<int>("cellsPerParticle"),1,1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,8 +181,7 @@ void voidFractionModel::reAllocArrays(int nP)
|
|||||||
if(particleCloud_.numberOfParticlesChanged())
|
if(particleCloud_.numberOfParticlesChanged())
|
||||||
{
|
{
|
||||||
// get arrays of new length
|
// get arrays of new length
|
||||||
particleCloud_.dataExchangeM().allocateArray(
|
particleCloud_.dataExchangeM().allocateArray(particleCloud_.getParticlePropertyRef<int**>("cellsPerParticle"),1,1,nP);
|
||||||
particleCloud_.getParticleVectorPropertyRef<int>("cellsPerParticle"),1,1,nP);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,6 @@ protected:
|
|||||||
|
|
||||||
volScalarField voidfractionNext_;
|
volScalarField voidfractionNext_;
|
||||||
|
|
||||||
|
|
||||||
int maxCellsPerParticle_;
|
int maxCellsPerParticle_;
|
||||||
|
|
||||||
scalar weight_;
|
scalar weight_;
|
||||||
|
|||||||
Reference in New Issue
Block a user