Expressions

In Simcenter STAR-CCM+, you can define property values using expressions, which you write using a function language that is a subset of the C programming language. Expressions can define mathematical expressions or perform other operations, such as interpolating tabular data from XY tables in the simulation.

The expression syntax includes symbols and rules that:
  • identify operators and functions (for example, +, *, <, sin(), grad(), interpolateTable())
  • allow you to use existing simulation objects (for example, field functions and reports) as variables

For details, see Expression Syntax.

An expression is valid when:
  • its syntax is correct
  • it evaluates to the data type that is determined by the context in which the expression is used.

    For example, if you use an expression to define a scalar quantity that is not a function of space, the expression must evaluate to a single scalar value. If it evaluates to a vector or to a scalar field of values, it is not valid.

Simcenter STAR-CCM+ provides an expression editor that simplifies the process for writing valid expressions. For details and instructions, see Using the Expression Editor.

Checking the Value of Expressions Immediately in Properties

In the properties, if a value property is an expression, the editor provides an i button that you can click to see the evaluated value of this expression. When entering an expression for a value function (when editing this property), the i button is also available for you to do a dynamic evaluation of the input in the text field. The evaluating result shows up in a tooltip.

This feature works as follows:

  • If the value of current property is a constant and not being edited, the i button does not appear.
  • If an expression is invalid, an error message replaces the evaluated value in the tooltip.
  • You must manually click the i button to trigger the evaluation and show the result in a tooltip.

This feature only applies to value functions, such as scalar and vector physical quantities, and coordinates. It is not appropriate for spatially varying functions.

Context and Data Types

Depending on the object that the expression defines, the expression must evaluate to the appropriate data type. When using existing simulation objects as variables, consider what type of object the expression defines. As only field functions can be a function of space, use spatially varying field functions as variables only when the expression defines a user field function that depends on space. In all other cases, use spatially invariant quantities as variables.

The following table lists the objects that you can define using expressions and the appropriate data types for each object:
Context Data Type
Constant Inputs

When you define scalar and vector quantities (for example, boundary values, material properties, and motion settings) using the Constant method (see Scalar and Vector Profiles), you can use an expression that evaluates to a spatially invariant quantity. In this context, "constant" means constant at each time-step (or iteration), so the expression can be time-dependent.

Depending on the type of value, the expression must evaluate to either a single scalar or vector (not a scalar or vector field). Expressions that define constant profiles can use the following objects as variables:
  • reports (except for system reports)
  • parameters
  • spatially invariant field functions such as Time

For more information, see Constant Profiles.

User Field Functions
Depending on the type of field function, the expression must evaluate to either a scalar, vector, or tensor. Expressions that define field functions can either be a function of space or be spatially invariant. You can use the following objects as variables:
  • reports (except for system reports)
  • parameters
  • spatially invariant field functions such as Time
  • spatially varying field functions such as Pressure

For more information, see Creating User Defined Field Functions.

Expression Reports
At each time-step, the expression must evaluate to a single scalar value. Expressions that define reports can use the following variables:
  • reports (except for system reports)
  • scalar parameters
  • spatially invariant field functions such as Time

For more information, see Expression Reports .

Parameters

Depending on the type of parameter, the expression must evaluate to either a single scalar or vector value (not a scalar or vector field). Expressions that define parameters can only use other parameters as variables. Parameters cannot be time-dependent.

For more information, see Global Parameters and Design Parameters.

Coordinates

A coordinate is a complex data structure that is comprised of three scalar types (represented as a single vector value), each with its own units. Coordinate expressions must evaluate to a vector value, and can be defined with expressions made of Scalar or Vector Global Parameters.

The meaning of the coordinate values and their respective units is drastically different under different coordinate systems. Therefore when you change coordinate systems, the expression is evaluated under the old coordinate system, converted to the new coordinate system, and the coordinate's expression is replaced by the new evaluated value.

NoteIn the special case of local coordinate systems, Simcenter STAR-CCM+ treats the Origin position as a Coordinate, but treats the directions (such as X Direction) as vector data types (not to be confused with vector physical quantities).
Update Frequency Triggers

When inspecting and editing the three update frequency triggers, you can compose the Frequency, Start, and Stop values as expressions. These expressions can only use parameters, so that they remain constant throughout the run of a simulation. The dimensions of these properties must correspond with expected dimensions for the field.

For more information, see Global Parameters.

Examples

Expressions can evaluate to scalar, vector, or tensor quantities, which can depend on space and time. In the following table, you find examples for each data type, with the list of objects that you can define with each expression.

These examples do not explain the syntax of each expression. For details, see Expression Syntax.

Evaluates to: Examples: Can be used to define:
Spatially-invariant, Time-independent Scalar
3*sin(3.14/2)
  • constant scalar input
  • expression report
  • scalar parameter
  • scalar field function
sin(${angle})^2

where angle is either a spatially-invariant field function, a report, or a scalar parameter.

  • constant scalar input
  • expression report
  • scalar parameter (only when angle is a scalar parameter)
  • scalar field function
Spatially-invariant, Time-dependent Scalar
1/exp(${Time})

where Time is the Time field function.

  • constant scalar input
  • expression report
  • scalar field function
Spatially-varying Scalar Value (can be time-dependent)
grad(${Pressure})

where Pressure is a spatially-varying scalar field function.

scalar field function
div($${Velocity})

where Velocity is a spatially-varying vector field function.

scalar field function (the divergence of a vector evaluates to a scalar)
Spatially-invariant, Time-independent Vector
[0,-1,0]
(defined with respect to a coordinate system)
  • constant vector input
  • vector parameter
  • vector field function
$${angularVelocity}/2

where angularVelocity is either a spatially-invariant vector field function or a vector parameter.

  • constant vector input
  • vector parameter (only when angularVelocity is a vector parameter)
  • vector field function
Spatially-invariant, Time-dependent Vector

(spatially-invariant)

$${angularVelocity}/exp(${Time})

where Time is the Time field function.

  • constant vector input
  • vector field function
Spatially-varying Vector Value (can be time-dependent)
$${Velocity}/2

where Velocity is a spatially-varying vector field function.

vector field function
Tensor
$$${Stress}/exp(${Time})

where Stress is a tensor field function.

tensor field function