26  Expressions

Named constants and reusable physical-quantity expressions

26.1 What this setting is

expressions is an optional case-wide dictionary of named constants and reusable expressions. Use it for repeated physical values and coordinate-based profiles. It does not apply to numerical controls such as CFL or tolerances.

26.2 Parameter table

Key or form Type Meaning Valid use
expressions.<name>: <number> number Named constant. Physical-quantity expression.
expressions.<name>: <string> string Reusable expression, expanded before evaluation. Physical-quantity expression.
"$name" string Complete-field reference shorthand. Physical-quantity field only.
"name + 1" string Inline expression; bare names are expanded in larger expressions. Physical-quantity field only.
{ "type": "expression", "expr": "…" } object Explicit expression form; equivalent to the bare string. Physical-quantity field only.
{ "type": "constant", "value": … } object Explicit constant form; a bare number is auto-converted to it. Physical-quantity field only.

26.3 Constants and reusable expressions

{
  "expressions": {
    "V0": 10.0,
    "H": 0.02,
    "inlet_profile": "V0*(1-(y/H)^2)"
  },
  "domains": [{
    "boundaries": [{
      "name": "INLET",
      "type": "velocity_inlet",
      "mesh_markers": ["INLET"],
      "velocity": { "type": "expression", "expr": "$inlet_profile" },
      "flow_direction": [1.0, 0.0, 0.0]
    }]
  }]
}

A number defines a constant. A string defines a reusable expression. Inside a field, write the expression text either as a bare string or in the expr key of an explicit expression object; the two are equivalent. Use the $ prefix only when the whole text is one reference, such as { "type": "expression", "expr": "$p_inlet" }; inside a larger expression, use the bare name, as in { "type": "expression", "expr": "p_inlet + dp" }.

26.4 Reserved names and validation

x, y, z, and t are reserved in boundary, initialization, and source expressions. T, P, and rho are additionally reserved in material and source expressions; pi is always reserved. Do not redefine them.

Situation Wake CFD behavior Action
Expression refers to another named expression Dependencies resolve before evaluation. Keep definitions small and readable.
A reference cycle exists Input validation fails. Break the cycle.
A name is unknown Input validation fails. Correct it or define it.
Expression used for CFL, tolerance, or relaxation Not supported. Use a numeric value.

Start with a constant baseline, then introduce one expression at a time.