Lecture 4: User Defined Memory and Scalars Lecture 4: User Defined Memory and Scalars ANSYS Fluent Using User-Defined Functions (UDFs) Release 2019 R3 11 © 2019 ANSYS, Inc. User-Defined Memories (UDMs) • Useful to define extra field variables to store and retrieve values defined by the user. • User-defined Memories (UDMs) are defined in • Up to 500 UDMs can be used to store and retrieve user values. • They can be plotted in contours and are saved in the data file. • These values are not changed by Fluent, only within a UDF 2 © 2019 ANSYS, Inc. Access UDMs within a UDF • Stores the face value of a user-defined memory with index i. F_UDMI(face,thread,index) • Stores the cell value of a user-defined memory with index i. Depends on UDM definition. C_UDMI(cell,thread,index) • Stores the node value of a user-defined memory with index i. N_UDMI(node,index) • • • 3 Note that if you try to use F_UDMI, C_UDMI, or N_UDMI before you have allocated memory, then an error will result. Both C_UDMI and N_UDMI can be post-processed: Default names are User Memory 0, etc. and User Node Memory 0, etc. N_UDM and N_NODE_UDM provide the number of user-defined memory locations and userdefined memory node locations that have been used. © 2019 ANSYS, Inc. User-Defined Scalars (UDS) • Fluent can solve the transport equations for N user-defined scalars (UDS) governed by the generic PDEs Unsteady Advection Diffusion Sources where πͺπͺππ is the diffusion coefficient and πΊπΊππ the term which you supply for each of the N scalar equations. User-Defined Scalars are defined in 4 © 2019 ANSYS, Inc. source User-Defined Scalars: Settings • Each scalar equation can be set to be only calculated in • Each scalar equation can have different flux function settings • Each scalar equation can be separately considered as steady or unsteady. – However, unsteady is only available when case defined as transient 5 © 2019 ANSYS, Inc. User-Defined Scalars: UDF-Macros (1) Unsteady • Unsteady: Advection Diffusion Sources See UDS workshop for more details about the unsteady UDS functions. − None: Steady State case (unsteady term neglected) − Default: Use default definition for the unsteady term − Customize by using real DEFINE_UDS_UNSTEADY(udf_name,c,t,i,apu,su) • Advective Flux: − Mass flow rate: means that ππππ = ππππππ is used − None: Advection term is neglected − Customize by using 6 © 2019 ANSYS, Inc. real DEFINE_UDS_FLUX(udf_name,f,t,i) User-Defined Scalars: DEFINE_UDS_FLUX • Advection term given in its most general form: (If “mass flow rate” is chosen, ππ = ππππ is used.) • To define the advection term using your UDF must return the scalar value ππ οΏ½ ππππ real DEFINE_UDS_FLUX(udf_name,f,t,i) ππ οΏ½ π¨π¨ where π¨π¨ is the face normal vector of the face. Note: The advective flux field supplied by your UDF should be divergence-free. 7 © 2019 ANSYS, Inc. User-Defined Scalars: UDF-Macros (2) Unsteady • Advection Diffusion Sources Diffusion: The diffusivity of the scalar must be defined in the material property panel for each material. Default diffusivity for all scalars is 1.0. This constant can be changed to a different value or customized using real DEFINE_DIFFUSIVITY(udf_name,c,t,i) • Sources: Source terms for scalars are set using the standard macro introduced before. real DEFINE_SOURCES(udf_name,c,t,dS,eqn) 8 © 2019 ANSYS, Inc. User-defined Scalars: Boundary Conditions • Boundary conditions for the scalars are defined in the boundary condition panel in the UDS tab. Options to specify are • Specified value − − Constant UDF Profile • Specified Flux − Constant − UDF Profile 9 © 2019 ANSYS, Inc. Example: Post-processing – Gradient Vector of a UDS with UDMs #include "udf.h" DEFINE_ADJUST(set_uds0_gradient_magnitude, domain) { Thread *ct; cell_t c; int index; index = 0; /* Could do a loop over N_UDS, the number of UDSs */ /* or over N_UDM, the number of UDMs defined. */ thread_loop_c(ct,domain) { begin_c_loop(c,ct) { /* The gradient vector of many calculated values can be got */ /* by adding _G to the standard variable name: C_T_G(c,ct) */ C_UDMI(c,ct,index) = NV_MAG(C_UDSI_G(c,ct,index)); } end_c_loop(c,ct) } } 10 © 2019 ANSYS, Inc. • This DEFINE_ADJUST sets a UDM to the magnitude of the spatial gradient vector of a UDS so that contours and other post-processing can be done on the gradient. • N_UDS provides the number of user-defined scalar transport equations • The UDS gradient can be accessed by C_UDSI_G(c,ct,index ) (see next slide) Gradient Vector Macros • For many of the cell variables, the gradient (G) can be accessed – identified by the suffix _G. Example: Cell temperature C_T, and the temperature gradient C_T_G. • Macros as C_U_G are not always available since the solver removes data from memory that it does not need. Prevent the solver from freeing up memory by using the TUI command • For more details see ANSYS Fluent Customization Manual 3.2.3.7 Gradient (G) and Reconstruction Gradient (RG) Vector Macros 11 © 2019 ANSYS, Inc.