2.2.1.  DEFINE_ADJUST

2.2.1.1. Description

DEFINE_ADJUST is a general-purpose macro that can be used to adjust or modify ANSYS Fluent variables that are not passed as arguments. For example, you can use DEFINE_ADJUST to modify flow variables (for example, velocities, pressure) and compute integrals. You can also use it to integrate a scalar quantity over a domain and adjust a boundary condition based on the result. A function that is defined using DEFINE_ADJUST executes at every iteration and is called at the beginning of every iteration before transport equations are solved. For an overview of the ANSYS Fluent solution process which shows when a DEFINE_ADJUST UDF is called, refer to Figure 1.2: Solution Procedure for the Pressure-Based Segregated Solver, Figure 1.3: Solution Procedure for the Pressure-Based Coupled Solver, and Figure 1.4: Solution Procedure for the Density-Based Solver.

2.2.1.2. Usage

DEFINE_ADJUST (name, d)

Argument Type

Description

symbol name

UDF name.

Domain *d

Pointer to the domain over which the adjust function is to be applied. The domain argument provides access to all cell and face threads in the mesh. For multiphase flows, the pointer that is passed to the function by the solver is the mixture-level domain.

Function returns

void

There are two arguments to DEFINE_ADJUST: name and d. You supply name, the name of the UDF. d is passed by the ANSYS Fluent solver to your UDF.

2.2.1.3. Example 1

The following UDF, named my_adjust, integrates the turbulent dissipation over the entire domain using DEFINE_ADJUST. This value is then displayed in the console. The UDF is called once every iteration. It can be executed as an interpreted or compiled UDF in ANSYS Fluent.

/********************************************************************
   UDF for integrating turbulent dissipation and displaying it in the
   console
 *********************************************************************/
 
 #include "udf.h"
 
 DEFINE_ADJUST(my_adjust,d)
 {
    Thread *t;
    /* Integrate dissipation. */
    real sum_diss=0.;
    cell_t c;

    thread_loop_c(t,d)
    {
     begin_c_loop(c,t)
      sum_diss += C_D(c,t)*
      C_VOLUME(c,t);
     end_c_loop(c,t)
    }

    printf("Volume integral of turbulent dissipation: %g\n", sum_diss);
 } 

2.2.1.4. Example 2

The following UDF, named adjust_fcn, specifies a user-defined scalar as a function of the gradient of another user-defined scalar, using DEFINE_ADJUST. The function is called once every iteration. It is executed as a compiled UDF in ANSYS Fluent.

/********************************************************************
   UDF for defining user-defined scalars and their gradients
 *********************************************************************/
 
 #include "udf.h"
 
 DEFINE_ADJUST(adjust_fcn,d)
 {
    Thread *t;
    cell_t c;
    real K_EL = 1.0;

    /* Do nothing if gradient isn’t allocated yet. */
    if (! Data_Valid_P())
      return;

    thread_loop_c(t,d)
      {
      if (FLUID_THREAD_P(t))
        {
         begin_c_loop_all(c,t)
            {
            C_UDSI(c,t,1) +=
                    K_EL*NV_MAG2(C_UDSI_G(c,t,0))*C_VOLUME(c,t);
            }
         end_c_loop_all(c,t)
        }
      }
 } 

2.2.1.5. Hooking an Adjust UDF to ANSYS Fluent

After the UDF that you have defined using DEFINE_ADJUST is interpreted (Interpreting UDFs) or compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, adjust_fcn) will become visible and selectable via the User-Defined Function Hooks dialog box in ANSYS Fluent. Note that you can hook multiple adjust functions to your model. See Hooking DEFINE_ADJUST UDFs for details.


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