|
[Sponsors] |
July 2, 2019, 00:08 |
Looping macro for DPM
|
#1 |
New Member
Hasan
Join Date: Mar 2017
Posts: 7
Rep Power: 9 |
Hi all,
I am aware that in the customization manual there are some examples of looping macros including one to loop over all particles in a cell. But I was just wondering if there is any way of defining a certain radius around let's say a cell, where the tracked particle is currently located, and then loop over all particles that are located within that defined radius? May be we can identify the cells that fall withing that radius and then extend our looping macro to go over multiple cells, instead of just one? Thanks a lot for your help in advance. With best regards Hasan |
|
July 2, 2019, 01:11 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you may define cell by it's coordinates and find all adjusted cells within radius, which you specify
to make this loop over all cells and check if coordinates are inside sphere. Ansys Fluetn Customization manual -> C_CENTROID best regards |
|
July 2, 2019, 22:39 |
|
#3 |
New Member
Hasan
Join Date: Mar 2017
Posts: 7
Rep Power: 9 |
Hi Alexander,
Thanks a lot for your very helpful hint. In order to confirm what you suggested, I have drafted a test code. Would you please check my test code and let me know whether or not I was able to implement the idea correctly. The other idea I have is to check it with DEFINE_ON_DEMAND, however this UDF has no pointer to the tracked particle. Perhaps you have a hint to resolve that issue. Furthermore, I was wondering if there was any alternative way of doing the check, as opposed to unnecessarily going through the entire domain. Because if I execute this every time step it is going to take forever, isn't it? Cheers Hasan Code:
#include <udf.h> DEFINE_DPM_SCALAR_UPDATE(count_cells, cell, thread, initialize, tp) { real xc0[ND_ND]; C_CENTROID(xc0, cell, thread); /*This should be my reference cell where the currently tracked particle is located*/ Domain *d; d = Get_Domain(1); /*get the domain ID of fluid*/ cell_t c; Thread *t; real xc[ND_ND]; int counter = 0; int n = 0; /* loop over all cell threads in the domain */ thread_loop_c(t, d) { /* loop over all cells */ begin_c_loop_int_ext(c, t) { C_CENTROID(xc, c, t); if (sqrt(ND_SUM(pow(xc[0] - xc0[0], 2.), pow(xc[1] - xc0[1], 2.), pow(xc[2] - xc0[2], 2.))) < 0.1) counter++;/*count if within radius of 10 cm*/ else n++;/*count if not within radius*/ } end_c_loop_int_ext(c, t) } /*this is to check the calculation, do not mind the formatting*/ FILE *debugf; debugf = fopen("debugf_1.txt", "a"); fprintf(debugf, "%d %d\n", n, counter); fclose(debugf); } Last edited by hjubaer; July 3, 2019 at 05:04. |
|
July 3, 2019, 05:32 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
first of all, try to compile your code, you will get some errors.
I don't understand your line Code:
C_CENTROID(xc0, cell, thread); /*This should be my reference cell where the currently tracked particle is located*/ so you get them, but later do the same again Code:
C_CENTROID(xc, c, t); so delete: Code:
thread_loop_c(t, d) { /* loop over all cells */ begin_c_loop_int_ext(c, t) { C_CENTROID(xc, c, t); Code:
if (sqrt(ND_SUM(pow(xc[0] - xc0[0], 2.), pow(xc[1] - xc0[1], 2.), pow(xc[2] - xc0[2], 2.))) < 0.1) Code:
FILE *debugf; debugf = fopen("debugf_1.txt", "a"); fprintf(debugf, "%d %d\n", n, counter); fclose(debugf); to be Code:
C_UDMI(c,t,0) = n; C_UDMI(c,t,1) = counter; Code:
DEFINE_EXECUTE_AT_END(write_log) { Domain *d; Thread *t; cell_t c; FILE *debugf; d=Get_Domain(1); debugf = fopen("debugf_1.txt", "a"); thread_loop_c(t,d) { begin_c_loop(c,t) { fprintf(debugf, "%d %d\n", C_UDMI(c,t,0), C_UDMI(c,t,1)); } end_c_loop(c,t) } } fclose(debugf); } best regards |
|
July 3, 2019, 08:09 |
|
#5 |
New Member
Hasan
Join Date: Mar 2017
Posts: 7
Rep Power: 9 |
first of all, thanks heaps! You are awesome!!
Let me quickly explain the part that created confusion. My understanding was Code:
C_CENTROID(xc0, cell, thread); Code:
TP_POS(tp)[0], TP_POS(tp)[1], TP_POS(tp)[2] Code:
C_CENTROID(xc, c, t); I know that I do not need to check all the cells in the domain, as most of them would obviously be outside the reach/radius. But Is there any way to limit my search to the neighbouring threads only? Does it make sense now? Cheers Hasan |
|
July 6, 2019, 00:45 |
|
#6 |
New Member
Hasan
Join Date: Mar 2017
Posts: 7
Rep Power: 9 |
Hello everyone,
Is there any way to loop through all the particles in my calculation domain (transient case) without going into the thread and cell loop? Code:
Particle *p; Injection *Ilist, *I; Ilist = Get_dpm_injections(); loop(I, Ilist) { loop(p, I->p_init) /* Standard ANSYS Fluent Looping Macro to get particle streams in an Injection */ {/*do whatever calculation is needed in here*/ } } Cheers Hasan Last edited by hjubaer; July 8, 2019 at 23:19. |
|
July 8, 2019, 02:21 |
|
#7 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Code:
C_CENTROID(xc0, cell, thread); Aa you've mentioned, you need Code:
P_POS(tp)[0], P_POS(tp)[1], P_POS(tp)[2] For more information about UDF for DPM read Ansys FLuent Customization manual , DPM Macros chapter best regards |
|
July 8, 2019, 23:18 |
|
#8 |
New Member
Hasan
Join Date: Mar 2017
Posts: 7
Rep Power: 9 |
Thank you for your time and help.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
fvOptions | npatricia | OpenFOAM | 6 | May 23, 2018 06:21 |
Fluent UDF wrong number of cells in parallel - correct in serial | dralexpe | Fluent UDF and Scheme Programming | 7 | May 17, 2018 09:26 |
timestep extraction for macro | manuc | Tecplot | 0 | August 10, 2016 13:20 |
looping a macro | Troy | Siemens | 0 | July 3, 2008 19:17 |
looping macro equivalence | Swarup | FLUENT | 1 | June 8, 2006 06:14 |