2.5.10.  DEFINE_DPM_SCALAR_UPDATE

2.5.10.1. Description

You can use DEFINE_DPM_SCALAR_UPDATE to update scalar quantities every time a particle position is updated. The function allows particle-related variables to be updated or integrated over the life of the particle. Particle values can be stored in an array associated with the Tracked_Particle (accessed with the macro TP_USER_REAL(tp,i)). Values calculated and stored in the array can be used to color the particle trajectory.

During ANSYS Fluent execution, the DEFINE_DPM_SCALAR_UPDATE function is called at the start of particle integration (when initialize is equal to ) and then after each time step for the particle trajectory integration.

2.5.10.2. Usage

DEFINE_DPM_SCALAR_UPDATE (name, c, t, initialize, tp)

Argument Type

Description

symbol name

UDF name.

cell_t c

Index that identifies the cell that the particle is currently in.

Thread *t

Pointer to the thread the particle is currently in.

int initialize

Variable that has a value of when the function is called at the start of the particle integration, and thereafter.

Tracked_Particle *tp

Pointer to the Tracked_Particle data structure which contains data related to the particle being tracked.

Function returns

void

There are five arguments to DEFINE_DPM_SCALAR_UPDATE: name, c, t, initialize, and tp. You supply name, the name of the UDF. c, t, initialize, and tp are variables that are passed by the ANSYS Fluent solver to your UDF.


Important:  Pointer tp can be used as an argument to the macros defined in DPM Macros to obtain information about particle properties (for example, injection properties). Also, the real array user is available for storage. The size of this array should be set in the Discrete Phase Model dialog box in the Number of Scalars field.


2.5.10.3. Example

The following compiled UDF computes the melting index along a particle trajectory. The DEFINE_DPM_SCALAR_UPDATE function is called at every particle time step in ANSYS Fluent and requires a significant amount of CPU time to execute.

The melting index is computed from

(2–20)

Also included in this UDF is an initialization function DEFINE_INIT that is used to initialize the scalar variables. DPM_OUTPUT is used to write the melting index at sample planes and surfaces. The macro NULLP(p), which expands to ((p) == NULL), checks if its argument p is a null pointer.

/*********************************************************************
   UDF for computing the melting index along a particle trajectory
 **********************************************************************/
 #include "udf.h"
 
 DEFINE_INIT(melt_setup,domain)
 {
    /* if memory for the particle variable titles has not been
   * allocated yet, do it now */
    if (NULLP(user_particle_vars)) Init_User_Particle_Vars();
      /* now set the name and label */
      strcpy(user_particle_vars[0].name,"melting-index");
      strcpy(user_particle_vars[0].label,"Melting Index");
      strcpy(user_particle_vars[1].name,"melting-index-0");
      strcpy(user_particle_vars[1].label,"Melting Index 0");
 }
 
 /* update the user scalar variables */
 DEFINE_DPM_SCALAR_UPDATE(melting_index,cell,thread,initialize,tp)
 {
    cphase_state_t *c = &(tp->cphase[0]);
    if (initialize)
      {
     /* this is the initialization call, set:
     * TP_USER_REAL(tp,0) contains the melting index, initialize to 0
     * TP_USER_REAL(tp,1) contains the viscosity at the start of a time step*/
     TP_USER_REAL(tp,0) = 0.;
     TP_USER_REAL(tp,1) = c->mu;
      }
    else
      {
       /* use a trapezoidal rule to integrate the melting index */
       TP_USER_REAL(tp,0) += TP_DT(tp) * .5 * (1/TP_USER_REAL(tp,1) + 1/c->mu);
       /* save current fluid viscosity for start of next step */   
      TP_USER_REAL(tp,1) = c->mu;
      }
   }
 
 /* write melting index when sorting particles at surfaces */
 DEFINE_DPM_OUTPUT(melting_output,header,fp,tp,thread,plane)
 {
    char name[100];
    if (header)
    {
     if (NNULLP(thread))
       par_fprintf_head(fp,"(%s %d)\n",THREAD_HEAD(thread)->
         dpm_summary.sort_file_name,11);
     else
       par_fprintf_head(fp,"(%s %d)\n",plane->sort_file_name,11);
       par_fprintf_head(fp,"(%10s %10s %10s %10s %10s %10s %10s"
        " %10s %10s %10s %10s %s)\n",
        "X","Y","Z","U","V","W","diameter","T","mass-flow",
        "time","melt-index","name");
      }
    else
      {
       sprintf(name,"%s:%d",TP_INJECTION(tp)->name,TP_ID(tp));
       /* add P_INJ_ID(TP_INJECTION(tp)) and part_id for sorting in parallel */
       par_fprintf(fp,
          "%d %d ((%10.6g %10.6g %10.6g %10.6g %10.6g %10.6g "
          "%10.6g %10.6g %10.6g %10.6g %10.6g) %s)\n",
        P_INJ_ID(TP_INJECTION(tp)), TP_ID(tp),
        TP_POS(tp)[0], TP_POS(tp)[1], TP_POS(tp)[2],
        TP_VEL(tp)[0], TP_VEL(tp)[1], TP_VEL(tp)[2],
        TP_DIAM(tp), TP_T(tp), TP_FLOW_RATE(tp), TP_TIME(tp),
        TP_USER_REAL(tp,0), name);
      }
 } 

2.5.10.4. Hooking a DPM Scalar Update UDF to ANSYS Fluent

After the UDF that you have defined using DEFINE_DPM_SCALAR_UPDATE is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument will become visible in the Discrete Phase Model dialog box in ANSYS Fluent.

See Hooking DEFINE_DPM_SCALAR_UPDATE UDFs for details on how to hook your DEFINE_DPM_SCALAR_UPDATE UDF to ANSYS Fluent.


Release 18.2 - © ANSYS, Inc. All rights reserved.