mirror of
https://github.com/ParticulateFlow/CFDEMcoupling-PFM.git
synced 2025-12-08 06:37:44 +00:00
fix up probe model
remove internal vProbes and sProbes and corresponding getter functions since the data structures are unsuitable and they are not used anywhere else; remove misleading const specifiers from methods and the excruciating mutable specifiers; use const references as parameters where appropriate;
This commit is contained in:
@ -1,3 +1,2 @@
|
||||
//set probeModel parameters for this force model
|
||||
particleCloud_.probeM().setOutputFile();
|
||||
particleCloud_.probeM().setCounter();
|
||||
//set probeModel parameters for this force model
|
||||
if (probeIt_) { particleCloud_.probeM().setOutputFile(typeName+".logDat"); }
|
||||
|
||||
@ -497,16 +497,6 @@ label cfdemCloud::liggghtsCommandModelIndex(word name)
|
||||
return index;
|
||||
}
|
||||
|
||||
std::vector< std::vector<double*> >* cfdemCloud::getVprobe()
|
||||
{
|
||||
return probeModel_->getVprobe();
|
||||
}
|
||||
|
||||
std::vector< std::vector<double> >* cfdemCloud::getSprobe()
|
||||
{
|
||||
return probeModel_->getSprobe();
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * WRITE * * * * * * * * * * * * * //
|
||||
|
||||
// * * * write cfdemCloud internal data * * * //
|
||||
|
||||
@ -49,7 +49,7 @@ SourceFiles
|
||||
#include "fvCFD.H"
|
||||
#include "IFstream.H"
|
||||
|
||||
#include <turbulenceModel.H>
|
||||
#include "turbulenceModel.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -351,7 +351,7 @@ public:
|
||||
|
||||
inline const IOModel& IOM() const;
|
||||
|
||||
inline const probeModel& probeM() const;
|
||||
inline probeModel& probeM();
|
||||
|
||||
inline const averagingModel& averagingM() const;
|
||||
|
||||
@ -394,10 +394,6 @@ public:
|
||||
|
||||
void resetArray(double**&,int,int,double resetVal=0.);
|
||||
|
||||
std::vector< std::vector<double*> >* getVprobe();
|
||||
|
||||
std::vector< std::vector<double> >* getSprobe();
|
||||
|
||||
void otherForces(volVectorField&);
|
||||
};
|
||||
|
||||
|
||||
@ -262,9 +262,9 @@ inline const IOModel& cfdemCloud::IOM() const
|
||||
return IOModel_;
|
||||
}
|
||||
|
||||
inline const probeModel& cfdemCloud::probeM() const
|
||||
inline probeModel& cfdemCloud::probeM()
|
||||
{
|
||||
return probeModel_;
|
||||
return probeModel_();
|
||||
}
|
||||
|
||||
inline const voidFractionModel& cfdemCloud::voidFractionM() const
|
||||
|
||||
@ -87,12 +87,12 @@ particleProbe::particleProbe
|
||||
if (propsDict_.found("verbose")) verbose_=true;
|
||||
if (propsDict_.found("verboseToFile")) verboseToFile_=true;
|
||||
|
||||
if (propsDict_.found("printEvery")) printEvery_= readScalar(propsDict_.lookup("printEvery"));
|
||||
if (propsDict_.found("sampleAll")) sampleAll_=true;
|
||||
if (propsDict_.found("probeDebug")) probeDebug_=true;
|
||||
if (propsDict_.found("includePosition")) includePosition_=true;
|
||||
if (propsDict_.found("printEvery")) printEvery_ = readScalar(propsDict_.lookup("printEvery"));
|
||||
if (propsDict_.found("sampleAll")) sampleAll_ = true;
|
||||
if (propsDict_.found("probeDebug")) probeDebug_ = true;
|
||||
if (propsDict_.found("includePosition")) includePosition_ = true;
|
||||
|
||||
if (propsDict_.found("writePrecision")) writePrecision_= readScalar(propsDict_.lookup("writePrecision"));
|
||||
if (propsDict_.found("writePrecision")) writePrecision_ = readScalar(propsDict_.lookup("writePrecision"));
|
||||
|
||||
}
|
||||
|
||||
@ -100,25 +100,36 @@ particleProbe::particleProbe
|
||||
|
||||
particleProbe::~particleProbe()
|
||||
{
|
||||
clearProbes();
|
||||
forAll(sPtrList_, i)
|
||||
delete sPtrList_[i];
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void particleProbe::setOutputFile() const
|
||||
void particleProbe::setOutputFile(const word& logFileName)
|
||||
{
|
||||
//set the current item ID
|
||||
if(currItemId_== itemCounter_)
|
||||
currItemId_=1;
|
||||
else
|
||||
currItemId_+=1;
|
||||
sPtr = sPtrList_[currItemId_-1]; //set the pointer to the output file from list
|
||||
probeIndex_=currItemId_-1;
|
||||
if (itemCounter_ > 0 && verboseToFile_)
|
||||
{
|
||||
bool foundFile = false;
|
||||
forAll(itemsToSample_, i)
|
||||
{
|
||||
if (itemsToSample_[i] == logFileName)
|
||||
{
|
||||
probeIndex_ = i;
|
||||
foundFile = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundFile)
|
||||
FatalError << "particleProbe::setOutputFile for logFileName " << logFileName << " : " << "File not found" << abort(FatalError);
|
||||
currItemId_ = probeIndex_ + 1;
|
||||
setCounter();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void particleProbe::initialize(word typeName, word logFileName) const
|
||||
void particleProbe::initialize(const word& modelName, const word& logFileName)
|
||||
{
|
||||
//update the list of items to be sampled
|
||||
++itemCounter_;
|
||||
@ -126,7 +137,7 @@ void particleProbe::initialize(word typeName, word logFileName) const
|
||||
|
||||
// init environment
|
||||
//propsDict_ = particleCloud_.couplingProperties().subDict(typeName + "Props");
|
||||
name_ = typeName;
|
||||
name_ = modelName;
|
||||
|
||||
if (verboseToFile_)
|
||||
{
|
||||
@ -136,8 +147,8 @@ void particleProbe::initialize(word typeName, word logFileName) const
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank_);
|
||||
|
||||
//open a separate file for each processor
|
||||
char* filecurrent_ = new char[strlen(logFileName.c_str()) + 4]; //reserve 4 chars for processor name
|
||||
sprintf(filecurrent_,"%s%s%d", logFileName.c_str(), ".", rank_);
|
||||
char* filecurrent_ = new char[logFileName.length() + 1 + 4 + 1]; //reserve 4 chars for processor name
|
||||
sprintf(filecurrent_,"%s.%d", logFileName.c_str(), rank_);
|
||||
|
||||
Info << "particleProbe for model " << name_ << " will write to file " << filecurrent_ << endl;
|
||||
|
||||
@ -171,120 +182,44 @@ void particleProbe::initialize(word typeName, word logFileName) const
|
||||
scalarFields_.clear();
|
||||
vectorFields_.clear();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void particleProbe::writeHeader() const
|
||||
{
|
||||
if (verboseToFile_)
|
||||
{
|
||||
*sPtr << "#processor: " << rank_ << endl;
|
||||
*sPtr << "#index time " << " ";
|
||||
*sPtr << "|| vectorData: " << " ";
|
||||
|
||||
if(verboseToFile_ )
|
||||
{
|
||||
*sPtr<<"#processor: " << rank_ << endl;
|
||||
*sPtr<<"#index time " << " ";
|
||||
forAll(vectorFields_, iter)
|
||||
{
|
||||
if (!probeDebug_ && iter > 0) break;
|
||||
*sPtr << vectorFields_(iter) << " ";
|
||||
}
|
||||
|
||||
|
||||
*sPtr<<"|| vectorData: " << " ";
|
||||
|
||||
forAll(vectorFields_, iter)
|
||||
{
|
||||
if(!probeDebug_ && iter>0) break;
|
||||
*sPtr << vectorFields_(iter) << " ";
|
||||
}
|
||||
|
||||
if(probeDebug_)
|
||||
{
|
||||
*sPtr<<"|| scalarData: " << " ";
|
||||
if (probeDebug_)
|
||||
{
|
||||
*sPtr << "|| scalarData: " << " ";
|
||||
forAll(scalarFields_, iter)
|
||||
{
|
||||
*sPtr << scalarFields_(iter) << " ";
|
||||
*sPtr << scalarFields_(iter) << " ";
|
||||
}
|
||||
}
|
||||
|
||||
if(includePosition_) *sPtr<<" || position" << endl;
|
||||
else *sPtr << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void particleProbe::clearProbes() const
|
||||
{
|
||||
for (unsigned int i=0; i<vProbes_.size(); i++)
|
||||
vProbes_[i].clear();
|
||||
|
||||
for (unsigned int j=0; j<sProbes_.size(); j++)
|
||||
sProbes_[j].clear();
|
||||
|
||||
sProbes_.clear();
|
||||
vProbes_.clear();
|
||||
}
|
||||
|
||||
void particleProbe::updateProbes(int index, Field<scalar> sValues, Field<vector> vValues) const
|
||||
{
|
||||
int vSize_=vProbes_.size();
|
||||
int sSize_=sProbes_.size();
|
||||
|
||||
//check if the particle already has an allocated vector. If not, create it. It should be only called at the beginning.
|
||||
while(index >= vSize_)
|
||||
{
|
||||
std::vector<double*> particleVector_;
|
||||
vProbes_.push_back(particleVector_);
|
||||
vSize_=vProbes_.size();
|
||||
}
|
||||
|
||||
while(index >= sSize_)
|
||||
{
|
||||
std::vector<double> particleScalar_;
|
||||
sProbes_.push_back(particleScalar_);
|
||||
sSize_=sProbes_.size();
|
||||
}
|
||||
|
||||
//register vector probes on the corresponding vector
|
||||
forAll(vValues, iter)
|
||||
{
|
||||
int ProbeSize_=vProbes_[index].size();
|
||||
|
||||
if(probeIndex_<ProbeSize_) //The corresponding probe for this particle already exists, values are overwritten.
|
||||
{
|
||||
vProbes_[index][probeIndex_][0]=vValues[iter][0];
|
||||
vProbes_[index][probeIndex_][1]=vValues[iter][1];
|
||||
vProbes_[index][probeIndex_][2]=vValues[iter][2];
|
||||
}
|
||||
else //The corresponding probe for this particle has to be created
|
||||
{
|
||||
double * probe_= new double[3];
|
||||
|
||||
probe_[0]=vValues[iter][0];
|
||||
probe_[1]=vValues[iter][1];
|
||||
probe_[2]=vValues[iter][2];
|
||||
|
||||
vProbes_[index].push_back(probe_);
|
||||
}
|
||||
}
|
||||
|
||||
//register scalar probes on the corresponding vector
|
||||
forAll(sValues, iter)
|
||||
{
|
||||
int ProbeSize_=sProbes_[index].size();
|
||||
|
||||
if(probeIndex_<ProbeSize_) //The corresponding probe for this particle already exists, values are overwritten.
|
||||
{
|
||||
sProbes_[index][probeIndex_]=sValues[iter];
|
||||
}
|
||||
else //The corresponding probe for this particle has to be created
|
||||
{
|
||||
sProbes_[index].push_back(sValues[iter]);
|
||||
}
|
||||
if (includePosition_) *sPtr << " || position" << endl;
|
||||
else *sPtr << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void particleProbe::writeProbe(int index, Field<scalar> sValues, Field<vector> vValues) const
|
||||
|
||||
void particleProbe::writeProbe(int index, Field<scalar> sValues, Field<vector> vValues)
|
||||
{
|
||||
updateProbes(index,sValues,vValues); //update probe vectors
|
||||
|
||||
|
||||
if(printNow_ && checkIDForPrint(index) && verboseToFile_)
|
||||
if (printNow_ && verboseToFile_ && checkIDForPrint(index))
|
||||
{
|
||||
sPtr = sPtrList_[probeIndex_]; //set the pointer to the output file from list
|
||||
|
||||
//index and time
|
||||
*sPtr << setprecision(IOstream::defaultPrecision()+7);
|
||||
*sPtr << index << tab << particleCloud_.mesh().time().value() << " ";
|
||||
@ -298,7 +233,6 @@ void particleProbe::writeProbe(int index, Field<scalar> sValues, Field<vector> v
|
||||
*sPtr << vValues[iter][0] << " ";
|
||||
*sPtr << vValues[iter][1] << " ";
|
||||
*sPtr << vValues[iter][2] << " ";
|
||||
|
||||
}
|
||||
|
||||
//scalarFields
|
||||
@ -324,42 +258,40 @@ void particleProbe::writeProbe(int index, Field<scalar> sValues, Field<vector> v
|
||||
*sPtr << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool particleProbe::checkIDForPrint(int index) const
|
||||
{
|
||||
bool sampleThisId_ = false;
|
||||
if(sampleAll_) sampleThisId_ = true;
|
||||
else
|
||||
{
|
||||
forAll(particleIDsToSample_, iSample)
|
||||
{
|
||||
if(index==particleIDsToSample_[iSample]) sampleThisId_ = true;
|
||||
}
|
||||
}
|
||||
return sampleThisId_;
|
||||
if(sampleAll_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
forAll(particleIDsToSample_, iSample)
|
||||
{
|
||||
if (index == particleIDsToSample_[iSample]) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void particleProbe::setCounter() const
|
||||
void particleProbe::setCounter()
|
||||
{
|
||||
|
||||
//reset or increment counter for printing to file
|
||||
//reset or increment counter for printing to file
|
||||
//Do only if called by first item in the list of items!
|
||||
if(currItemId_==1)
|
||||
if (currItemId_ == 1)
|
||||
{
|
||||
printCounter_++;
|
||||
if( printCounter_ >= printEvery_ )
|
||||
++printCounter_;
|
||||
|
||||
if (printCounter_ >= printEvery_)
|
||||
{
|
||||
printCounter_=0;
|
||||
printCounter_ = 0;
|
||||
printNow_ = true;
|
||||
}
|
||||
else printNow_ = false;
|
||||
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -63,7 +63,7 @@ private:
|
||||
|
||||
dictionary propsDict_;
|
||||
|
||||
mutable word name_;
|
||||
word name_;
|
||||
|
||||
cfdemCloud& particleCloud_;
|
||||
|
||||
@ -75,7 +75,7 @@ private:
|
||||
|
||||
word dirName_;
|
||||
|
||||
mutable int rank_;
|
||||
int rank_;
|
||||
|
||||
mutable OFstream* sPtr;
|
||||
|
||||
@ -89,25 +89,23 @@ private:
|
||||
|
||||
const labelList particleIDsToSample_;
|
||||
|
||||
mutable wordList itemsToSample_;
|
||||
wordList itemsToSample_;
|
||||
|
||||
mutable List<OFstream*> sPtrList_;
|
||||
List<OFstream*> sPtrList_;
|
||||
|
||||
mutable int itemCounter_;
|
||||
int itemCounter_;
|
||||
|
||||
mutable int currItemId_;
|
||||
int currItemId_;
|
||||
|
||||
mutable int printCounter_;
|
||||
int printCounter_;
|
||||
|
||||
mutable bool printNow_;
|
||||
bool printNow_;
|
||||
|
||||
mutable std::vector< std::vector<double> > sProbes_;
|
||||
std::vector<std::string> probeName_;
|
||||
|
||||
mutable std::vector< std::vector<double*> > vProbes_;
|
||||
int probeIndex_;
|
||||
|
||||
mutable std::vector<std::string> probeName_;
|
||||
|
||||
mutable int probeIndex_;
|
||||
void setCounter();
|
||||
|
||||
public:
|
||||
|
||||
@ -131,17 +129,11 @@ public:
|
||||
~particleProbe();
|
||||
|
||||
// Member Functions
|
||||
void updateProbes(int index, Field<scalar> sValues, Field<vector> vValues) const;
|
||||
void initialize(word typeName, word logFileName) const;
|
||||
void setOutputFile() const;
|
||||
void initialize(const word& modelName, const word& logFileName);
|
||||
void setOutputFile(const word& logFileName);
|
||||
void writeHeader() const;
|
||||
void writeProbe(int index, Field<scalar> sValues, Field<vector> vValues) const;
|
||||
void writeProbe(int index, Field<scalar> sValues, Field<vector> vValues);
|
||||
bool checkIDForPrint(int) const;
|
||||
void setCounter() const;
|
||||
void clearProbes() const;
|
||||
std::vector< std::vector<double*> >* getVprobe() { return &vProbes_; }
|
||||
std::vector< std::vector<double> >* getSprobe() { return &sProbes_; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -133,16 +133,12 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
virtual void initialize(word typeName, word logFileName) const {}
|
||||
virtual void setOutputFile() const {}
|
||||
virtual void initialize(const word& modelName, const word& logFileName) {}
|
||||
virtual void setOutputFile(const word& logFileName) {}
|
||||
virtual void writeHeader() const {}
|
||||
virtual void writeProbe(int index, Field<scalar> sValues, Field<vector> vValues) const {}
|
||||
virtual void writeProbe(int index, Field<scalar> sValues, Field<vector> vValues) {}
|
||||
virtual bool checkIDForPrint(int) const { return false; }
|
||||
virtual void setCounter() const {}
|
||||
virtual bool active() const { return true; }
|
||||
virtual std::vector< std::vector<double*> >* getVprobe() { return NULL; }
|
||||
virtual std::vector< std::vector<double> >* getSprobe() { return NULL; }
|
||||
virtual void clearProbes() const {}
|
||||
|
||||
// Access
|
||||
|
||||
|
||||
Reference in New Issue
Block a user