FLUENT V5 - Sample User-defined Function (UDF) to determine flow direction through interior faces in the domain


The domain has many interiors in order to know where the flow goes (in or out from some region). The objective is to determine flow rate and direction through each of them. Unfortunately, flux reports don't use a uniform normal direction and the sign has no meaning. Report/Surface-integral will also provide flow rate but not the flow direction. A UDF seems like the best solution. Here is a sample created to work with FLUENT V5.


#include "udf.h"
extern Domain* domain;

DEFINE_ON_DEMAND(flux)
{
int count, massflow_zone;
real f_mdot[3], nx, ny, nz, A[3], Vmag, At, x_vel, y_vel, z_vel;
real cx0[ND_ND], cx1[ND_ND], fx[ND_ND], dr0[ND_ND], dr1[ND_ND];
real vf0[ND_ND], vf1[ND_ND];
cell_t c0, c1;
Thread *t, *ct0, *ct1;
face_t f;

massflow_zone = 5; /*This is the ID of interior face */
t = Lookup_Thread(domain, massflow_zone);
nx = 0.;
ny = 0.;
nz = 0.;
f_mdot[0] = 0.;
f_mdot[1] = 0.;
f_mdot[2] = 0.;
count = 0;
begin_f_loop(f,t)
{
F_AREA(A, f, t);
At = NV_MAG(A);
nx += A[0]/At;
ny += A[1]/At;
nz += A[2]/At;
/* get neighbouring cells and their centroid */
c0 = F_C0(f, t);
ct0 = THREAD_T0(t);
c1 = F_C1(f, t);
ct1 = THREAD_T1(t);
C_CENTROID(cx0, c0, ct0);
C_CENTROID(cx1, c1, ct1);
F_CENTROID(fx, f, t);
/* calculate distance from face centroid */
NV_VV(dr0, =, fx, -, cx0);
NV_VV(dr1, =, fx, -, cx1);

/* interpolate velocities on face (since it is not kept in memory)
* using a central differencing scheme */
vf0[0] = C_U(c0,ct0) + C_DUDX(c0,ct0)*dr0[0] + C_DUDY(c0,ct0)*dr0[1] + C_DUDZ(c0,ct0)*dr0[2];
vf0[1] = C_V(c0,ct0) + C_DVDX(c0,ct0)*dr0[0] + C_DVDY(c0,ct0)*dr0[1] + C_DVDZ(c0,ct0)*dr0[2];
vf0[2] = C_W(c0,ct0) + C_DWDX(c0,ct0)*dr0[0] + C_DWDY(c0,ct0)*dr0[1] + C_DWDZ(c0,ct0)*dr0[2];

vf1[0] = C_U(c1,ct1) + C_DUDX(c1,ct1)*dr1[0] + C_DUDY(c1,ct1)*dr1[1] + C_DUDZ(c1,ct1)*dr1[2];
vf1[1] = C_V(c1,ct1) + C_DVDX(c1,ct1)*dr1[0] + C_DVDY(c1,ct1)*dr1[1] + C_DVDZ(c1,ct1)*dr1[2];
vf1[2] = C_W(c1,ct1) + C_DWDX(c1,ct1)*dr1[0] + C_DWDY(c1,ct1)*dr1[1] + C_DWDZ(c1,ct1)*dr1[2];
x_vel = (vf0[0]+vf1[0])/2;
y_vel = (vf0[1]+vf1[1])/2;
z_vel = (vf0[2]+vf1[2])/2;
Vmag = sqrt(pow(x_vel, 2.) + pow(y_vel, 2.) + pow(z_vel, 2.));
f_mdot[0] += x_vel*C_R(c0,ct0)*A[0];
f_mdot[1] += y_vel*C_R(c0,ct0)*A[1];
f_mdot[2] += z_vel*C_R(c0,ct0)*A[2];
++count;
}
end_f_loop(f,t);
nx /= count;
ny /= count;
nz /= count;
Message("n");
Message("Mean x flux : %f n", f_mdot[0]);
Message("Mean y flux : %f n", f_mdot[1]);
Message("Mean z flux : %f n", f_mdot[2]);
Message("Mean interior normal : (%f, %f, %f)n", nx,ny,nz);
}





Show Form
No comments yet. Be the first to add a comment!