FLUENT V6 - User-Defined Function (UDF) to flag the cells at a boundary that have reversed flow (backflow)

Can we "flag" the cells which has reverse flow (backflow)?
This UDF will "flag" the cells which has reverse flow, thus enables us to uniquely see which cells have reversed flow. This is particularly useful if the surface is complex and does not coincide with the X, Y or Z coordinate planes.

This UDF has two UDMs - UDM0 will have values +1/-1 corresponding to +/- mass flow rates. UDM1 will have values same as the mass flow rate through the adjacent boundary face.

How this UDF works?-

1. Read case/data
2. Change the Zone ID (of the face on which mass flow rate is required) in UDF
3. Compile UDF, load library
4. Allocate TWO UDMs
5. Initialize UDMs by going to Display->Contours->UDMs, select UDM0, click on "Compute". Repeat the same for UDM1.
6. Execute DEFINE_ON_DEMAND function "massflow_mark".
7. This will print the mass flow rate through the boundary zone in the fluent console.
8. You can display the contours of UDMs.

UDF is pasted below -

/* UDF to calculate mass flux through a boundary face and mark the adjacent cells based on +/- mass flux */
/* Cells with Positive mass flux (out of the domain) is marked with a UDM0 value of 1
Cells with Negative mass flux (in to the domain) is marked with a UDM0 value of -1 */
/* UDM1 is used to mark the cells with the mass flux value through the adjacent face */

/* Please note that this UDF will work only for Segregated Solver and only for Boundary Zones
(not for interior zones) */

/* Written by: Vishak T, Michael Ruith - Fluent Inc. */

#include "udf.h"

#define tid 6 /* Thread id of the face on which mass flow rate is required */

Domain *d = Get_Domain(1);
Thread *tf=Lookup_Thread(d, tid);
face_t f;
cell_t c0, c1, c;
Thread *tc0, *tc1, *tc;
real mass_flux;
real pos_mass_flux=0, neg_mass_flux=0;
int countpos=1, countneg=1;

thread_loop_c(tc, d)
C_UDMI(c, tc,0)= 0;
C_UDMI(c, tc,1)= 0;
end_c_loop(c, tc)


if(tc1!=NULL) /* if the face is not a boundary face */
Error(" Zone : %d is not a boundary face n", tid);

mass_flux = F_FLUX(f,tf);

C_UDMI(c0,tc0,0)= -1;
C_UDMI(c0,tc0,1)= mass_flux;
C_UDMI(c0,tc0,0)= 1;
C_UDMI(c0,tc0,1)= mass_flux;
end_f_loop(f, tf)

Message("nMass flow rate in to the domain (through %d faces): %g kg/sn", countneg, neg_mass_flux);
Message("nMass flow rate out of the domain (through %d faces): %g kg/s n", countpos, pos_mass_flux);


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