ANSYS BLOG

July 9, 2019

# Ansys Tips and Tricks: Enter Expressions Directly into the Fluent UI

Wouldn’t it be great if every simulation had a static boundary and cell zone settings? Unfortunately, the world isn’t static, so many engineers are faced with the challenge of inputting variable settings into some aspect of a simulation.

This is why I want to tell you about the ability to input expressions directly into the Ansys Fluent user interface (UI).

Until now, Fluent users who needed to specify various boundary and cell zone conditions had to write a Fluent user defined function (UDF).

UDFs can get complicated quick. For instance, Figure 1 shows you the Fluent UDF code required to set up a sinusoidally fluctuating heat source based on the function Energy(t) = 90000*sin(t) [W/m^3].

Figure 1. Fluent UDF code required to set up a sinusoidally fluctuating heat source based on the function
Energy(t) = 90000*sin(t) [W/m3]

Even a small UDF, like the one in Figure 1, requires a considerable amount of thought to create.For example, to create this UDF, engineers converted units, programmed in C and learned Fluent-specific programming concepts.

These concepts include, but are not limited to:

• Threads (Fluent UDF’s data structure)
• Macros (like DEFINE_SOURCE)
• Utilities (like CURRENT_TIME)

Even for experienced users, this could take a while. That’s why Fluent UI expressions are so useful. They are based on an expression involving, declarative and interpreted language that enables Fluent users to enhance simulations without the need to write, compile and load UDFs.

With expressions, engineers can make use of a combination of mathematical functions, logical operators, Fluent field variables and other common concepts to simplify the specification of complex boundary and cell zone conditions.

## How to Enter Expressions into the Fluent UI Without UDF

UDFs, while powerful, require users to have knowledge of programming. Expressions, however, expand the rich customization capabilities of Fluent to more users.

Returning to the fluctuating heat source in Figure 1, now we can easily enter it as an expression using standard mathematical notation (and some unit cleanup). As seen in Figure 2, the expression (sin(Time/1[s]))*90000[Wm^-3] can now be input directly into the Fluent UI.

Figure 2. Now expressions can be easily added through the user interface in standard mathematical notation.

The editor allows the engineer to name, define and describe an expression in a single interface. One can then use this named expression in multiple boundary and cell zone conditions to create any desired combination of expressions.

Figure 3. A graph of an expression that represents a sinusoidally
fluctuating heat source

Specifying this expression in previous versions of Fluent involved writing/interpreting/compiling the C file, building the UDF and hooking it up to the boundary condition. These additional steps are eliminated by the use of a named expression.

Additionally, these expressions can be used to define conditional cell zone source terms, models and solver settings (like acceleration due to gravity). Users can also enter the expression directly in the boundary condition panel.

A rich set of mathematical, trigonometric and other functions can be used to define these expressions, including:

• Positional variables (like time)
• Field variables (like total temperature and helicity)
• Solution variables (like time-step and iteration)
• Reduction operations (like minimum, maximum, average and sum)

Boolean expressions can also be used in specification, refinement and size criteria for mesh adaption.

To learn more about expressions, watch the recorded webinar: Directly Enter Expressions to speed, simplify simulations in Ansys Fluent.