CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Fluent UDF and Scheme Programming (
-   -   access velocity on xy-line in udf (

moe April 20, 2010 06:05

access velocity on xy-line in udf

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"

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


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

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)
printf("velocity is negative. set tau to -0.06\n");
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.


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.
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.


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

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++)
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 ?

All times are GMT -4. The time now is 13:25.