User-Defined Scalar in ANSYS Fluent - Beginner to Advanced (Guide)
User-Defined Scalar (UDS) in ANSYS Fluent
What a UDS is, why it's so powerful, and how to use it — explained simply for beginners, then taken deeper for advanced users who want to customise every term with UDFs.
Sooner or later, every CFD engineer hits a wall: "I need Fluent to track something it doesn't solve by default." Maybe it's the age of air in a room, a contaminant concentration, a custom radiation field, or your own physics. The answer is the User-Defined Scalar (UDS) — a spare transport equation Fluent will solve for any quantity you define. This guide explains it in plain language for Beginner readers first, then goes under the hood for Advanced users who want full control with UDFs.
What This Guide Covers
Beginner What Is a User-Defined Scalar?
Think of Fluent as already solving a few "built-in" quantities: velocity, pressure, temperature. A User-Defined Scalar (UDS) is like handing Fluent a blank extra equation and saying: "Also solve for this thing I care about, and let it be carried by the flow and spread out just like heat does."
Why & When to Use a UDS
A UDS is the right tool whenever you need to track a quantity that moves with the flow, spreads by diffusion, and can be created or consumed — but that Fluent doesn't solve by default. Common uses:
Age of Air
Mean time air has spent in a room — a key ventilation metric.
Contaminant / Dye
Track a passive pollutant or tracer concentration through the domain.
Custom Radiation / Potential
Solve a bespoke field like incident radiation G or an electric potential.
Custom Physics
Implement a simplified reaction, marker, or your own transported quantity.
Beginner The Scalar Transport Equation
Fluent solves every UDS using one general "transport equation." Don't be scared of it — it's just a bookkeeping statement that says change = what flows in/out + what spreads + what's created:
where φ (phi) is your scalar, ρ density, u the flow velocity, Γ (gamma) the diffusion coefficient, and S the source. Each piece is one of the four terms you control.
The Four Terms You Control
1. Transient
How the scalar changes with time. Turn off for steady state, on for transient.
2. Convection (Flux)
How the flow carries the scalar. Options: none, mass flow rate, or a UDF.
3. Diffusion
How the scalar spreads out, set by the diffusivity Γ (constant or UDF).
4. Source
Where the scalar is created or destroyed inside the domain.
| Term | Fluent option | Set where |
|---|---|---|
| Transient (Unsteady Function) | none / default / UDF | User-Defined Scalars dialog |
| Convection (Flux Function) | none / mass flow rate / UDF | User-Defined Scalars dialog |
| Diffusion (Diffusivity) | constant / UDF | Materials dialog |
| Source | constant / UDF | Cell Zone Conditions |
Setting Up a UDS in Fluent (Step by Step)
- Open the dialog:
Parameters & Customization → User-Defined Scalars → Edit. - Set the number of scalars (e.g. 1). Each gets an index starting at 0.
- Choose Solution Zones (e.g. all fluid zones).
- Flux Function: none (pure diffusion), mass flow rate (standard convection), or a UDF.
- Unsteady Function: none (steady), default (standard transient), or a UDF.
- Diffusivity: set in the Materials dialog (constant or UDF).
- Source term: add in Cell Zone Conditions if needed.
- Boundary conditions: specify the scalar value or flux at each boundary, initialise, and solve.
Advanced Customising Each Term with UDFs
For custom physics, each term maps to a DEFINE macro in a User-Defined Function. You write C code, then interpret or compile it and hook it in the dialog:
| Term | DEFINE macro | Returns |
|---|---|---|
| Diffusion coefficient | DEFINE_DIFFUSIVITY | Γ for the scalar (e.g. varies with T) |
| Convective flux | DEFINE_UDS_FLUX | Mass flow rate through a face |
| Transient term | DEFINE_UDS_UNSTEADY | Custom su and apu (unsteady) terms |
| Source term | DEFINE_SOURCE | Source (and its derivative) |
| Anisotropic diffusion | DEFINE_ANISOTROPIC_DIFFUSIVITY | Diffusivity tensor |
su and a central-coefficient term apu. If you solve several scalars, use an if on the scalar index i inside one UDF to give each its own behaviour. Note: DEFINE_UDS_FLUX works in fluid zones only.Advanced Example: A Simple Source-Term UDF
Here's a minimal UDF adding a constant source to scalar 0 (illustrative — adapt to your physics):
/* Add a source term to user-defined scalar 0 */ #include "udf.h" DEFINE_SOURCE(uds0_source, c, t, dS, eqn) { real source; source = 100.0; /* constant source, units per your scalar */ dS[eqn] = 0.0; /* derivative wrt the scalar (0 for constant) */ return source; } /* Example: temperature-dependent diffusivity for the scalar */ DEFINE_DIFFUSIVITY(uds0_diff, c, t, i) { return 1.0e-5 * pow(C_T(c,t)/300.0, 1.5); /* Gamma(T) */ }
Interpret it via Define → User-Defined → Functions → Interpreted (or compile for speed), then hook uds0_source in Cell Zone Conditions and uds0_diff in Materials. If you're new to UDFs, our learning-CFD guide and CFD tools overview help build the fundamentals.
UDS vs Species Transport — Which to Use?
| Feature | User-Defined Scalar | Species Transport |
|---|---|---|
| Purpose | Any custom transported quantity | Real chemical species / mixtures |
| Must sum to 1? | No | Yes (mass fractions) |
| Chemistry / reactions | Only if you code it | Built-in models |
| Control of terms | Full (via UDFs) | Limited to model options |
| Best for | Age of air, tracers, custom physics | Combustion, mixing of real gases |
Common Mistakes
- Forgetting to set the flux function. "none" solves pure diffusion — your scalar won't be carried by the flow. Use mass flow rate for normal convection.
- No diffusivity set. Assign Γ in Materials, or the scalar won't spread as expected.
- Wrong solution zones.
DEFINE_UDS_FLUXcan't compute convective flux in solid zones — select fluid zones. - Missing boundary conditions. Specify the scalar value or flux at inlets/outlets/walls.
- Not monitoring the UDS residual. Watch it converge like any other equation.
- Over-complicating with UDFs. Many UDS problems need no code — start with built-in options.
Frequently Asked Questions
What is a User-Defined Scalar in ANSYS Fluent?
An extra transport equation Fluent solves for a quantity you define (concentration, age of air, custom field), with transient, convection, diffusion and source terms you control.
What are the four terms of the UDS transport equation?
Transient (time change), convection/flux (carried by flow), diffusion (spreading via Γ), and source (creation/destruction). You choose how each is treated.
When should I use a User-Defined Scalar?
When you need to track a quantity that moves with the flow, diffuses, and can be created or consumed — e.g. age of air, tracers, custom radiation or physics.
Do I need a UDF to use a User-Defined Scalar?
No — many cases work with built-in options (mass-flow-rate flux, constant diffusivity, BCs). UDFs are only for custom terms via DEFINE_DIFFUSIVITY, DEFINE_UDS_FLUX, DEFINE_SOURCE, etc.
What is the difference between a UDS and a species transport equation?
Species transport is built-in for real chemical mixtures (mass fractions sum to 1, with chemistry). A UDS is a general, flexible equation for any custom quantity with full term control.
How many user-defined scalars can Fluent solve?
Multiple, each with its own index from 0, configured in the User-Defined Scalars dialog. In UDFs, an if on the index gives each scalar different behaviour.
Conclusion
The User-Defined Scalar is one of Fluent's most powerful extensibility tools — and it's approachable at every level. Beginners can solve a passive tracer or age-of-air with a few dialog clicks and no code. Advanced users can program every term — diffusivity, flux, unsteady, source — with DEFINE macros to implement custom physics. Understand the four terms of the transport equation, start simple, and reach for UDFs only when you need custom behaviour. That's the whole art of the UDS.
For more ANSYS Fluent, CFD and simulation tutorials plus free engineering calculators, explore Free CFD Tutorial. If this guide helped you, please share it with your fellow CFD engineers and students.

Comments
Post a Comment