CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Tracking Particle Positions in kinematicCloud

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 18, 2025, 20:26
Post Tracking Particle Positions in kinematicCloud
  #1
New Member
 
Sadra Seyfi
Join Date: Jan 2024
Posts: 1
Rep Power: 0
SScfd1380 is on a distinguished road
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?
SScfd1380 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of positions in particle tracking sujay CFX 31 November 11, 2020 15:30
Particle tracking error alchem OpenFOAM Bugs 5 May 6, 2017 16:30
Ubuntu 12.10 + openfoam2.2.0 ==> paraview error message peteryuan OpenFOAM Installation 6 August 18, 2013 18:00
[OpenFOAM] ParaView ErrOr soheil nazmdeh ParaView 1 August 17, 2013 07:40
injection problem Mark New FLUENT 0 August 4, 2013 01:30


All times are GMT -4. The time now is 19:26.