User-Defined Memory (UDM) and User-Defined Scalars (UDS) in ANSYS Fluent

Welcome to the third part of our User-Defined Functions (UDFs) series for ANSYS Fluent! After covering UDF basics and UDF macros in our earlier blogs, we’re now going to look at two very useful features: User-Defined Memory (UDM) and User-Defined Scalars (UDS).

Sometimes the standard CFD simulation tools just aren’t enough for special engineering problems. That’s where these features come in handy. They let you create custom physics models and track extra variables in your computational domain. Whether you’re experienced with CFD or just starting to explore Fluent customization, this guide will help you get the most out of UDMs and UDSs in your simulations. Additionally, you can benefit from numerous CFD tutorials provided in our UDF CFD Simulation section of the CFD Shop.

Introduction to UDMs and UDSs

ANSYS Fluent is great for standard fluid flow simulations, but many engineering projects need to track extra variables or solve custom transport equations that aren’t built into the software. This is where User-Defined Memory (UDM) and User-Defined Scalars (UDS) come in.

UDMs let you create and store extra field variables that stay throughout your simulation, while UDSs let you define and solve your own transport equations alongside Fluent’s standard ones. Together with UDFs, these tools help you extend Fluent’s abilities to solve special engineering problems.

Understanding User-Defined Memory (UDM)

What is User-Defined Memory?

User-Defined Memory (UDM) gives you extra field variables so you can store custom data at each cell or face in your mesh. Think of UDMs as extra “containers” attached to each cell or face where you can put any numbers needed for your simulation. Unlike regular Fluent variables that change automatically during solving, UDM values stay the same unless your UDFs change them. This makes them perfect for:

  • Storing calculation results halfway through
  • Keeping track of custom values across iterations
  • Creating special visualization variables
  • Keeping data throughout the simulation
  • Passing information between different UDF macros

Key Features of User-Defined Memory (UDM)

  • Storage space: ANSYS Fluent lets you define up to 500 UDM locations per simulation
  • Saving: UDM values are saved in case and data files, so they’re kept between simulation sessions
  • Viewing: Values can be shown using standard post-processing tools
  • Protection: Only your UDFs can change UDM values, not Fluent itself
  • Easy access: Can be accessed in both cell and face zones (boundary faces only)

How to Define UDMs in ANSYS Fluent

Setting up User-Defined Memory is easy:

  1. Go to Define → User-Defined → User-Defined Memory
  2. Type in the number of UDM locations you need (between 1 and 500)
  3. Click “Apply” to set aside the memory

User-Defined Memory (UDM) and User-Defined Scalars (UDS) in ANSYS Fluent

Figure 1: This picture shows the UDM allocation dialog in ANSYS Fluent

Accessing UDM Values in UDFs

To read or change UDM values in your User-Defined Functions, ANSYS Fluent gives you two special macros:

C_UDMI(c,ct,i) – For accessing cell UDM values

  • c: Cell index
  • ct: Cell thread pointer
  • i: UDM index (starting from 0)

F_UDMI(f,ft,i) – For accessing boundary face UDM values

  • f: Face index
  • ft: Face thread pointer
  • i: UDM index (starting from 0)
  • Note: Only works for boundary faces

You can use these macros on both sides of equal signs, so you can both read and write UDM values.

Practical Example: Storing UDS Gradient Magnitude in UDM

A common use of UDMs is storing calculated values that aren’t directly available in Fluent’s standard variables. Here’s an example that calculates the gradient magnitude of a User-Defined Scalar and stores it in a UDM so you can see it:

#include “udf.h”

DEFINE_ADJUST(set_uds0_gradient_magnitude, domain)

{

Thread *ct;

cell_t c;

int index = 0; /* Could loop over N_UDS or N_UDM */

thread_loop_c(ct, domain)

{

begin_c_loop(c, ct)

{

/* Store magnitude of UDS gradient in UDM */

C_UDMI(c, ct, index) = NV_MAG(C_UDSI_G(c, ct, index));

}

end_c_loop(c, ct)

}

}

This UDF code calculates how fast the first User-Defined Scalar is changing in space, and stores this value in the first UDM location for each cell. You can then view this using contour plots to see where the scalar is changing quickly or slowly throughout your model.

Practical Example 2: Locally Magnetized Vessel Simulation Using UDF & UDM

User-Defined Memory (UDM) and User-Defined Functions (UDFs) show their true power when applied to complex engineering problems. A perfect example is our Locally Magnetized Vessel CFD Simulation, where we model how magnetic fields affect ferrofluids in a vessel with local magnetization. In this advanced simulation:

  • UDM locations store the spatially-varying magnetic field components
  • UDFs implement custom equations that define the magnetic field behavior
  • The simulation captures complex magnetohydrodynamic (MHD) effects that standard Fluent models cannot handle

This tutorial demonstrates how UDMs provide the crucial framework for storing magnetic field data at each computational cell, while UDFs use this stored information to calculate the resulting forces on the ferrofluid. Without UDM capabilities, modeling such specialized physics would be impossible in ANSYS Fluent.

User-Defined Memory (UDM) and User-Defined Scalars (UDS) in ANSYS Fluent

User-Defined Memory (UDM) and User-Defined Scalars (UDS) in ANSYS Fluent

Figure 2: One of the applications of UDM for localized magnetic field

Understanding User-Defined Scalars (UDS)

What are User-Defined Scalars?

While UDMs are simple storage spots, User-Defined Scalars (UDSs) are much more powerful. A UDS is a full transport variable with its own conservation equation that ANSYS Fluent will solve along with the standard flow equations. User-Defined Scalars let you model extra physics beyond what’s available in standard Fluent models. Examples include custom chemical species, special turbulence parameters, or any other quantity that needs to move through your computational domain.

The UDS Transport Equation

ANSYS Fluent solves transport equations for User-Defined Scalars using this general form:

 \frac{\partial(\rho\phi_k)}{\partial t} + \frac{\partial}{\partial x_i}\left(F_i\phi_k - \Gamma_k\frac{\partial\phi_k}{\partial x_i}\right) = S_{\phi_k} \quad k = 1,…,N

This represents a general transport equation for multiple scalar quantities (indexed by k), where:

  • ρ is density
  • φₖ is the scalar variable
  • Fᵢ represents convective flux
  • Γₖ is the diffusion coefficient
  • S_φₖ is the source term
  • The equation applies for k ranging from 1 to N

This equation includes:

  • Unsteady term: ∂(ρφ)/∂t – Represents changes over time
  • Convective term: ∇·(ρvφ) – Accounts for transport due to fluid moving
  • Diffusive term: ∇·(Γ∇φ) – Represents transport due to concentration differences
  • Source term: Sφ – Accounts for creation or destruction of the scalar

Where:

  • φ is the scalar quantity
  • ρ is density
  • v is velocity vector
  • Γ is the diffusion coefficient
  • Sφ is the source term

Setting Up User-Defined Scalars

To define UDSs in ANSYS Fluent:

  1. Go to Define → Models → User-Defined Scalars
  2. Enter the number of scalars you want to solve for
  3. For each scalar, set up:
  • Where it applies (fluid zones, solid zones, or selected zones)
  • Flux function settings
  • Whether to use UDFs to customize parts of the transport equation

User-Defined Memory (UDM) and User-Defined Scalars (UDS) in ANSYS Fluent

Figure 3: UDS setup dialog in ANSYS Fluent

Customizing UDS Properties

Setting Diffusivity

For each User-Defined Scalar, you need to set the diffusion coefficient (Γ):

  1. Go to Define → Materials → Properties
  2. Select the material
  3. Find the UDS Diffusivity section
  4. Enter the diffusion coefficient for each scalar

The default diffusivity is 1.0, but you can:

  • Change it to any constant value
  • Use a DEFINE_DIFFUSIVITY UDF to make it depend on flow conditions

User-Defined Memory (UDM) and User-Defined Scalars (UDS) in ANSYS Fluent

Figure 4: UDS diffusivity settings in material properties

Setting Boundary Conditions

Good boundary conditions are very important for accurate UDS solutions:

  1. Go to Define → Boundary Conditions
  2. Select the boundary you want
  3. Go to the UDS tab
  4. Choose from options like:
  • Constant value
  • Constant flux
  • UDF profile for value or flux

User-Defined Memory (UDM) and User-Defined Scalars (UDS) in ANSYS Fluent

Figure 5: UDS boundary condition settings

Customizing the UDS Transport Equation

ANSYS Fluent gives you several UDF macros to customize different parts of the UDS transport equation:

  1. DEFINE_SOURCE – Add custom source terms

DEFINE_SOURCE(my_source_term, cell, thread, dS, eqn)

{

/* Calculate source term */

*dS = derivative_term; /* For linearization */

return source_value;

}

  1. DEFINE_UDS_FLUX – Customize the convective flux

DEFINE_UDS_FLUX(my_flux, face, thread, i)

{

/* Calculate custom flux */

return flux_value;

}

User-Defined Memory (UDM) and User-Defined Scalars (UDS) in ANSYS Fluent

Figure 6: User-defined Scalars panel box in ANSYS Fluent

3. DEFINE_UDS_UNSTEADY – Modify the unsteady term

DEFINE_UDS_UNSTEADY(my_unsteady, cell, thread, i, apu, phi)

{

/* Custom unsteady term implementation */

}

4. DEFINE_DIFFUSIVITY – Set variable diffusion coefficient

DEFINE_DIFFUSIVITY(my_diffusivity, cell, thread, i)

{

/* Calculate diffusivity based on local conditions */

return diffusivity_value;

}

Comparing UDMs and UDSs

To help understand when to use each tool, here’s a comparison of User-Defined Memory (UDM) and User-Defined Scalars (UDS):

Feature

User-Defined Memory (UDM)

User-Defined Scalar (UDS)

Main Purpose Store custom data Solve additional transport equations
Governing Equation None (storage only) Full transport equation with convection, diffusion, and sources
Maximum Number Up to 500 Limited by computer resources
Access in UDFs C_UDMI, F_UDMI C_UDSI, F_UDSI, C_UDSI_G
Storage Location Memory and data file Memory and data file
Visualization Can be plotted in contours Can be plotted in contours
Computational Cost Low (storage only) Higher (equation solved each iteration)
Typical Use Cases Intermediate calculations, custom field data, post-processing Chemical species, turbulence parameters, passive tracers
Customization Options Values set by UDFs only Transport equation parts customizable through UDFs

Conclusion

User-Defined Memory (UDM) and User-Defined Scalars (UDS) are powerful extensions to ANSYS Fluent’s already strong simulation capabilities. UDMs provide flexible data storage that improves post-processing and enables complex algorithms, while UDSs allow for the solution of custom transport equations that can model specialized physical phenomena.

By mastering these features, engineers and researchers can go beyond the standard capabilities of ANSYS Fluent to address unique simulation challenges. Whether you’re modeling custom chemical reactions, tracking specialized performance metrics, or implementing novel physical models, UDMs and UDSs offer the flexibility and power needed for advanced CFD simulations.

FAQs

  • What is the main difference between UDMs and UDSs in ANSYS Fluent?

User-Defined Memory (UDM) provides simple storage locations for custom data that don’t have their own transport equations, while User-Defined Scalars (UDS) are full variables with their own conservation equations that Fluent solves during each iteration.

  • How many UDMs and UDSs can I define in ANSYS Fluent?

You can define up to 500 UDMs in ANSYS Fluent. The number of UDSs isn’t strictly limited but depends on your computer’s resources and memory.

  • Are UDM values saved with the case file?

Yes, UDM values are saved when you save your case and data files, allowing you to restart simulations with your custom values intact. This makes them ideal for tracking simulation history across multiple sessions.

  • Can UDMs and UDSs be used together in the same simulation?

Yes, UDMs and UDSs are often used together in complex simulations. For example, UDMs can store calculations related to UDSs or track historical values of UDSs for post-processing and analysis.

  • Do UDMs increase computational cost significantly?

UDMs themselves add very little computational cost since they’re just storage. However, any calculations performed to fill UDMs will add some computational cost. The impact is generally much less than solving additional UDS transport equations.

  • How do I visualize UDM and UDS values?

Both UDMs and UDSs can be visualized using ANSYS Fluent’s standard post-processing tools, including contour plots, vector plots, and isosurfaces. This makes them valuable for analyzing simulation results in ways that aren’t possible with standard Fluent variables.

  • Can I use UDS in both steady and transient simulations?

Yes, User-Defined Scalars work in both steady-state and transient simulations, though the equations solved will be a bit different. In transient simulations, the time-dependent term in the transport equation is active, while in steady-state simulations, only the spatial terms are considered.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Scroll to Top