CFD Online Discussion Forums

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

chris February 1, 2007 05: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 11, 2010 00: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 16: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 17: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 02: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 05: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 14: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 04: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 12: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 09: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 19: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 20: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.


All times are GMT -4. The time now is 20:36.