CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   access velocity on xy-line in udf (https://www.cfd-online.com/Forums/fluent-udf/75239-access-velocity-xy-line-udf.html)

moe April 20, 2010 06:05

access velocity on xy-line in udf
 
hi,

i have created a grid and set it up for a vof calculation and created a horizontal line in fluent with the surface/line option. now i want to access the y-velocity on the line in the flow field and calculate the mean value for setting my bc depending on the results. this is my code:

#include "udf.h"

DEFINE_PROFILE(settau,thread,i)
{
Domain *d;
Thread *t;
face_t f,v;
real v_sum, v_mean_wall=0, v_mean_xy=0;
int count, zone_id_wall=THREAD_ID(thread), zone_id_xy=14;
//i know the id of the line

//velocity at xy line
d=Get_Domain(1);
t=Lookup_Thread(d,zone_id_xy);

v_sum=0;
count=1;
begin_f_loop(v,t)
{
v_sum+=F_V(v,t);
count++;
}
end_f_loop(v,t)
v_mean_xy=v_sum/count;

printf("mean y velocity at xy-line %i is: %g m/s with %d cells\n", zone_id_xy, v_mean_xy, count);

//velocity at BC
v_sum=0;
count=1;
begin_f_loop(f,thread)
{
v_sum+=F_V(f,thread);
++count;
}
end_f_loop(f,thread)
v_mean_wall=v_sum/count;

printf("mean y velocity at wall %i is: %g m/s with %d cells\n", zone_id_wall, v_mean_wall, count);

//set bc depending on results
if (v_mean_wall<=0 && v_mean_xy<=0)
{
begin_f_loop(f,thread)
{
F_PROFILE(f,thread,i)=-0.06;
}
end_f_loop(f,thread)
printf("velocity is negative. set tau to -0.06\n");
}
else
{
begin_f_loop(f,thread)
{
F_PROFILE(f,thread,i)=0.06;
}
end_f_loop(f,thread)
printf("velocity is positive. set tau to 0.06\n");
}

}

i get an access violation because of the F_V(,t) command. i assume i can not access the y velocity on a xy-line like this with the face command. i searched the documentation, but i didn't found anything what kind of data type a line is and how i can access its values.

maybe somebody knows? thanks a lot!

moe April 20, 2010 18:48

i found out that as far as i know it is not possible to access data with a face loop on a xy line like i tried to.
it seems that a line of interest has to be defined in the mesh/grid generator (for example gambit), so it is getting its own fixed id that you can see in the BC panel. with this id you are able to access the "line" in udf with lookup_thread.
but it is not working if the bc on this created line is set to "interior". in that case i still get access error.

coglione April 21, 2010 05:55

hello moe,
a possible workaround would be to use solve/execute command to calculate the average and write it to a file at any intervals (e.g. every timestep). Just record a macro with the appropriate steps: report/surface integrals blablabla....
Then read the current value within your udf from the file and update your bc.

cheers

moe April 21, 2010 15:36

i have not tried the workaround, because it's not suitable in my case. but it might work.

after having a conversation with some experts i found out that it is not possible to acces velocity at interior faces.
http://my.fit.edu/itresources/manual...udf/node91.htm
for interior faces you can only get the massflow rate and the pressure. other variables have to be computed by the user himself.
the other properties you only can get on boundary lines.

closed

moe April 22, 2010 07:13

i found out that it is possible to get the velocities and other properties through the adjacent cells of the face. when the line is interior C0 and C1 exist, then the velocity can be accessed with F_C0(f,t)/F_C1(f,t) and THREAD_T0(t)/THREAD_T1(t).
you can calculate an average value on different ways by yourself.

beezee99 October 23, 2010 05:11

Hi.
 
Hello.
I have a 2D (x,y) domain of size (0,0)(xmax,ymax) divided into a 50x50 grid. I want to find properties (e.g. y-velocity) of all cells at any given instant in the following manner.

for (y=0,y=ymax,y++)
{
for(x=0,x=xmax,x++)
{
location[x][y]= ........ ?
y_velocity[x][y]=........ ?
}
}

It means that I fix y, then loop over all available x-cells to store values. Then increase y and repeat the process for x-cells. I need to store the values in arrays for further analysis or written to files. How do I add it to my UDF ?
Thanx.
NVD.

Anirudh616 February 11, 2022 04:03

Isn't velocity a cell property? Try using C loop instead of F loop

Kuljeet June 6, 2023 11:19

accessing line properties
 
One can use if statement using cell centroid as condition to make a line within begin c loop. I am assuming you know dimension and mesh details.
-K


All times are GMT -4. The time now is 06:40.