CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to loop over parcels in OpenFOAM 9 (https://www.cfd-online.com/Forums/openfoam-programming-development/238364-how-loop-over-parcels-openfoam-9-a.html)

ASimonsen September 8, 2021 09:32

How to loop over parcels in OpenFOAM 9
 
Hi

I'm in the process of switching from OF8 to OF9, where I'm currently updating my main solver. It is a lagrangian solver, where I in OF8 looped over all parcels by:

Code:

forAllIter(decltype(parcels),parcels,p)
{
    vector position = p().position();
}

The thing is that the variable "parcels" was previously defined in createClouds.H:

Code:

basicSprayCloud parcels
(
    "sprayCloud",
    rho,
    U,
    g,
    slgThermo
);

In OF9 the clouds/parcels have moved to fvModels, so now I do not have access to the variable "parcels" in my solver code anymore (as there is no createClouds.H anymore), and I can't seem to figure out how to get it from the fvModels variable.

I am able to loop over all the models in my simulation by:
Code:

PtrListDictionary<fvModel>& modelList(fvModels);
forAll(modelList, i)
{
    Info << "Name: " << modelList[i].name() << endl;
}

I have three different models applied in my simulation, and the cloud is the second on. So I guess it is something like:

Code:

autoPtr<???>& parcels = modelList[1];
Can anyone help me with my problem, such that I again can loop over parcels in OF9? :)

Kind regards Anders

ASimonsen September 20, 2021 09:21

Hi again

I still haven't succeeded in looping over the parcels in OF9. However, I've made some progress, which I'll share here:

Via the object registry, I was able to get a pointer to the parcelCloud object:
Code:

Foam::parcelCloud& Obj_ParcelCloud = mesh.lookupObjectRef<Foam::parcelCloud>("cloud");
Using this object, I'm able to evolve the cloud:
Code:

runTime++;
Info << "Time = " << runTime.timeName() << nl << endl;
Obj_ParcelCloud.evolve();

However, I'm still not able to loop over the parcels - I simply do not know how to access it.
The iterator methods are defined in "Cloud.H":
Code:

    // Member Functions

        // Access

            //- Return the polyMesh reference
            const polyMesh& pMesh() const
            {
                return polyMesh_;
            }

            //- Return the number of particles in the cloud
            label size() const
            {
                return IDLList<ParticleType>::size();
            };


            // Iterators

                const const_iterator begin() const
                {
                    return IDLList<ParticleType>::begin();
                };

                const const_iterator cbegin() const
                {
                    return IDLList<ParticleType>::cbegin();
                };

                const const_iterator end() const
                {
                    return IDLList<ParticleType>::end();
                };

                const const_iterator cend() const
                {
                    return IDLList<ParticleType>::cend();
                };

                iterator begin()
                {
                    return IDLList<ParticleType>::begin();
                };

                iterator end()
                {
                    return IDLList<ParticleType>::end();
                };

However, the methods .begin, .cbegin, .end, .cend are not members of the "Obj_ParcelCloud" object, which I have available in my solver as shown above.

Can someone help me further, such that I can loop over all parcels? Or give me a hint/tip, as I seem to be stuck! :confused:

Kind regards Anders

ASimonsen October 4, 2021 03:42

Hi again

I still haven't figured it out - can anyone give a hint or a suggestion? :)

Kind regards Anders

yv3s95 November 1, 2021 18:38

I am actually wondering the same, if anybody has a suggestion.

David* November 10, 2021 02:30

just a wild guess, if you are using a pointer to object, do you have to access the member functions with a dereference operator like "->" ?
https://www.decodejava.com/cpp-point...-functions.htm


All times are GMT -4. The time now is 23:57.