Custom Fields

NOTE: Custom fields in the SDK are experimental. They may change or be removed in the future.

A custom field is a scalar field computed from an expression over the solution’s fields, such as "Pressure" * 2. These are the same custom fields you define in the UI.

Custom field expressions use a subset of the vis expression language that vis queries use: the subset the solver supports. This page lists that subset. See What’s changing, below.

Using a custom field

Create one with vis.CustomField, register it where it is used, and read it with to_field():

import luminarycloud.vis as vis

p2 = vis.CustomField("p2", '"Pressure" * 2')
scene.add_custom_field(p2)
display = vis.DisplayAttributes()
display.field = p2.to_field()

A custom field can be registered with:

  • Scene.add_custom_field, for images.

  • DataExtractor.add_custom_field, for data extracts.

  • the custom_fields argument of vis.range_query and vis.extrema_query.

vis.validate_custom_fields checks expressions against a solution without rendering anything.

Expressions

Part

Example

Notes

A field name, in double quotes

"Pressure", "Density"

A field of the solution.

A component of a vector field

"Velocity-X", "Velocity-MAGNITUDE"

A -X, -Y, -Z or -MAGNITUDE suffix.

Numbers

2, 0.5

Constants

pi, PI

π

Operators

+, -, *, /

* and / before + and -; parentheses group. A leading - negates.

Functions

sqrt(x), pow(x, 2)

See the table below.

Function

Arguments

sqrt, cbrt, log, exp, abs

one; log is the natural log

sin, cos, tan, asin, acos, atan

one, in radians

pow, hypot, atan2, max, min

two

For example, the dynamic pressure and the speed in the x-y plane:

0.5 * "Density" * pow("Velocity-MAGNITUDE", 2)
hypot("Velocity-X", "Velocity-Y")

Limits

  • The result is one scalar at each point or cell. There are no vectors.

  • There are no comparisons or conditionals, and no ^; use pow.

  • There is no mesh geometry, such as cell volume or normals.

  • An expression can’t use another custom field.

  • A vis query can’t read a custom field by name. Write the expression in the query’s program instead (see Vis Expression Language).

What’s changing

Custom fields will soon support the full vis expression language. They will gain what it adds, such as vectors, if, mesh geometry like normal, and named variables. This page will be updated when that happens.