![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
This section contains an example of a custom reaction rate UDF. It is executed as a compiled UDF in ANSYS FLUENT.
Volume Reaction Rate
A custom volume reaction rate for a simple system of two gaseous species is considered. The species are named species-a and species-b. The reaction rate is one that converts species-a into species-b at a rate given by the following expression:
where
is the mass fraction of
species-a, and
and
are constants.
The 2D (planar) domain consists of a 90-degree bend. The duct has a porous region covers the bottom and right-hand wall, and the reaction takes place in the porous region only. The species in the duct have identical properties. The density is 1.0 kg/m
, and the viscosity is 1.7894
kg/m-s.
The outline of the domain is shown in Figure 8.2.23. The porous medium is the region below and to the right of the line that extends from the inlet on the left to the pressure outlet at the top of the domain.
Through the inlet on the left, gas that is purely
species-a enters with an
velocity of 0.1 m/s. The gas enters both the open region on the top of the porous medium and the porous medium itself, where there is an inertial resistance of 5 m
in each of the two coordinate directions. The laminar flow field (Figure
8.2.24) shows that most of the gas is diverted from the porous region into the open region.
The flow pattern is further substantiated by the vector plot shown in Figure 8.2.25. The flow in the porous region is considerably slower than that in the open region.
The source code ( rate.c) that contains the UDF used to model the reaction taking place in the porous region is shown below. The function, named vol_reac_rate, is defined on a cell for a given species mass fraction using DEFINE_VR_RATE . The UDF performs a test to check for the porous region, and only applies the reaction rate equation to the porous region. The macro FLUID_THREAD_P(t) is used to determine if a cell thread is a fluid (rather than a solid) thread. The variable THREAD_VAR(t).fluid.porous is used to check if a fluid cell thread is a porous region.
/****************************************************************** rate.c Compiled UDF for specifying a reaction rate in a porous medium *******************************************************************/ #include "udf.h" #define K1 2.0e-2 #define K2 5. DEFINE_VR_RATE(vol_reac_rate,c,t,r,mole_weight,species_mf,rate,rr_t) { real s1 = species_mf[0]; real mw1 = mole_weight[0]; if (FLUID_THREAD_P(t) && THREAD_VAR(t).fluid.porous) *rate = K1*s1/pow((1.+K2*s1),2.0)/mw1; else *rate = 0.; *rr_t = *rate; } |
This UDF is executed as a compiled UDF in ANSYS FLUENT. Follow the procedure for compiling source files using the Compiled UDFs dialog box that is described in Section 5.2.
After the function vol_reac_rate is compiled and loaded, you can hook the reaction rate UDF to ANSYS FLUENT by selecting the function's name in the Volume Reaction Rate Function drop-down list in the User-Defined Function Hooks dialog box (Figure 6.2.36).
Define
User-Defined
Function Hooks...
Initialize and run the calculation. The converged solution for the mass fraction of species-a is shown in Figure 8.2.27. The gas that moves through the porous region is gradually converted to species-b in the horizontal section of the duct. No reaction takes place in the fluid region, although some diffusion of species-b out of the porous region is suggested by the wide transition layer between the regions of 100% and 0% species-a.