|
[Sponsors] |
May 23, 2022, 09:49 |
Finding a cell closest to a point
|
#1 |
Member
Mohammad Shafiee
Join Date: Apr 2021
Posts: 30
Rep Power: 7 |
Hello,
I've written a DEFINE_EXECUTE_ON_LOADING macro to find a cell in the domain closest to a specified point. I did it by looping over all the cells and finding the cell with minimum distance from that point. Later I will use this cell's identifiers (hubthread_id, hubcell_id in the code below) in a DEFINE_ADJUST macro from another source file to address it. Here's a shortened version of my code: Code:
#include "udf.h" Thread *hubthread_id ; cell_t hubcell_id ; DEFIINE_EXECUTE_ON_LOADING(macro_name,libname) { Domain *dom ; Thread *c_thread ; cell_t cell ; double d, d_new, c[3], temp[3]; double x_h[3] = {0.0,3.0,0.0} ; dom = Get_Domain(1) ; d = 1.2 ; thread_loop_c(c_thread,dom) { begin_c_loop(cell,c_thread) { C_CENTROID(c, cell, c_thread); d_new = sqrt(pow(x[0]-c[0],2)+pow(x[1]-c[1],2)+pow(x[2]-c[2],2)); if (d_new < d) { hubthread_id = c_thread ; hubcell_id = cell ; d = d_new ; } } end_c_loop(cell,c_thread) } C_CENTROID(temp, hubcell_id, hubthread_id); /*I'm trying to see if its working properly, but gave me an error*/ Message("\n %d %d %d", temp[0],temp[1],temp[2]) ; } I can compile it with no errors but after loading the library the last two lines are causing my code to break with these errors: SharedScreenshot.jpg Any reasons why this is happening? or any better ways to do this whole process? Last edited by Mohammad74; May 23, 2022 at 12:24. |
|
May 23, 2022, 23:39 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
no idea how you could compile it without errors, as there are few typos
I recommend you to compile code always I was able to compile following code, test it: Code:
#include "udf.h" Thread *hubthread_id ; cell_t hubcell_id ; DEFINE_EXECUTE_ON_LOADING(macro_name,libname) { Domain *dom ; Thread *c_thread ; cell_t cell ; real d, d_new, c[ND_ND], temp[ND_ND]; real x[3] = {0.0,3.0,0.0} ; dom = Get_Domain(1) ; d = 1.2 ; thread_loop_c(c_thread,dom) { begin_c_loop(cell,c_thread) { C_CENTROID(c, cell, c_thread); d_new = sqrt(pow(x[0]-c[0],2)+pow(x[1]-c[1],2)+pow(x[2]-c[2],2)); if (d_new < d) { hubthread_id = c_thread ; hubcell_id = cell ; d = d_new ; } } end_c_loop(cell,c_thread) } C_CENTROID(temp, hubcell_id, hubthread_id); /*I'm trying to see if its working properly, but gave me an error*/ Message0("\n %f %f %f", temp[0],temp[1],temp[2]) ; }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
May 24, 2022, 09:17 |
|
#3 | |
Member
Mohammad Shafiee
Join Date: Apr 2021
Posts: 30
Rep Power: 7 |
Quote:
I'm sorry, Yeah you are correct about typos. But i made these mistakes while typing the code in this forum. Anyway, I compiled the code you provided and again it was compiled with no errors, but after loading the library, it gives a lot of errors and I couldn't find the reason behind it. Here are images of my tui after loading the library made from your code: 1.jpg2.jpg |
||
Tags |
cell centroid, fluent 19.0, udf and programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[blockMesh] Floating Point Exception while generating wedge based mesh | jns-v | OpenFOAM Meshing & Mesh Conversion | 9 | July 8, 2021 06:36 |
Simulating fire in a tunnel | luca1992 | OpenFOAM | 14 | August 16, 2017 14:50 |
[General] Finding the exact location of a cell paraview | arieljeds | ParaView | 0 | January 7, 2016 08:12 |
FvMatrix coefficients | shrina | OpenFOAM Running, Solving & CFD | 10 | October 3, 2013 15:38 |
Errors in UDF | shashank312 | Fluent UDF and Scheme Programming | 6 | May 30, 2013 21:30 |