CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Sampling lagrangian data (https://www.cfd-online.com/Forums/openfoam-post-processing/63124-sampling-lagrangian-data.html)

farbfilm March 30, 2009 05:31

Sampling lagrangian data
 
Hi,

I tried to sample lagrangian data from a simulation with dieselFoam with the sample utility (i.e. with a sampleDict-File). I defined a plane under the keyword 'surfaces' and wanted to sample the diameter of the particles, i.e. choose d under the keyword 'Fields to sample'! When I'm running the utility no date are written!!!

When I choose U instead of d everything works fine!! So, it seems that only the sampling of the lagrangian data doesn't work!!

Has anybody some hints???

Thanks, Michael

niklas March 30, 2009 08:34

you have to write your own evaluation code if you want to do that kind of thing

farbfilm March 31, 2009 07:27

oh, well, I have no idea of doing something like that...

I'm wondering that nobody else has that problem! Or is there another/better way to sample the langrangian data like the droplet sizes??

farbfilm April 7, 2009 06:14

Doesn't anybody have a hint how to postprocess lagrangian data??
For example, one of my request is to get the data of the diameter of the droplets in a arbitrary plane! Then, I want this date to use in Matlab!!

I hope somebody can help me...

Thanks, Michael

gschaider April 7, 2009 08:03

Hi Michael!

The "best" way to postprocess the raw lagrangian data WITHOUT PROGRAMMING is:

1. start paraFoam
2. load the lagrangian data in addition to the "regular" data
3. "Split off" the lagrangian data using the "Extract Block"-filter
4. Open a new view on the result and make that view a "Spreadsheet view". In that view you will see the raw lagrangian data
5. File->Export that view to a CSV-file

The CSV can be imported into most programs (OpenOffice-Calc, Origin and I guess also MATLAB)

Bernhard

farbfilm April 8, 2009 09:48

Thank you, Bernhard!

That's definitely a way to do it!! For the moment that's fine! Thanks again!
But I think in the future, I'll don't get out of programming something when I'm dealing with lots of data!

So, if there is somebody who has a "more comfortable" solution (i.e. with programming) for that problem I would be still interested!!!

Michael

gschaider April 8, 2009 17:53

Quote:

Originally Posted by farbfilm (Post 212341)
But I think in the future, I'll don't get out of programming something when I'm dealing with lots of data!

So, if there is somebody who has a "more comfortable" solution (i.e. with programming) for that problem I would be still interested!!!

Best example how to read/filter/rewrite lagrangian data in C++ might still be mapLagrangianFields.C in the sources of the mapFields-utility.
For myself, if there is not too much data (some thousant particles without history data) I use the PyFoam-library to parse/process it. But I may be biased, because I'm on quite good speaking terms with the author so the lack of documentation for the programming interface isn't that big a problem for me

Bernhard

matejfor April 9, 2009 02:56

Hi,
I'm using KinematicParticle class for Lagrangian particles and there is even everything ready for you. The function is called dumpParticlePositions() and you may find it around line 500 in the file: src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C

Calling this function along with kinematicCloud1.evolve(); in your solver will give you
every time step one file with whatever you tell the function to print for all the particles in the coud.
I was actually post-processing these files in matlab 2 days ago...

good luck
matej

farbfilm April 9, 2009 05:32

Hi,

using KinematicParticle sounds quite good!
Could you please give me some details of how to build this function in my solver and how to tell the function what quantities it should write??

Sorry for so many questions!

Thanks, Michael

matejfor April 9, 2009 05:59

it's quite simple, but not for 5 lines.
you may have a look at rhoTurbTwinParcelFoam tutorial which comes with 1.5.x installation for your inpiration. there is a solver calling intermediate clases like kinematicCloud and thermoCloud for solving Lagrangian phase.

if you want to print out the data, you can add as I've written previously kinematicCloud1.dumpParticlePositions(); to the main solver where you call kinematicCloud1.evolve();

To specify what to print, you look for that function in src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C file.
For example my line n this function looks like:
pObj<< "v " << p.d() <<" "<< p.nParticle() <<" "<< p.stk()<<" "<< p.Ur() <<" "<< p.position().x() << " " << p.position().y() << " "

where for example p.stk is particle Stokes number, which I defined as an inline function in: parcels/Templates/KinematicParcel/KinematicParcel.H
and specified in:
parcels/Templates/KinematicParcel/KinematicParcelI.H

there you will find other variables which you may be interested in.

hope it helps you.
good luck
matej

az1362f August 18, 2009 10:29

Viewing Re number and relative velocity
 
Hi,

I want to write relative velocity and Reynolds number of each particle and then plot them,Is there any way?

please help me

regard

matejfor August 19, 2009 05:28

if you want to plot it in the paraview, the simple way is to calculate it in paraview by constructing your own filter. you can use the available variables in a calculator to construct your own new variable and plot it the paraview.

if you want it to be calculated during the run and written to the field for postprocessing, you have to inicialise the variable and write it at the end of the lagrangian calculation. How to do it would mean to trace in for variable like diameter and do the same for the relative Re.

good luck

matej

az1362f August 21, 2009 04:23

sampling lagrangian data
 
Hello Dear matej;

Thank you for your suggestion.I used calculator filter to made a new variable by name of Urel=U(droplet)-U(gas) but just exist U(droplet) in the vector variables and U(gas) is not active and does not exist in the vector variables.

For your second suggestion I traced in for variable like diameter and
I saw these lines in the parcelIO.C and I think that these lines write output files of particles properties,could you say me how can I add Urel and Re to these properties(d,T,m,y,.....)?
I want to write Urel and Re in addition to these values.


void Foam:: parcel::writeFields
(
const Cloud<parcel>& c
)
{
Particle<parcel>::writeFields(c);

label np = c.size();

IOField<scalar> d(c.fieldIOobject("d"), np);
IOField<scalar> T(c.fieldIOobject("T"), np);
IOField<scalar> m(c.fieldIOobject("m"), np);
IOField<scalar> y(c.fieldIOobject("y"), np);
IOField<scalar> yDot(c.fieldIOobject("yDot"), np);
IOField<scalar> ct(c.fieldIOobject("ct"), np);
IOField<scalar> ms(c.fieldIOobject("ms"), np);
IOField<scalar> tTurb(c.fieldIOobject("tTurb"), np);
IOField<scalar> liquidCore(c.fieldIOobject("liquidCore"), np);
IOField<scalar> injector(c.fieldIOobject("injector"), np);

IOField<vector> U(c.fieldIOobject("U"), np);
IOField<vector> Uturb(c.fieldIOobject("Uturb"), np);
IOField<vector> n(c.fieldIOobject("n"), np);

label i = 0;
forAllConstIter(Cloud<parcel>, c, iter)
{
const parcel& p = iter();

d[i] = p.d_;
T[i] = p.T_;
m[i] = p.m_;
y[i] = p.y_;
yDot[i] = p.yDot_;
ct[i] = p.ct_;
ms[i] = p.ms_;
tTurb[i] = p.tTurb_;
liquidCore[i] = p.liquidCore_;
injector[i] = p.injector_;

U[i] = p.U_;
Uturb[i] = p.Uturb_;
n[i] = p.n_;

i++;
}

d.write();
T.write();
m.write();
y.write();
yDot.write();
ct.write();
ms.write();
tTurb.write();
liquidCore.write();
injector.write();

U.write();
Uturb.write();
n.write();

// write the liquid molar fractions
if (np > 0)
{
Cloud<parcel>::const_iterator iter = c.begin();
const parcel& p0 = iter();

label nX = p0.X().size();
const List<word>& names = p0.liquidNames();

for (label j=0; j<nX; j++)
{
IOField<scalar> X(c.fieldIOobject(names[j]), np);

label i = 0;
forAllConstIter(Cloud<parcel>, c, iter)
{
const parcel& p = iter();
X[i++] = p.X()[j];
}

X.write();
}
}
}

az1362f August 22, 2009 15:14

sampling lagrangian data
 
Hello Dear matej;

Thank you for your suggestion.I used calculator filter to made a new variable by name of Urel=U(droplet)-U(gas) but just exist U(droplet) in the vector variables and U(gas) is not active and does not exist in the vector variables.

For your second suggestion I traced in for variable like diameter and
I saw these lines in the parcelIO.C and I think that these lines write output files of particles properties,could you say me how can I add Urel and Re to these properties(d,T,m,y,.....)?
I want to write Urel and Re in addition to these values.


void Foam:: parcel::writeFields
(
const Cloud<parcel>& c
)
{
Particle<parcel>::writeFields(c);

label np = c.size();

IOField<scalar> d(c.fieldIOobject("d"), np);
IOField<scalar> T(c.fieldIOobject("T"), np);
IOField<scalar> m(c.fieldIOobject("m"), np);
IOField<scalar> y(c.fieldIOobject("y"), np);
IOField<scalar> yDot(c.fieldIOobject("yDot"), np);
IOField<scalar> ct(c.fieldIOobject("ct"), np);
IOField<scalar> ms(c.fieldIOobject("ms"), np);
IOField<scalar> tTurb(c.fieldIOobject("tTurb"), np);
IOField<scalar> liquidCore(c.fieldIOobject("liquidCore"), np);
IOField<scalar> injector(c.fieldIOobject("injector"), np);

IOField<vector> U(c.fieldIOobject("U"), np);
IOField<vector> Uturb(c.fieldIOobject("Uturb"), np);
IOField<vector> n(c.fieldIOobject("n"), np);

label i = 0;
forAllConstIter(Cloud<parcel>, c, iter)
{
const parcel& p = iter();

d[i] = p.d_;
T[i] = p.T_;
m[i] = p.m_;
y[i] = p.y_;
yDot[i] = p.yDot_;
ct[i] = p.ct_;
ms[i] = p.ms_;
tTurb[i] = p.tTurb_;
liquidCore[i] = p.liquidCore_;
injector[i] = p.injector_;

U[i] = p.U_;
Uturb[i] = p.Uturb_;
n[i] = p.n_;

i++;
}

d.write();
T.write();
m.write();
y.write();
yDot.write();
ct.write();
ms.write();
tTurb.write();
liquidCore.write();
injector.write();

U.write();
Uturb.write();
n.write();

// write the liquid molar fractions
if (np > 0)
{
Cloud<parcel>::const_iterator iter = c.begin();
const parcel& p0 = iter();

label nX = p0.X().size();
const List<word>& names = p0.liquidNames();

for (label j=0; j<nX; j++)
{
IOField<scalar> X(c.fieldIOobject(names[j]), np);

label i = 0;
forAllConstIter(Cloud<parcel>, c, iter)
{
const parcel& p = iter();
X[i++] = p.X()[j];
}

X.write();
}
}
}

az1362f August 24, 2009 07:47

sampling lagrangian
 
any body can help me.
I am still waiting for a response.

matejfor August 28, 2009 11:41

OK if we stick to kinematicCloud class you need to do few thinkg there.

I've played around a bit and here is what you should do:
(I'm using 1.5-dev Foam version)

In parcels/Templates/KinematicParcel/KinematicParcelI.H :

define inline function for your relative Reynolds number,
In KinematicParcel.H add this function to a member function list.

now you need to tell the code to write this Re number out, so you need to edit KinematicParcelIO.C where you will find two member function - one is for reading the fields and the other is for writting. All you have to do now is to add IOField specification (around line 158) and then add {ReynoldsNumber function name}.write(); line compile and enjoy.

I guess about the same you can do also with other particle classes, not only with kinematic one.
If I do miss something here, hopefully someone more skilled will correct me.

I should add do not do all of this in the main src code. You will make some errors for sure and you want at least something to work. For example I have my local intermediateWORK library which I play around with.


good luck

matej

az1362f August 28, 2009 17:45

sampling lagrangian
 
Hello Dear

I try to do your suggustion.
There is an inline function to describe Urel like this in parcelI.H:

inline vector parcel::Urel(const vector& U) const
{
return U_ - U;
}

the problem is to define vector U(gas velocity) in every iteration to inline function for returning Ugas.

I add this line from parcel.C :

vector Up = sDB.UInterpolator().interpolate(position(), cell())
+ Uturb();

after these lines in parcelIO.C file:

forAllConstIter(Cloud<parcel>, c, iter)
{
const parcel& p = iter();

and add these lines to write function of parcelIO.C:

IOField<vector> Urel(c.fieldIOobject("Urel"), np);
Urel[i] = p.Urel(Up)
Urel.write();

exactly like parcelIO.C method, But because I did not declare Up and Uturb() I face errors when I try to compile it.

how can I add U (gas velocity) to Urel function[Urel(const vector& U)] when I call it for every iteration?

Tariq Ahmed May 8, 2015 11:11

Lagrangian particle velocity
 
Hi,
I am experiencing the same kind of problem in sprayFOAM solver. I want to sample droplet velocity and droplet diameter so I can postprocess in Matlab but I cant seem to find how to sample the lagrangian data since sample cmd works only for eularian phase.

Also I cant seem to find 'kinematicCloud1.dumpParticlePositions()' in KinematicCloud.C file. Any help would be really appreciated

Tariq

Tariq Ahmed May 11, 2015 05:55

Hope somebody is able to help me in the topic

Subhasree February 11, 2016 01:31

Hi Everyone!

I am using icoLagrangianFoam solver of foam extend 3.1 in which I have used patch injection method to insert particles over an object. I need to calculate the number of particles getting deposited on the object surface.

Can I use function lib in controlDict file for this?

chpjz0391 May 12, 2016 22:48

Quote:

Originally Posted by Subhasree (Post 584620)
Hi Everyone!

I am using icoLagrangianFoam solver of foam extend 3.1 in which I have used patch injection method to insert particles over an object. I need to calculate the number of particles getting deposited on the object surface.

Can I use function lib in controlDict file for this?

have you found the solution for your question?

I need to count the particle numbers in a specified area?

Do you have any hints?

wadekar October 23, 2017 08:49

Hello Foamer

I am struggling with lagrangian data sampling for sprayFoam, OF2.2.x version.
Basically, i want to evaluate size distribution. So want to calculate particle diameter and velocity during run time.

can someone guide me about the easiest way to do that....?

Thanks

gschaider October 23, 2017 10:40

Quote:

Originally Posted by wadekar (Post 668868)
Hello Foamer

I am struggling with lagrangian data sampling for sprayFoam, OF2.2.x version.
Basically, i want to evaluate size distribution. So want to calculate particle diameter and velocity during run time.

can someone guide me about the easiest way to do that....?

Thanks

In my world (which, some people say, is a strange and rather self-centered world) the easiest and most flexible way would be swak4Foam. Look for instance at this file from the examples https://sourceforge.net/p/openfoam-e...em/controlDict (function object "coalDiameter"). With a "swakExpressionDistribution" you could even calculate proper distributions

foamiste January 11, 2018 11:19

Quote:

Originally Posted by Tariq Ahmed (Post 545600)
Hi,
I am experiencing the same kind of problem in sprayFOAM solver. I want to sample droplet velocity and droplet diameter so I can postprocess in Matlab but I cant seem to find how to sample the lagrangian data since sample cmd works only for eularian phase.

Also I cant seem to find 'kinematicCloud1.dumpParticlePositions()' in KinematicCloud.C file. Any help would be really appreciated

Tariq

Hello Tariq,

Did you solve this problem? because I have the same now and I don't know what to do.

Asmaa

gschaider January 11, 2018 16:03

Quote:

Originally Posted by foamiste (Post 677739)
Hello Tariq,

Did you solve this problem? because I have the same now and I don't know what to do.

Asmaa

Format of the particle data is rather simple: in the lagrangian-folder each property has a file where the values for all particles are stored. Writing a script that strips away the start and the end should generate a file that is easily read by MATLAB

I did something like this in PyFoam. See slide 148ff in
https://openfoamwiki.net/images/0/05...ForTheLazy.pdf
(to fully appreciate it a little knowledge of Pandas would be good)

foamiste January 11, 2018 16:23

Quote:

Originally Posted by gschaider (Post 677765)
Format of the particle data is rather simple: in the lagrangian-folder each property has a file where the values for all particles are stored. Writing a script that strips away the start and the end should generate a file that is easily read by MATLAB

I did something like this in PyFoam. See slide 148ff in
https://openfoamwiki.net/images/0/05...ForTheLazy.pdf
(to fully appreciate it a little knowledge of Pandas would be good)


Thank you very much for your quick reply, the presentation is very usefull and respond to a big part of what I need actually!!

But in the other hand I need to extract particles that coincide with a circular surface defined by vector axis and radius and then treat those clouds.

Do you have an idea how I can achieve this?

Regards,
Asmaa

gschaider January 11, 2018 18:45

Quote:

Originally Posted by foamiste (Post 677766)
Thank you very much for your quick reply, the presentation is very usefull and respond to a big part of what I need actually!!

But in the other hand I need to extract particles that coincide with a circular surface defined by vector axis and radius and then treat those clouds.

Do you have an idea how I can achieve this?

That is in post-processing I assume? You want to look at the particles inside/outside/on a cylinder-surface. You've got the particle positions in the data. So a little calculation (distance of the particle from the axis) should give you a criterion to select the particles that you want and drop the rest

foamiste January 12, 2018 06:13

1 Attachment(s)
Quote:

Originally Posted by gschaider (Post 677779)
That is in post-processing I assume? You want to look at the particles inside/outside/on a cylinder-surface. You've got the particle positions in the data. So a little calculation (distance of the particle from the axis) should give you a criterion to select the particles that you want and drop the rest

Hello,

Thanks for your reply! yes it is post processing. I want to calculate the sauter mean diameter of particles that coincide with the surface below.
Actually I am doing it manually using paraview, by clipping 2 cylinders then slice a plane and extract .csv file than calculate the SMD (SMD=sum(d^3)/sum(d^2)). And I have to vary the radius of cylinders at every sampling. So, I find it really painful that's why I am looking for an automatic way to do it.

Any hints will be appreciated!
Thanks
Asmaa

gschaider January 12, 2018 08:34

Quote:

Originally Posted by foamiste (Post 677835)
Hello,

Thanks for your reply! yes it is post processing. I want to calculate the sauter mean diameter of particles that coincide with the surface below.
Actually I am doing it manually using paraview, by clipping 2 cylinders then slice a plane and extract .csv file than calculate the SMD (SMD=sum(d^3)/sum(d^2)). And I have to vary the radius of cylinders at every sampling. So, I find it really painful that's why I am looking for an automatic way to do it.

Any hints will be appreciated!
Thanks
Asmaa

That shouldn't be to hard. You could add field dist to the dataframe similary to what I do in the presentation with distCenter. Then something like
Code:

(data["dist"] **3).sum()/(data["dist"]**2).sum()
would calculate that.

Reading the particle positions might be problematic with OF 5.0 and v1712 as in those versions the meaning of the positions-file changed.

foamiste January 12, 2018 09:48

Thanks for your prompt responses,
[QUOTE=gschaider;677857]
Code:

(data["dist"] **3).sum()/(data["dist"]**2).sum()
Yes you're right it is just a command to execute but the problem is how to extract this surface.
Concerning the output of the cloud positions I don't know how it is built because it contains more than 3 components!!
For exemple: (0 0.02311223035 0.01947409306 0.9574136766) 638 96587 1

Actually I am looking in the samplingSurface and cutting plane to see if I can get something through it!

Asmaa

ashrufsyed April 15, 2018 14:08

I too have similar issue! Below is a sample 'positions' output

(0.212065 0.0952962 0.536003 0.156636) 376063 1199337 1
(0.0683043 0.384839 0.287326 0.25953) 415092 1305086 2

Not able to understand what is the data (with four components + three numbers thereafter) that OF is trying to dump in the time directory.

In my case the file location is time_dir/lagrangian/reactingCloud1/positions

Other files like d, U, T etc in the same directory ( time_dir/lagrangian/reactingCloud1/ ) seems to be in typical format and understandable except the 'positions' file.

wyldckat April 15, 2018 17:27

Quick'ish question: I received a private message (PM) from ashrufsyed and I came to take a quick look into this... I've learned from the PM that OpenFOAM-dev is being used... But the problem here is that I'm not familiar with how exactly people are retrieving these position files. @ashrufsyed and/or @foamiste: Please provide instructions on which tutorial case I can look into, so that I can check what's going on here?

Because my guess is that the 1st value is a time value for the particle, but it's just a guess based on other cases. The problem is what time exactly is that.

ashrufsyed April 17, 2018 03:58

Thanks @wyldckat for taking time to have a look at the thread!

I am using fireFoam solver (Version 17.07.24) from the github with the OF-dev (commit 1ff578)
For a sample case, you can have a look at the detailedSprinklerInjection case from the github.

The 'positions' file is saved in the location time_dir/lagrangian/reactingCloud1/

Regarding the first value, I don't think it correspond to time, because the sample output I posted was for 30s. Also all the four components I get are positive ( at least in my case) whereas my droplet positions actually should have negative x and y values as well

ashrufsyed April 17, 2018 04:03

Quote:

Reading the particle positions might be problematic with OF 5.0 and v1712 as in those versions the meaning of the positions-file changed
Does that mean the 'positions' output doesn't correspond to the droplet/particle coordinates? If so, what do those four components mean?

ashrufsyed April 17, 2018 05:11

Quote:

Originally Posted by gschaider (Post 677857)
That shouldn't be to hard. You could add field dist to the dataframe similary to what I do in the presentation with distCenter. Then something like
Code:

(data["dist"] **3).sum()/(data["dist"]**2).sum()
would calculate that.

Reading the particle positions might be problematic with OF 5.0 and v1712 as in those versions the meaning of the positions-file changed.

This reply from gschaider gave me a hint to explore the way particle tracking was changed starting from v5.0. From the release notes, it is clear that OF now uses a local barycentric coordinates for tracking particles (including lagrangian solver and for creating streamlines etc.,). Also this thread further suggests that the 'positions' file is indeed written in barycentric format.

So the question now will be how can we convert these local barycentric coordinates into the global cartesian system?

Since the thread suggests that position() variable during the Cloud calculation gives the actual global coordinates, is it possible to get it directly from the OF I/O file itself (in the form an output file) ?

wyldckat April 17, 2018 19:35

Quick answer:
  1. It's not straight forward to get an IO file generated by OpenFOAM with the X,Y,Z coordinates of the particles. It's not impossible, but it is necessary to do some coding.
  2. In order to not have to code, then there are two possibilities:
    1. Use foamToVTK, for exporting the data to VTK format... then use ParaView to do the export to CSV or something else...
    2. Use the following block inside the case file "system/controlDict":
      Code:

      DebugSwitches
      {
          kinematicCloud 1;
      }

      Then run the case as you usually do. This was meant to create an OBJ (wavefront format) file inside each time folder, but for me it would only overwrite the file "kinematicCloud_positions.obj" inside the root folder of the case. I tested this with 5.x, but not with OpenFOAM-dev.
      • If you want to use this option, please open a report at https://bugs.openfoam.org with the instructions on how to reproduce this issue with one of OpenFOAM's tutorial cases... I can't do it myself now, because I don't have enough time to answer to you and report the bug :(
  3. If you don't mind coding, then look into calling the method 'writePositions()': https://github.com/OpenFOAM/OpenFOAM...d/Cloud.C#L429

jairoandres June 7, 2020 15:29

I've just gotten through all the posts as I have to do something similar. I need to determine particle properties (mass, d, nParcels, velocity) in different positions inside the domain. Don't you think it might be easier to modify the particleCollector.C file to write other properties of the parcels being collected? I am not a very good programmer but if the parcels going through the polygon can be "collected" and removed from the simulation, you can also print to a file some properties of those parcels.

atul1018 June 26, 2020 10:09

Hello Bernhard,


I am trying to plot Lagrangian data (particle velocity along a line at a particular time) and I came across your answer regarding sampling Lagrangian data. In your answer you mentioned the following:



1. start paraFoam
2. load the lagrangian data in addition to the "regular" data
3. "Split off" the lagrangian data using the "Extract Block"-filter
4. Open a new view on the result and make that view a "Spreadsheet view". In that view you will see the raw lagrangian data
5. File->Export that view to a CSV-file


I am able to extract kinematicloud but I am not able to open a new view over that and get the data (step 4). can you please explain a bit more step 4 (may be some screenshots from paraview)?


I will be grateful if you or someone can help me to get the particle velocity data along a line.


Best Regards
Atul Jaiswal


All times are GMT -4. The time now is 09:55.