CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

UDF for current particle position

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 5, 2019, 20:25
Default UDF for current particle position
  #1
New Member
 
Join Date: May 2018
Posts: 3
Rep Power: 8
zyfantastic is on a distinguished road
Hi all,
I am trying to get the particle position in domain in a transient flow by UDF. I tried to use DEFINE_EXECUTE_AT_END so that I can get the position every time step. my code is as follows:
DEFINE_EXECUTE_AT_END(gpif)
{
Injection *Ilist;
Injection *I;
Particle *p;
Ilist = Get_dpm_injections();
FILE *fid1;
fid1 = fopen("particleposition.txt","w");
loop(I,Ilist)
{
loop(p, I->p_init)
{
fprintf(fid1, "%f %f %f %f %f %f %f %"int64_fmt"\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],P_VEL(p)[0],P_VEL(p)[1],P_VEL(p)[2],P_TIME(p),p->part_id);
}
}
fclose(fid1);
}
I can only get the initialization position of the particles.
if I change Particle *p to Tracked_Particle *p, the fluent just crashed.
Can someone help me to solve the problem please?
Thanks in advance.
zyFan
zyfantastic is offline   Reply With Quote

Old   March 5, 2019, 21:23
Default
  #2
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
gearboy is on a distinguished road
Your code seems only prints the position of particles at injections. They will not be tracked at each iteration end. So error occurs. I suggest you use DPM macros, such as DEFINE_DPM_SCALAR_UPDATE(name,c,t,initialize,p), where p is just the Tracked_Particle * type given by Fluent.

Quote:
Originally Posted by zyfantastic View Post
Hi all,
I am trying to get the particle position in domain in a transient flow by UDF. I tried to use DEFINE_EXECUTE_AT_END so that I can get the position every time step. my code is as follows:
DEFINE_EXECUTE_AT_END(gpif)
{
Injection *Ilist;
Injection *I;
Particle *p;
Ilist = Get_dpm_injections();
FILE *fid1;
fid1 = fopen("particleposition.txt","w");
loop(I,Ilist)
{
loop(p, I->p_init)
{
fprintf(fid1, "%f %f %f %f %f %f %f %"int64_fmt"\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],P_VEL(p)[0],P_VEL(p)[1],P_VEL(p)[2],P_TIME(p),p->part_id);
}
}
fclose(fid1);
}
I can only get the initialization position of the particles.
if I change Particle *p to Tracked_Particle *p, the fluent just crashed.
Can someone help me to solve the problem please?
Thanks in advance.
zyFan
gearboy is offline   Reply With Quote

Old   March 6, 2019, 02:22
Default
  #3
New Member
 
Join Date: May 2018
Posts: 3
Rep Power: 8
zyfantastic is on a distinguished road
Hi gearboy,

Thanks for your answer, I have tries the DEFINE_DPM_SCALAR_UPDATE(name,c,t,initialize,p). But it exported too many particle data information as the macros is called every time a particle position is update. If I set the condition if (P_TIME(p) == CURRENT_TIME), the code is as follows:

#include "udf.h"
#include "dpm.h"

DEFINE_DPM_SCALAR_UPDATE(gpif,c,t,initialize,p)
{
int n;
n = N_TIME;
char filename[50];
real current_time = CURRENT_TIME;
snprintf(filename,50,"particleposition_%d.txt",n);
FILE *fid1;
fid1 = fopen(filename,"a");
if (P_TIME(p) == CURRENT_TIME)
{
fprintf(fid1, "%f %f %f %f %f %f %f %"int64_fmt"\n",P_POS(p)[0],P_POS(p)[1],P_POS(p)[2],P_VEL(p)[0],P_VEL(p)[1],P_VEL(p)[2],P_TIME(p),p->part_id);
}
else
{
printf("time is not reached");
}
fclose(fid1);
}

I can`t get all particle data after 1st time step.
I need all particles position data at the end of each time step. Do you have any method to do it?

Thanks and regards,
zyFan
zyfantastic is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Particle cooling rate - UDF papteo Fluent UDF and Scheme Programming 9 January 29, 2012 10:28
Force dependent on particle position jranita OpenFOAM Programming & Development 1 August 23, 2011 20:44
UDF for Particle reaction and DPM_Property saifulraju ANSYS 0 September 22, 2010 08:24
udf about particle concentration--who can help me? zhaoh FLUENT 1 January 17, 2007 12:46
Help: UDF of "particle body force" !!! zhaoh FLUENT 3 January 16, 2007 21:17


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