c is an index that identifies a cell within the given thread. t is a pointer to the thread on which the material property definition is to be applied.
Note that like source term UDFs, property UDFs (defined using DEFINE_PROPERTY) are called by FLUENT from within a loop on cell threads. The solver passes to a DEFINE_PROPERTY UDF all of the necessary variables it needs to define a custom material, since properties are assigned on a cell basis. Consequently, your UDF will not need to loop over cells in a zone since FLUENT is already doing it. Your UDF will only be required to compute the property for a single cell and return the real value to the solver, as shown in the 例子: below. 例子:
下面的UDF名字为cell_viscosity, generates a variable viscosity profile to simulate solidification. The function is called for every cell in the zone. The viscosity in the warm ( T > 288 K) fluid has a molecular value for the liquid (5.5 kg/m-s), while the viscosity for the cooler region ( T < 286 K) has a much larger value (1.0 kg/m-s). In the intermediate temperature range (286 K 288 K), the viscosity follows a linear profile that extends between the two values given above:
(4.3.8)
This model is based on the assumption that as the liquid cools and rapidly becomes more viscous, its velocity will decrease, thereby simulating solidification. Here, no correction is made for the energy field to include the latent heat of freezing. The UDF can be executed as interpreted or compiled in FLUENT.
/*********************************************************************/
/* UDF that simulates solidification by specifying a temperature- */
/* dependent viscosity property */ /*********************************************************************/
#include \
DEFINE_PROPERTY(cell_viscosity, c, t) {
real mu_lam;
real temp = C_T(c, t);
if (temp > 288.) mu_lam = 5.5e-3; else if (temp > 286.)
mu_lam = 143.2135 - 0.49725 * temp; else
mu_lam = 1.;
return mu_lam; }
The function cell_viscosity is defined on a cell. Two real variables are introduced: temp, the value of C_T(c,t), and mu_lam, the laminar viscosity computed by the function. The value of the temperature is checked, and based upon the range into which it falls, the appropriate value of mu_lam is computed. At the end of the function, the computed value for the viscosity ( mu_lam) is returned to the solver. Activating a Material Property UDF in FLUENT
Once you have compiled and linked your property UDF, you can activate it by selecting it in the Materials panel in FLUENT. See Section 8.2.4 for more details. 4.3.7 DEFINE_SCAT_PHASE_FUNC 功能和使用方法的介绍
你可以使用DEFINE_SCAT_PHASE_FUNC macro to define the radiation scattering phase function for the discrete ordinates model. The function computes two values: the fraction of radiation energy scattered from direction i to direction j, and the forward scattering factor.
Macro: DEFINE_SCAT_PHASE_FUNC ( name, cosine, f ) Argument types: real cosine
There are three arguments to DEFINE_SCAT_PHASE_FUNC: name, cosine, and f. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 cosine and f are variables that are passed by the FLUENT solver to your UDF.
real *f Function returns: real cosine is a real variable that is the cosine of the angle between the two directions. f is a real pointer that points to the location in memory where the real forward scattering factor is stored. The solver computes and stores a scattering matrix for each material by calling this function for each unique pair of discrete ordinates. Your UDF will need to return the fraction of radiation energy scattered from direction i to direction j to the solver, as shown in the 例子: below. The forward scattering factor is stored in the real variable that is referenced by the pointer f. 例子:
在下面的例子中,:, a number of UDFs are concatenated in a single C source file. These UDFs implement backward and forward scattering phase functions that are cited by Jendoubi et al. [ 1]. The source code can be executed as interpreted or compiled in FLUENT.
/*******************************************************************/ /* UDFs that implement backward and forward scattering */ /* phase functions as cited by Jendoubi et. al. */
/*******************************************************************/
#include \
DEFINE_SCAT_PHASE_FUNC(ScatPhiB2, c, fsf) {
real phi=0; *fsf = 0;
phi = 1.0 - 1.2*c + 0.25*(3*c*c-1); return (phi); }
DEFINE_SCAT_PHASE_FUNC(ScatPhiB1, c,fsf) {
real phi=0; *fsf = 0;
phi = 1.0 - 0.56524*c + 0.29783*0.5*(3*c*c-1) +
0.08571*0.5*(5*c*c*c-3*c) + 0.01003/8*(35*c*c*c*c-30*c*c+3) + 0.00063/8*(63*c*c*c*c*c-70*c*c*c+15*c); return (phi); }
DEFINE_SCAT_PHASE_FUNC(ScatPhiF3, c, fsf) {
real phi=0; *fsf = 0;
phi = 1.0 + 1.2*c + 0.25*(3*c*c-1);
return (phi); }
DEFINE_SCAT_PHASE_FUNC(ScatPhiF2, c, fsf) {
real phi=0;
real coeffs[9]={1,2.00917,1.56339,0.67407,0.22215,0.04725, 0.00671,0.00068,0.00005}; real P[9]; int i; *fsf = 0; P[0] = 1; P[1] = c;
phi = P[0]*coeffs[0] + P[1]*coeffs[1]; for(i=1;i<7;i++) {
P[i+1] = 1/(i+1.0)*((2*i+1)*c*P[i] - i*P[i-1]); phi += coeffs[i+1]*P[i+1]; }
return (phi); }
DEFINE_SCAT_PHASE_FUNC(ScatIso, c, fsf) {
*fsf=0; return (1.0); }
Activating a Radiation Scattering Phase UDF in FLUENT
Once you have compiled and linked your scattering phase UDF, you can activate it by selecting it in the Materials panel in FLUENT. See Section 8.2.4 for more details. 4.3.8 DEFINE_SOURCE 功能和使用方法的介绍
你可以使用DEFINE_SOURCE macro to define custom source terms for the different types of solved transport equations in FLUENT (except the discrete ordinates radiation model) including:
? ? ? ? ?
continuity momentum k,
energy (also for solid zones) species mass fractions
?
user-defined scalar (UDS) transport
Macro: DEFINE_SOURCE ( name, c, t, dS, eqn) Argument types: cell_t c Thread *t real dS[] int eqn Function returns: real
There are five arguments to DEFINE_SOURCE: name, c, t, dS, and eqn. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 c, t, dS, and eqn are variables that are passed by the FLUENT solver to your UDF.
c is the index of a cell on the thread pointed to by t. This is the cell in which the source term is to be applied. Array dS specifies the derivative of the source term with respect to the dependent variable of the transport equation. These derivatives may be used to linearize the source term if they enhance the stability of the solver. To see this, note that the source term can be expressed, in general, as Equation 4.3-10, where is the dependent variable, A is the explicit part of the source term, and implicit part.
is the
(4.3.9)
Specifying a value for B in Equation 4.3-10 can enhance the stability of the solution and help convergence rates due to the increase in diagonal terms on the solution matrix. FLUENT automatically determines if the value of B that is given by the user will aid stability. If it does, then FLUENT will define A as
, and
B as . If not, the source term is handled explicitly. Your UDF will need to return the real value of the total source term to the solver, but you have the choice of setting the implicit term dS[eqn] to , or forcing the explicit solution of the source term by setting it equal to 0.0. See Section 1.5.1 for a list of the transport