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 */

DEFINE_ON_DEMAND(massflow_mark)
{
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)
{
begin_c_loop(c,tc)
{
C_UDMI(c, tc,0)= 0;
C_UDMI(c, tc,1)= 0;
}
end_c_loop(c, tc)
}

begin_f_loop(f,tf)
{
c0=F_C0(f,tf);
tc0=THREAD_T0(tf);
c1=F_C1(f,tf);
tc1=THREAD_T1(tf);

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);

if(mass_flux<0)
{
C_UDMI(c0,tc0,0)= -1;
C_UDMI(c0,tc0,1)= mass_flux;
neg_mass_flux+=mass_flux;
countneg++;
}
else
{
C_UDMI(c0,tc0,0)= 1;
C_UDMI(c0,tc0,1)= mass_flux;
pos_mass_flux+=mass_flux;
countpos++;
}
}
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!