CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   DPM: UDF - loop over all particles (https://www.cfd-online.com/Forums/fluent-udf/43577-dpm-udf-loop-over-all-particles.html)

chris February 1, 2007 04:54

DPM: UDF - loop over all particles
 
I would like to have my EXECUTE_AT_END udf loop over all particles in the domain. I would like to know how many particles there are in every cell. But i get a "Segmentation violation" when i want to access any variable that is beeing processed during the "begin_particle_cell_loop". I am using FLUENT 6.3

Thanks for your help!

This is my code:

DEFINE_EXECUTE_AT_END(execute_at_end) {

Thread *t;

Domain *d;

Particle *pi; /* Particle index for looping over all particles in the cell */

real numb_cell=0.;

real numb_part_dom=0.;

cell_t c;

d = Get_Domain(1); /* mixture domain if multiphase */

thread_loop_c(t,d)

{

begin_c_loop(c,t)

{

numb_cell += 1;

begin_particle_cell_loop(pi,c,t)

{

numb_part_dom += 1;

}

end_particle_cell_loop(pi,c,t)

}

end_c_loop(c,t)

}

printf("Number of cells %g\n", numb_cell);

printf("Number of particles %g\n", numb_part_dom);

fflush(stdout); }

kmayank July 11, 2009 08:38

any solution?
 
Hey Chris,

Did you manage to get any solution to this problem? I am also stuck there.

Thanks
Mayank

johnwinter November 10, 2010 23:20

Hi Kmayank,

Do you have any idea How to get particle concentration in each cell?.
I am facing that problem now. any suggestion

John

snow November 18, 2010 15:39

DEFINE_ON_DEMAND(particle_cells_count)
{
Domain *d;
Thread *t;
cell_t c;
Particle *p;

int particles;
int cells;

d = Get_Domain(1);

Alloc_Storage_Vars(d, SV_DPM_PARTICLE_BIN, SV_NULL);
bin_particles_in_cells(d);

particles=0;
cells=0;

thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
cells++;
begin_particle_cell_loop(p,c,t)
{
particles++;
}
end_particle_cell_loop(p,c,t)
}
end_c_loop(c,t)
}

Free_Storage_Vars(d, SV_DPM_PARTICLE_BIN, SV_NULL);

Message("Number of cells: %d\n",cells);
Message("Number of particles: %d\n",particles);
}

Wikie December 1, 2010 16:22

hi,

are you able to compile the last code? I'm always getting the following error message:

error C2198: 'bin_particles_in_cells' : too few arguments for call

The error occurs in this line:

bin_particles_in_cells(d);

Any idea why I'm not able to compile this code??

cheers
wikie

Wikie January 18, 2011 01:38

Hi,

I still stuck at this problem. I'm always getting the same error message saying: "error C2198: 'bin_particles_in_cells' : too few arguments for call".
Can anybody help me please, I have to know the number of particles to continue my work.

Thanks,
wikie

coglione January 18, 2011 04:08

I would do it the following way:

loop(I, Ilist)
{
loop(p, I->p)
{
c = P_CELL(p);
c_t = P_CELL_THREAD(p);
parcel_trapped+=1;
num_part=p->number_in_parcel;
}
}
cheers

Wikie January 19, 2011 13:24

Hi coglione,

thank you very much for your reply.
I wrote the UDF as you recommended, but I want to make sure that I understood erverything.
In my case I'm getting num_part = 12, parcel_trapped = 45 and number_in_parcel = 0. parcel_trapped is clear, this is the number parcel from my surface injection. But why is number_in_parcel = 0? This should be the number of particles in one parcel, isn't it? Do I have to multiple num_part x parcel_trapped to get the total number of particles in my domain??

thank you
Wikie

--------------------------

Here you can see my UDF.

#include "udf.h"

DEFINE_ON_DEMAND(particle_cells_count)
{
Injection *Ilist;
Injection *I;
Particle *p;
cell_t c;
Thread *c_t;
int parcel_trapped = 0;
int num_part = 0;
int number_in_parcel = 0;

Ilist = Get_dpm_injections();

loop(I, Ilist)
{
loop(p, I->p)
{
c = P_CELL(p);
c_t = P_CELL_THREAD(p);
parcel_trapped+=1;
num_part=p->number_in_parcel;
}
}

Message("num_part: %d\n",num_part);
Message("parcel_trapped: %d\n",parcel_trapped);
Message("number_in_parcel: %d\n",number_in_parcel);

}

coglione January 20, 2011 03:04

1) number_in_parcel is a member function of the particle class defined somewhere in the source code of Fluent --> you redefine and initialize it with zero what may cause the behaviour you observe.
2) number_in_parcel returns a floating point number --> define num_part as real

cheers

Wikie January 20, 2011 11:53

Hi coglione,

sorry it's me again. I change my UDF as recommended, but now the result is num_part=0 and parcel_trapped = 0 :-(
Could you please check my UDF again?

Thank you very much,
Wikie

#include "udf.h"

DEFINE_ON_DEMAND(particle_cells_count)
{
Injection *Ilist;
Injection *I;
Particle *p;
cell_t c;
Thread *c_t;
int parcel_trapped = 0;
real num_part = 0;

Ilist = Get_dpm_injections();

loop(I, Ilist)
{
loop(p, I->p)
{
c = P_CELL(p);
c_t = P_CELL_THREAD(p);
parcel_trapped+=1;
num_part=p->number_in_parcel;
}
}

Message("num_part: %d\n",num_part);
Message("parcel_trapped: %d\n",parcel_trapped);

}

Wikie January 23, 2011 08:18

Hi coglione,

I still wasn't able to solve this problem. I looked up number_in_parcel in the dpm_types.h file and I found "real number_in_parcel; /* number of particles in parcel (unsteady only) */". I can use this just in unsteay simulation, am I right? But my simulation is steady :-( Any ideas to get the number of all particles in whole domain for stady cases?

I'm finally interested in the total reacting surface of all particles. Perhaps there is a better way to determine this area.

Greatings,
Wikie

TedBrogan May 10, 2011 11:15

coglione (or anyone else for that matter),

Where did you find the command for loop(I,Ilist) { }? Stumbling upon this thread and finding that command was a major help for the udf I'm working on. I need a few more of these undocumented commands to finish the udf, and I was wondering if you knew of a place where I could find all of these. I've tried going through files like dpm.h, but I don't see how you could know loop(I,Ilist) is a command from that.

Specifically, I'm trying to change the start and stop time of unsteady particle injection in a udf. It's easy enough and documented how to change position, velocity, etc in the udf help files, but I can't find anything on this one.

Thanks!

Wikie May 11, 2011 01:05

Hi TedBrogan,

this is the normal command for loops. You'll also find it in manuals. I also learned this due to my discussion here in the forum.

cheers
wikie

cdf_user March 20, 2012 18:15

Quote:

Originally Posted by coglione (Post 290910)
I would do it the following way:

loop(I, Ilist)
{
loop(p, I->p)
{
c = P_CELL(p);
c_t = P_CELL_THREAD(p);
parcel_trapped+=1;
num_part=p->number_in_parcel;
}
}
cheers


Ilist = Get_dpm_Injections();

does not work. I get the error

function: "Get_dpm_Injections" not found (pc=12).

I have included udf.h, dpm.h, surf.h, mem.h, sg_mphase.h, sg.h,
cxiface.h

Please help!

cdf_user March 20, 2012 19:06

Quote:

Originally Posted by Wikie (Post 291187)
Hi coglione,

thank you very much for your reply.
I wrote the UDF as you recommended, but I want to make sure that I understood erverything.
In my case I'm getting num_part = 12, parcel_trapped = 45 and number_in_parcel = 0. parcel_trapped is clear, this is the number parcel from my surface injection. But why is number_in_parcel = 0? This should be the number of particles in one parcel, isn't it? Do I have to multiple num_part x parcel_trapped to get the total number of particles in my domain??

thank you
Wikie

--------------------------

Here you can see my UDF.

#include "udf.h"

DEFINE_ON_DEMAND(particle_cells_count)
{
Injection *Ilist;
Injection *I;
Particle *p;
cell_t c;
Thread *c_t;
int parcel_trapped = 0;
int num_part = 0;
int number_in_parcel = 0;

Ilist = Get_dpm_injections();

loop(I, Ilist)
{
loop(p, I->p)
{
c = P_CELL(p);
c_t = P_CELL_THREAD(p);
parcel_trapped+=1;
num_part=p->number_in_parcel;
}
}

Message("num_part: %d\n",num_part);
Message("parcel_trapped: %d\n",parcel_trapped);
Message("number_in_parcel: %d\n",number_in_parcel);

}


My Get_dpm_Injections does not works

Fluent says function Get_dpm_Injections not found

I have included "dpm.h"

Please Help!

cdf_user April 21, 2012 02:06

Quote:

Originally Posted by TedBrogan (Post 307021)
coglione (or anyone else for that matter),

Where did you find the command for loop(I,Ilist) { }? Stumbling upon this thread and finding that command was a major help for the udf I'm working on. I need a few more of these undocumented commands to finish the udf, and I was wondering if you knew of a place where I could find all of these. I've tried going through files like dpm.h, but I don't see how you could know loop(I,Ilist) is a command from that.

Specifically, I'm trying to change the start and stop time of unsteady particle injection in a udf. It's easy enough and documented how to change position, velocity, etc in the udf help files, but I can't find anything on this one.

Thanks!


If you go in system files of the fluent, you will find many .c files in include folder. One of those files is dpm.h. All the commands are listed there.

juzer_700 April 24, 2012 03:00

CFD Simulation of Gas turbine Engine_ Combustion Chamber
 
Hello everyone,

Can anyone suggest me a good document/book to start with simulation in gas turbine engine (combustion chamber).

I am planning to do the post processing in FLUENT. Is Openfoam software better than Fluent for combustion purpose?

Also, I intend to use C language to develop the code. Does Fluent take code written in Fortran. And which one is better? Fortran or C?

Please help me as I'm a beginner in this field.

cdf_user April 24, 2012 05:49

Fluent is better. Fluent takes c++ code for user defined functions. I dont much about combustion so cant really recommend a book. I have experience in simulating turbomachinary though..

ADI April 24, 2012 12:12

JUZER_700, OpeanFOAM is completely custom. As in you can define your own equations for everything from Continuity to Turbulence and much more.

FLUENT commercial package however has a ton of these in-built and ready to use.

As for good books on gas turbine combustion chamber i suggest
GAS Turbine Combustion by Lefebvre, Mechanics and thermodynamics of Propulsion by Hill and petersen and the AIAA series book named Aerothermodynamicsof gas turbine and rocket propulsion by Oates...

juzer_700 April 25, 2012 01:46

@ADI Thanks for the suggestion. I am planning to code advance combustion model and then link it to fluent/openfoam. I have certain parts of the code written in Fortran. Is there anyway I can directly use the fortran code in FLUENT?

Do I need to convert all the FORTRAn code into C language? Any method?

Please help.

ADI April 25, 2012 01:56

FORTRAN code UDF for FLUENT, I am 99% sure it is not possible. You will have to recode it in c/C++. Besides, If you are writing a UDF for FLUENT, usually you do not code every thing from continuity all the way to the slightest details in combustion. Use the FLUENT UDF manual. It really will guide you well.

As for openfoam, I dont have much experience. I have only tried a very small and simple pipe flow model at home. No where enough experience to provide help or advice.

juzer_700 April 25, 2012 02:01

Ok.

Yes I have started reading the UDF manual. Thanks for your advice.

juzer_700 April 25, 2012 05:42

@ADI : one more thing. It is possible to generate a virtual grid in C language and run the UFD code developed on that grid and to simultaneously run the FLUENT code (Continuity, mom, energy eqs) on the grid developed in GAMBIT/FLUENT?

sfotovati July 13, 2012 17:23

High everybody,

I would like to loop over all particles and find their intraction with each other. However, this has to be done inside a UDF for DPM (e.g. Defiend_DPM_SCALAR_UPDATE). The compiler will go wrong as soon as I have one of the macros related for looping over the particles (e.g. begin_particle_cell_loop!).

Does anyone have any idea to resolve this situation?

Thank you.

Sean

HyperNova April 11, 2015 00:47

Quote:

Originally Posted by Wikie (Post 290892)
Hi,

I still stuck at this problem. I'm always getting the same error message saying: "error C2198: 'bin_particles_in_cells' : too few arguments for call".
Can anybody help me please, I have to know the number of particles to continue my work.

Thanks,
wikie

hi Wikie
have you found any solution for that ? i stuck at this problem either, i am using Fluent v15.0, in v6.3.26 it works correctly, but in v15.0 no,
thank you

alburkatyhasan@yahoo.com August 27, 2017 19:34

nanoparticle measurement by CFD
 
Hello, dear
Is there any way to count the Particles on Boundries over the time ?
how can I do it in the fluent? pls tell me the steps for it, and pls how can I know How many particles pass the Inlet in those ten seconds of Simulation in the fluent? 1000000000 thanks

pat-cfd August 14, 2018 12:25

Solution: looping over all particles, calculating melt fraction
 
Hi All,

Thank you for all your posts! I haven't read all the posts, so I'm not sure if a solution has been found. If not, here's some code I've written to count all of the particles and calculate the melt fraction. Note that I only have one injection so I didn't have to loop through them, as we done in the previous posts with Ilist.

DEFINE_ON_DEMAND(melt_percent_calc)
{
Injection *I;
Particle *p;

real particle_count = 0;
real melt_count = 0;
real melt_percent = 0;

I = Get_dpm_injections();

loop(p, I->p)
{
particle_count++;
if (TP_T(p) > Tmelt){
melt_count++;
}
if (TP_TIME(p) > time){
time = TP_TIME(p);
}
}

melt_percent = (melt_count/particle_count)*100;
Message("\n");
Message("Particle count: %g\n", particle_count);
Message("Melt count: %g\n", melt_count);
Message("Melt percent: %g\n", melt_percent);

}

vavnoon June 17, 2020 01:21

Hello everybody,

I want to inject several particles using read a file in the DPM setting and finally get their positions.

I used the following UDF for writing the positions.

#include "udf.h"
#include "dpm.h"
DEFINE_ON_DEMAND(particles_position)
{

Domain *d;
Thread *t;
cell_t c;
d = Get_Domain(1);

Injection *I;
Particle *p;
I = Get_dpm_injections();

FILE *fp;

loop(p, I->p)
{

fp = fopen ("E:/aafinal/path/position.txt","a");

fprintf(fp, "%d %d %d \n", P_POS(p)[0], P_POS(p)[1], P_POS(p)[2]);

fclose(fp);

}

}
Despite the declaration variable I, I faced the error: I: undeclared variable.
Could anyone please guide me?

Thank you for your time and concern!

vavnoon June 17, 2020 02:11

I also have another question. Should I use if-loop if I want to get positions in several specified times? Do you have any suggestions?

Thanks

vinerm June 17, 2020 03:45

Compilation
 
Are you compiling it or interpreting it? Interpreter will not work for this scenario. As a compiled version, it would work fine. You don't need the following lines

#include "dpm.h"
Domain *d;
Thread *t;
cell_t c;
d = Get_Domain(1);

And open and close the file outside the loop, otherwise I/O will slow down the process significantly.

vavnoon June 17, 2020 05:38

Many thanks for the reply.

I interpreted it.
Yes, you're right. There is no need to write the lines.

#include "udf.h"

DEFINE_ON_DEMAND(particles_position)
{

Injection *I;
Particle *p;
I = Get_dpm_injections();

FILE *fp;
fp = fopen ("E:/aafinal/path/position.txt","a");

loop(p, I->p)
{

fprintf(fp, "%d %d %d \n", P_POS(p)[0], P_POS(p)[1], P_POS(p)[2]);
}

fclose(fp);
}

vinerm June 17, 2020 05:52

Compiler
 
You need to compile it. Interpreter won't work.


All times are GMT -4. The time now is 22:54.