|
[Sponsors] |
March 5, 2019, 20:25 |
UDF for current particle position
|
#1 |
New Member
Join Date: May 2018
Posts: 3
Rep Power: 8 |
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 |
|
March 5, 2019, 21:23 |
|
#2 | |
Senior Member
Join Date: Feb 2010
Posts: 164
Rep Power: 17 |
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:
|
||
March 6, 2019, 02:22 |
|
#3 |
New Member
Join Date: May 2018
Posts: 3
Rep Power: 8 |
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 |
|
|
|
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 |