# 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, nx, ny, nz, A, 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.; f_mdot = 0.; f_mdot = 0.; count = 0; begin_f_loop(f,t) { F_AREA(A, f, t); At = NV_MAG(A); nx += A/At; ny += A/At; nz += A/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 = C_U(c0,ct0) + C_DUDX(c0,ct0)*dr0 + C_DUDY(c0,ct0)*dr0 + C_DUDZ(c0,ct0)*dr0; vf0 = C_V(c0,ct0) + C_DVDX(c0,ct0)*dr0 + C_DVDY(c0,ct0)*dr0 + C_DVDZ(c0,ct0)*dr0; vf0 = C_W(c0,ct0) + C_DWDX(c0,ct0)*dr0 + C_DWDY(c0,ct0)*dr0 + C_DWDZ(c0,ct0)*dr0; vf1 = C_U(c1,ct1) + C_DUDX(c1,ct1)*dr1 + C_DUDY(c1,ct1)*dr1 + C_DUDZ(c1,ct1)*dr1; vf1 = C_V(c1,ct1) + C_DVDX(c1,ct1)*dr1 + C_DVDY(c1,ct1)*dr1 + C_DVDZ(c1,ct1)*dr1; vf1 = C_W(c1,ct1) + C_DWDX(c1,ct1)*dr1 + C_DWDY(c1,ct1)*dr1 + C_DWDZ(c1,ct1)*dr1; x_vel = (vf0+vf1)/2; y_vel = (vf0+vf1)/2; z_vel = (vf0+vf1)/2; Vmag = sqrt(pow(x_vel, 2.) + pow(y_vel, 2.) + pow(z_vel, 2.)); f_mdot += x_vel*C_R(c0,ct0)*A; f_mdot += y_vel*C_R(c0,ct0)*A; f_mdot += z_vel*C_R(c0,ct0)*A; ++count; } end_f_loop(f,t); nx /= count; ny /= count; nz /= count; Message("n"); Message("Mean x flux : %f n", f_mdot); Message("Mean y flux : %f n", f_mdot); Message("Mean z flux : %f n", f_mdot); Message("Mean interior normal : (%f, %f, %f)n", nx,ny,nz);}

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