|
[Sponsors] |
April 30, 2019, 22:36 |
Accessing Lagrangian Data During Run Time
|
#1 |
Member
Tony Zahtila
Join Date: Mar 2016
Posts: 33
Rep Power: 10 |
I am trying to access the age of the particles in my simulation.
I have seen a part of code in the file: lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcelI.H Code:
template<class ParcelType> inline Foam::scalar Foam::KinematicParcel<ParcelType>::age() const { return age_; } Code:
#include "KinematicParcel.H" Foam::KinematicParcel<Foam::particle>::age() error: cannot call member function ‘Foam::scalar& Foam::KinematicParcel<ParcelType>::age() [with ParcelType = Foam:article; Foam::scalar = double]’ without object Foam::KinematicParcel<Foam:article>::age() This is somewhat unsurprising, however, I am not sure how to proceed. I feel like I need to look up a KinematicParcel object but I am unable to determine what it's name would be, or how to access it. Any pointers would be appreciated. Kind regards. |
|
May 2, 2019, 05:59 |
|
#2 |
Member
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 8 |
Hey Tony,
you are absolutely right with your guess that you need a particle/parcel or something alike - object in order to call the function. The function is part of a class (- template) and since it is not a static function, you first need an existing object of that class in order to call it. Generally it is not possible to track a specific parcel since they do not have a specific ID, like for instance the cells or faces of your mesh (practical reasons, the container storing the particle is a linked list). What you could do in your solver (assuming your solver is containing a sprayCloud object - or some cloud object which type is derived from lagrangian/basic/Cloud - named parcels, I am using of1612): Code:
if(parcels.size()) { auto particle = parcels.cbegin(); // const access to first parcel in cloud Info << "position: " << particle().position() << nl; } Code:
forAllConstIter(decltype(parcels),parcels,cParcelIter) // or forAllIter it you want to modify { const auto pVelocity = cParcelIter().U(); // access data // do something with the data } Cheers RP |
|
May 6, 2019, 02:22 |
|
#3 |
Member
Tony Zahtila
Join Date: Mar 2016
Posts: 33
Rep Power: 10 |
Hello raumpolizei,
Thank you for taking the time to reply to my thread. In my createFields.H file, I have this part to create the lagrangian cloud. Code:
basicKinematicCollidingCloud kinematicCloud ( kinematicCloudName, rhoInf, U, mu, g ); The error I am receiving when trying to add on your suggestion: Code:
grabK.H:20:4: error: ‘parcels’ was not declared in this scope if(parcels.size()) I am nevertheless still a bit confused, I can see that there my code is creating an object called 'kinematicCloud'. I suggest this because in my main loop, we have the following line: kinematicCloud.evolve(). However, it is the case that the kinematicParcel contains the lagrangian particle data. And this itself cannot be access as an object. Is this correct? |
|
May 6, 2019, 02:43 |
|
#4 |
Member
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 8 |
Hey there,
the reason why it is not working is hidden in the lines of code you posted. In OpenFOAM and C++, a lot is done via classes. Object may be variables with user defined types (which are defined by classes). kinematicCloud is an object of the specific type basicKinematicCollidingCloud. Now, if you want to use functions of that class (non-static, public functions), you need to put the name of the object + a dot + the name of the function you would like to call, as I have done it for the fictive object parcels in my previous post. Code:
SomeCloud parcels; // create object parcels of type SomeCloud parcels.doSomeRandomStuff(); // calls function doSomeRandomStuff on object parcels of type SomeCloud Cheers RP |
|
May 21, 2019, 09:27 |
|
#5 |
Member
Tony Zahtila
Join Date: Mar 2016
Posts: 33
Rep Power: 10 |
Hello raumpolizei,
Thanks for your help so far, it has been invaluable and got me going! I have made some modifications so far and I am able to output the acceleration when I run OpenFOAM in serial.. but am having some issues in parallel. I have been able to diagnose my issue. First I will show you how I have modified the code: I created a field 'Uold' in the file: lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcelI.H and a few more files so that it is added to the KinematicParcel class: Code:
template<class ParcelType> inline Foam::KinematicParcel<ParcelType>::KinematicParcel ( const polyMesh& owner, const barycentric& coordinates, const label celli, const label tetFacei, const label tetPti ) : ParcelType(owner, coordinates, celli, tetFacei, tetPti), active_(true), typeId_(-1), nParticle_(0), d_(0.0), dTarget_(0.0), U_(Zero), Uold_(Zero), acceleration_(Zero), rho_(0.0), age_(0.0), tTurb_(0.0), UTurb_(Zero) {} p.Uold() = p.U(); Code:
bool Foam::KinematicParcel<ParcelType>::move ( TrackCloudType& cloud, trackingData& td, const scalar trackTime ) { typename TrackCloudType::parcelType& p = static_cast<typename TrackCloudType::parcelType&>(*this); typename TrackCloudType::parcelType::trackingData& ttd = static_cast<typename TrackCloudType::parcelType::trackingData&>(td); ttd.switchProcessor = false; ttd.keepParticle = true; const cloudSolution& solution = cloud.solution(); const scalarField& cellLengthScale = cloud.cellLengthScale(); const scalar maxCo = solution.maxCo(); p.Uold() = p.U(); Info << "Old particle velocity" << p.Uold(); while (ttd.keepParticle && !ttd.switchProcessor && p.stepFraction() < 1) This works fine when I am in serial but I am running into an annoying problem when I run in parallel. For the case where particles enter from a different processor onto a given processor, for some reason the Uold and U field for that time-step are the same, and only the particles that came onto that processor store the old velocity in Uold and the updated velocity in U. I can't work out why this is happening.. Any help would be appreciated, on even what I can try to debug this. |
|
May 22, 2019, 04:25 |
|
#6 |
Member
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 8 |
Hey there,
from my point of view, it looks like you are updating the velocity at the wrong place in the code. The piece of code updating Uold should be at the beginning of the function that is responsible for updating the velocity (I think the function name is something like calcVelocity). If you check the while statements, Code:
while (ttd.keepParticle && !ttd.switchProcessor && p.stepFraction() < 1) Cheers RP |
|
July 14, 2019, 23:12 |
|
#7 | |
Member
Tony Zahtila
Join Date: Mar 2016
Posts: 33
Rep Power: 10 |
Quote:
HTML Code:
lagrangian/intermediate/lnInclude/KinematicParcel.C:188:14: error: passing ‘const vector {aka const Foam::Vector<double>}’ as ‘this’ argument discards qualifiers [-fpermissive]
p.Uold() = banana;
Code:
const Foam::vector Foam::KinematicParcel<ParcelType>::calcVelocity ( TrackCloudType& cloud, trackingData& td, const scalar dt, const scalar Re, const scalar mu, const scalar mass, const vector& Su, vector& dUTrans, scalar& Spu ) const { const typename TrackCloudType::parcelType& p = static_cast<const typename TrackCloudType::parcelType&>(*this); typename TrackCloudType::parcelType::trackingData& ttd = static_cast<typename TrackCloudType::parcelType::trackingData&>(td); const typename TrackCloudType::forceType& forces = cloud.forces(); // Do a new old velocity Info << "Old particle velocity" << p.Uold() << endl; const vector banana = p.U(); p.Uold() = banana; Info << "banana" << banana; Any help would be kindly appreciated. |
||
July 15, 2019, 05:54 |
|
#8 | |
Member
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 94
Rep Power: 15 |
Quote:
I don't know what you are trying to do but I just saw the issue and wanted to reply if you need the answer in shorter time. The reason that the compiler is complaining is that you assign "banana" to a function call which will return a const access to the particle velocity (see p definition with "const" qualifier). And assignment for a const (if it is not at declaration) is not permitted. Take a look at how "const" works in C++ if you have doubts. Also, you may take a look at "https://github.com/OpenFOAM/OpenFOAM-dev/blob/aab3a22708d20fb3b31b5c897d151f831f9281d7/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcelI.H" to see there are two types of access functions "const" and "ref" ones. |
||
July 15, 2019, 22:59 |
|
#9 | |
Member
Tony Zahtila
Join Date: Mar 2016
Posts: 33
Rep Power: 10 |
Quote:
However, one thing keeps bugging me: Code:
const Foam::vector Foam::KinematicParcel<ParcelType>::calcVelocity ( TrackCloudType& cloud, trackingData& td, const scalar dt, const scalar Re, const scalar mu, const scalar mass, const vector& Su, vector& dUTrans, scalar& Spu ) const |
||
July 16, 2019, 06:11 |
|
#10 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
In most recent OpenFOAM versions (perhaps 1712 and later), the following should work Code:
for (const auto& p : parcels) { const vector& vel = p.U(); // access data // do something with the data } IMO using 'auto' can be reasonable for the loop (since we probably don't really care what type of particle it is), but using 'vector' for the inner deferencing of the U() makes for somewhat better documentation of what is going on. |
||
July 16, 2019, 08:58 |
|
#11 | |
Member
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 94
Rep Power: 15 |
Quote:
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[OpenFOAM] How to get the coordinates of velocity data at all cells and at all times | vidyadhar | ParaView | 9 | May 20, 2020 21:06 |
High Courant Number @ icoFoam | Artex85 | OpenFOAM Running, Solving & CFD | 11 | February 16, 2017 14:40 |
Stuck in a Rut- interDyMFoam! | xoitx | OpenFOAM Running, Solving & CFD | 14 | March 25, 2016 08:09 |
AMI interDyMFoam for mixer nu problem | danny123 | OpenFOAM Programming & Development | 8 | September 6, 2013 03:34 |
same geometry,structured and unstructured mesh,different behaviour. | sharonyue | OpenFOAM Running, Solving & CFD | 13 | January 2, 2013 23:40 |