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

11.5.1 Postprocessing Using User-Defined Scalars

Below is an example of a compiled UDF that computes the gradient of temperature to the fourth power, and stores its magnitude in a user-defined scalar. The computed temperature gradient can, for example, be subsequently used to plot contours. Although the practical application of this UDF is questionable, its purpose here is to show the methodology of computing gradients of arbitrary quantities that can be used for postprocessing.

/***********************************************************************/
/* UDF for computing the magnitude of the gradient of T^4              */
/***********************************************************************/

#include "udf.h"

/* Define which user-defined scalars to use. */
enum
{
  T4,
  MAG_GRAD_T4,
  N_REQUIRED_UDS
};

DEFINE_ADJUST(adjust_fcn, domain)
{
  Thread *t;
  cell_t c;
  face_t f;


  /* Make sure there are enough user-defined scalars. */
  if (n_uds < N_REQUIRED_UDS)
    Internal_Error("not enough user-defined scalars allocated");
  /* Fill first UDS with temperature raised to fourth power. */  
  thread_loop_c (t,domain)
    {
      if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)))
        {
          begin_c_loop (c,t)
            {
              real T = C_T(c,t);
              C_UDSI(c,t,T4) = pow(T,4.);
            }
          end_c_loop (c,t)
        }
    }


  thread_loop_f (t,domain)
    {
      if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)))
        {
          begin_f_loop (f,t)
            {
              real T = 0.;
              if (NULL != THREAD_STORAGE(t,SV_T))
                T = F_T(f,t);
              else if (NULL != THREAD_STORAGE(t->t0,SV_T))
                T = C_T(F_C0(f,t),t->t0);
              F_UDSI(f,t,T4) = pow(T,4.);
            }
          end_f_loop (f,t)
        }
    }

  /* Fill second UDS with magnitude of gradient. */
  thread_loop_c (t,domain)
    {
      if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)) &&
          NULL != T_STORAGE_R_NV(t,SV_UDSI_G(T4)))
       {
          begin_c_loop (c,t)
            {
              C_UDSI(c,t,MAG_GRAD_T4) = NV_MAG(C_UDSI_G(c,t,T4));
            }
          end_c_loop (c,t)
        }
    }

  thread_loop_f (t,domain)
    {
      if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)) &&
          NULL != T_STORAGE_R_NV(t->t0,SV_UDSI_G(T4)))
       {
          begin_f_loop (f,t)
           {
            F_UDSI(f,t,MAG_GRAD_T4)=C_UDSI(F_C0(f,t),t->t0,MAG_GRAD_T4);
           }
          end_f_loop (f,t)
        }
    }
}

The conditional statement if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4))) is used to check if the storage for the user-defined scalar with index T4 has been allocated, while NULL != T_STORAGE_R_NV(t,SV_UDSI_G(T4)) checks whether the storage of the gradient of the user-defined scalar with index T4 has been allocated.

In addition to compiling this UDF, as described in Chapter  7, you will need to enable the solution of a user-defined scalar transport equation in FLUENT.

Define $\rightarrow$ User-Defined $\rightarrow$ Scalars...

See Section  10.3 for more details.


next up previous contents index Previous: 11.5 User-Defined Scalars
Up: 11.5 User-Defined Scalars
Next: 11.5.2 Implementing FLUENT's P-1
© Fluent Inc. 2003-01-22