![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Description
You can use DEFINE_SOURCE to specify custom source terms for the different types of solved transport equations in ANSYS FLUENT (except the discrete ordinates radiation model) including:
Usage
DEFINE_SOURCE( name, c, t, dS, eqn) |
Argument Type | Description |
symbol name | UDF name. |
cell_t c | Index that identifies cell on which the source term is to be applied. |
Thread *t | Pointer to cell thread. |
real dS[] | Array that contains the derivative of the source term with respect |
to the dependent variable of the transport equation. | |
int eqn | Equation number. |
Function returns | |
real | |
There are five arguments to
DEFINE_SOURCE:
name,
c,
t,
dS, and
eqn. You supply
name, the name of the UDF.
c,
t,
dS, and
eqn are variables that are passed by the
ANSYS FLUENT solver to your UDF. Note that the source term derivatives may be used to linearize the source term if they enhance the stability of the solver. To illustrate this, note that the source term can be expressed, in general, as Equation
2.3-9, where
is the dependent variable,
is the explicit part of the source term, and
is the implicit part.
Specifying a value for
in Equation
2.3-9 can enhance the stability of the solution and help convergence rates due to the increase in diagonal terms on the solution matrix.
ANSYS FLUENT automatically determines if the value of
that is given by the user will aid stability. If it does, then
ANSYS FLUENT will define
as
, and
as
. If not, the source term is handled explicitly.
Your UDF will need to compute the
real source term
only for a single cell and return the value 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
.
Note that like property UDFs, source term UDFs (defined using DEFINE_SOURCE) are called by ANSYS FLUENT from within a loop on cell threads. The solver passes to the DEFINE_SOURCE term UDF all the necessary variables it needs to define a custom source term, since source terms are solved on a cell basis. Consequently, your UDF will not need to loop over cells in the thread since ANSYS FLUENT is already doing it.
The units on all source terms are of the form generation-rate/volume. For example, a source term for the continuity equation would have units of kg/m
-s.
Example 1 - Source Term Addition
The following UDF, named
xmom_source, is used to add source terms in
ANSYS FLUENT. The source code can be interpreted or compiled. The function generates an
-momentum source term that varies with
position as
Suppose
where
Then
The source term returned is
and the derivative of the source term with respect to
(true for both positive and negative values of
) is
/*******************************************************************/ /* UDF for specifying an x-momentum source term in a spatially */ /* dependent porous media */ /*******************************************************************/ #include "udf.h" #define C2 100.0 DEFINE_SOURCE(xmom_source,c,t,dS,eqn) { real x[ND_ND]; real con, source; C_CENTROID(x,c,t); con = C2*0.5*C_R(c,t)*x[1]; source = -con*fabs(C_U(c, t))*C_U(c,t); dS[eqn] = -2.*con*fabs(C_U(c,t)); return source; } |
Example 2 - Degassing Boundary Condition
The following UDFs are used to define the bottom surface as a standard velocity inlet for the gas (primary) phase. The inlet VOF of the droplet phase is 0 and a negative source term for secondary phase mass conservation is set for the layer of cells next to the outlet. The source removes all secondary phase mass in the cell during one time step. The recoil force due to the mass source is also calculated.
/*******************************************************************/ /*This UDF is an implementation of the degassing boundary condition*/ /*******************************************************************/ #include "udf.h" #include "sg.h" #include "sg_mphase.h" #include "flow.h" #include "mem.h" #include "metric.h" DEFINE_SOURCE(degassing_source, cell, thread, dS, eqn) { real source; Thread *tm = THREAD_SUPER_THREAD(thread); source = -C_R(cell,thread)*C_VOF(cell,thread)/CURRENT_TIMESTEP ; C_UDMI(cell,tm,0) = source; dS[eqn] = -C_R(cell,thread)/CURRENT_TIMESTEP; return source; } DEFINE_SOURCE(x_prim_recoil, cell, tp, dS, eqn) { real source; Thread *tm = THREAD_SUPER_THREAD(tp); Thread *ts; ts = THREAD_SUB_THREAD(tm,1); source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_U(cell,tp); dS[eqn] =-C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP; return source; } DEFINE_SOURCE(x_sec_recoil, cell, ts, dS, eqn) { real source; Thread *tm = THREAD_SUPER_THREAD(ts); source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_U(cell,ts); dS[eqn] = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP; return source; } DEFINE_SOURCE(y_prim_recoil, cell, tp, dS, eqn) { real source; Thread *tm = THREAD_SUPER_THREAD(tp); Thread *ts; ts = THREAD_SUB_THREAD(tm,1); source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_V(cell,tp); dS[eqn] =-C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP; return source; } DEFINE_SOURCE(y_sec_recoil, cell, ts, dS, eqn) { real source; Thread *tm = THREAD_SUPER_THREAD(ts); source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_V(cell,ts); dS[eqn] = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP; return source; } DEFINE_SOURCE(z_prim_recoil, cell, tp, dS, eqn) { real source; Thread *tm = THREAD_SUPER_THREAD(tp); Thread *ts; ts = THREAD_SUB_THREAD(tm,1); source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_W(cell,tp); dS[eqn] =-C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP; return source; } DEFINE_SOURCE(z_sec_recoil, cell, ts, dS, eqn) { real source; Thread *tm = THREAD_SUPER_THREAD(ts); source = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP*C_W(cell,ts); dS[eqn] = -C_R(cell,ts)*C_VOF(cell,ts)/CURRENT_TIMESTEP; return source; } |
Hooking a Source UDF to
ANSYS FLUENT
After the UDF that you have defined using DEFINE_SOURCE is interpreted (Chapter 4) or compiled (Chapter 5), the name of the argument that you supplied as the first DEFINE macro argument (e.g., xmom_source) will become visible and selectable in the Fluid or Solid cell zone condition dialog box in ANSYS FLUENT. See Section 6.2.19 for details.