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:
mass
momentum
,
energy (also for solid zones)
species mass fractions
P1 radiation model
user-defined scalar (UDS) transport
granular temperature (Eulerian, Mixture multiphase models)
DEFINE_SOURCE (name, c, t, dS, eqn)
|
Argument Type |
Description |
|---|---|
|
|
UDF name. |
|
|
Index that identifies cell on which the source term is to be applied. |
|
|
Pointer to cell thread. |
|
|
Array that contains the derivative of the source term with respect to the dependent variable of the transport equation. |
|
|
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–10, where is the dependent variable,
is the explicit part of
the source term, and
is the implicit part.
(2–10) |
Specifying a value for in Equation 2–10 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 you 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
must 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/m3-s.
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;
}
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;
}
After the UDF that you have defined using DEFINE_SOURCE is interpreted (Interpreting UDFs)
or compiled (Compiling UDFs), the name
of the argument that you supplied as the first DEFINE macro argument (for example, xmom_source) will become visible and selectable in the Fluid or Solid cell zone condition dialog box in ANSYS Fluent.
See Hooking DEFINE_SOURCE UDFs for details.