[ANSYS, Inc. Logo] return to home search
next up previous contents index

2.3.19 DEFINE_SOURCE



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 $\phi$ is the dependent variable, $A$ is the explicit part of the source term, and $B\phi$ is the implicit part.


 S_\phi = A + B \phi (2.3-9)

Specifying a value for $B$ 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 $B$ that is given by the user will aid stability. If it does, then ANSYS FLUENT will define $A$ as $S^*-(\partial S / \partial \phi)^*\phi^*$, and $B$ as $(\partial S / \partial \phi)^*$. 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 $dS / d\phi$, or forcing the explicit solution of the source term by setting it equal to $0.0$.

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 $^3$-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 $x$-momentum source term that varies with $y$ position as


{\rm source} = -0.5 C_2 \rho y \vert v_x\vert v_x

Suppose


{\rm source} = S = -A \vert v_x\vert v_x

where


A = 0.5 C_2 \rho y

Then


\frac{dS}{dv_x} = -A \vert v_x\vert -A v_x \frac{d}{dv_x} \left( \vert v_x\vert \right)

The source term returned is


{\rm source} = - A \vert v_x\vert v_x

and the derivative of the source term with respect to $v_x$ (true for both positive and negative values of $v_x$) is


\frac{dS}{dv_x} = -2 A \vert v_{x}\vert

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


next up previous contents index Previous: 2.3.18 DEFINE_SOLAR_INTENSITY
Up: 2.3 Model-Specific DEFINE Macros
Next: 2.3.20 DEFINE_SOX_RATE
Release 12.0 © ANSYS, Inc. 2009-01-14