User Field Function Examples

This section provides some examples of user field functions.

Scaling an Existing Field Function

Suppose that you wish to create a user field function that defines the distance in the x direction in inches, rather than in the SI units of the computation. You could create a field function that is called, say, “X inches” with the following definition:

$$Centroid[0]/0.0254

Setting a Transient Boundary Condition

Suppose that you want to set a transient boundary condition, such that temperature ramps up linearly from 300K to a value of 1000K at a time of 0.01 seconds. Your user field function definition (to be used in the definition of the boundary temperature) would be:

($Time >= 0.01)  ?  1000 : 300+70000*$Time

Specifying Components of a Vector Field Function

To define a vector, array or position field function in terms of its components, specify the three scalar components inside square brackets separated using commas. For example, to set up a field function to initialize the velocity in a reducing pipe, where the velocity is 2 m/s in the larger diameter and 10 m/s in the smaller diameter, and the diameter changed at x=4. The field function definition would be:

[($$Centroid[0] < 4) ? 2 : 10, 0, 0]

Calculating and Visualizing Face Normals

In Simcenter STAR-CCM+, the Area field function is a vector field function of the area components, that is the area magnitude multiplied by the unit normal. Therefore, to calculate the unit face normals, a field function can be created to normalize the Area field function by the area magnitude:

  • Create a field function that is called, for example, Face Normals.
  • Set its type to Vector and the definition to:
    $$Area / $$Area.mag()
This field function can be used to visualize the face normals by creating a vector scene, and setting the vector quantity to your Face Normals field function. You can also add a vector displayer to an existing scene. An example scene is shown below.

Creating a Velocity Field Function Based on Grid Flux

To create a field function that is based on Grid Flux that has the same units as velocity:
  1. Create a user-defined field function and rename it to Grid Flux Velocity.
  2. Set its dimensions to Length = 1 and Time = -1.
  3. Set its type to Vector.
  4. Set its definition to:
    $$GridFlux * $$Area / $$Area.mag2()

In this expression, $$GridFlux / $$Area.mag() is the magnitude of the velocity, and $$Area / $$Area.mag() is the direction of the flux, normal to the face area.

Calculating Derivatives with Vector Field Functions

Typical user field functions involving derivatives are:

  • Divergence of velocity ∇⋅v is specified as:
    div($$Velocity)
  • Divergence of density, velocity ∇⋅(ρv) is specified as:
    div($Density * $$Velocity)
  • Gradient of pressure p is specified as:
    grad($Pressure)
  • Curl of velocity ∇×v is specified as:
    curl($$Velocity)

A cell-based least squares gradient algorithm is used for the computation of the field gradients. At boundaries, zero-order extrapolation is used. This algorithm differs from the gradients that the various solvers compute. Therefore, the gradients computed for post-processing are likely to differ slightly from solver gradients that are viewed by using the Temporary Storage Retained option in specific solvers. However, they are sufficiently close for most practical purposes.

Calculating Surface Tractions

At a fixed surface constraint, you can calculate surface tractions from the dot product of the stress tensor with the face normals. The user field function definition would be:

dotVector($$$StressTensor,$$Area/$$Area.mag())

As $$Area provides a constant value for each face, the calculated tractions are average values per face.