March 18, 2025, 20:26
|
Tracking Particle Positions in kinematicCloud
|
#1
|
New Member
Sadra Seyfi
Join Date: Jan 2024
Posts: 1
Rep Power: 0
|
Hi foamers,
I'm working on a lagrangian particle tracking solver which is a combination of pimpleFoam and lagrangian/intermediate library. I want to add a header file to pimpleFoam source code so I can access each particle position at each timesep. Here is my code:
Code:
#include "kinematicCloud.H"
#include "IOdictionary.H"
#include "faceSet.H"
#include "OFstream.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "fvCFD.H"
namespace Foam
{
class faceHitCounter
{
const kinematicCloud& cloud_;
//const KinematicCloud& cloudtemp_;
const fvMesh& mesh_;
const Time& runTime_;
scalar totalParticles_;
scalar totalHits_;
autoPtr<OFstream> csvFile_;
scalar xcs, ycs, zcs;
scalar rcs;
public:
faceHitCounter(const kinematicCloud& cloud, const fvMesh& mesh, const Time& runTime)
: cloud_(cloud),
mesh_(mesh),
runTime_(runTime),
totalParticles_(0),
totalHits_(0)
{
IOdictionary gaugeProperties
(
IOobject
(
"gaugeProperties",
runTime_.constant(),
mesh_,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);
// Extract Catch Surface Coordinates and Radius
vector catchSurfaceCoor(gaugeProperties.lookup("catchSurface"));
xcs = catchSurfaceCoor.x();
ycs = catchSurfaceCoor.y();
zcs = catchSurfaceCoor.z();
rcs = readScalar(gaugeProperties.lookup("catchSurfaceRadius"));
csvFile_.reset(new OFstream(runTime_.path()/"catchEfficiency.csv"));
*csvFile_ << "Time, TotalParticles, TotalHits, CumulativeCatchEfficiency\n";
}
void trackHits()
{
scalar stepHitCount = 0;
forAllIter(typename Foam::KinematicCloud, cloud_, iter)
{
const auto& particle = iter();
const vector& pos = particle.position();
if (pow(pos.x() - xcs, 2.0) + pow(pos.y() - ycs, 2.0) <= rcs * rcs && pos.z() <= zcs)
{
stepHitCount++;
}
}
totalParticles_ = cloud_.nParcels();
totalHits_ = stepHitCount;
// Calculate Collection Efficiency
scalar CatchEfficiency = totalParticles_ > 0
? scalar(totalHits_) / totalParticles_
: 0.0;
Info << "Time: " << runTime_.timeName() << nl
<< "Particles Injected: " << totalParticles_ << nl
<< "Particles Collected: " << totalHits_ << nl
<< "Current Catch Efficiency: " << CatchEfficiency << endl;
*csvFile_ << runTime_.timeName() << ", "
<< totalParticles_ << ", "
<< totalHits_ << ", "
<< CatchEfficiency << "\n";
}
};
}
My problem is in my for loop which doesn't work kinematicCloud class. Any Ideas on how to fix this issue?
|
|
|