Skip to content

Expression Langauge

SeifIbrahim edited this page Aug 28, 2019 · 14 revisions

Types

Integral Types

  • integer
  • double
  • mesh variables: strings, e.g. "pressure" indicate a variable defined on the mesh.
  • bool: Note: only produced as the result of a comparison. Not sure we need keywords true and false since I don't see how we would use it in practice.

Objects

Functions can return objects that contain values and attributes. Objects with values can be treated as just another value in an expression. Objects with only attributes must be manipulated with function calls to extract values.

Idea: currently, vector math, e.g. v1+v2 is implemented in the binary op code. Perhaps there is a way that we can define objects in such a way that it contains the code that defines supported ops like an overloaded operator in c++. In the near term, it is simpler to just add a add(vector,vector) function. Additionally, its unclear how we will generate code for JIT derived expressions.

Simple Objects: values only

  • Vector: a 3D vector created with the vector function, e.g., vector(0,1,0).

Complex Objects: might not have a value.

  • Histogram: contains bin counts, min values, max values, bin deltas. Values are extracted via functions.

Other

  • anytype: An internal type used by the language to allow functions to take in arguments of any type and return values of any type. This is used by functions like history and position.

Operators

Binary Operators

  • Math: -, +, *, /, %
  • Comparison: ==, >=, <=, !=, >, <
  • Boolean: and, or , not. For JIT, we can just substitute whatever we need back in. Note: not is a unary operator.

Unary Operators

  • -

Functions

Arguments

Functions take a list of arguments, a subset of which are optional. Arguments are passed in the form of comma separated positional arguments followed by comma separated named arguments. The named arguments must come after all the positional arguments but the order in which the named arguments are specified has no effect.

Supported Functions

scalar avg(meshvar arg1)

Return the field average of a mesh variable.

scalar max(scalar arg1, scalar arg2)

Return the maximum of two scalars.

scalar max(meshvar arg1)

Return the maximum value from the meshvar. Its position is also stored and is accessible via the position function.

scalar min(scalar arg1, scalar arg2)

Return the minimum of two scalars.

scalar min(meshvar arg1)

Return the minimum value from the meshvar. Its position is also stored and is accessible via the position function.

vector position(anytype position)

Return the 3D position vector for the input value.

scalar cycle()

Return the current simulation cycle.

vector vector(scalar arg1, scalar arg2, scalar arg3)

Return a vector with the input values.

scalar magnitude(vector arg1)

Return the magnitude of the input vector.

histogram histogram(meshvar arg1, scalar num_bins[optional], scalar min_val[optional], scalar max_val[optional])

Return a histogram of the mesh variable.

  • num_bins defaults to 256
  • min_val defaults to min(arg1)
  • max_val defaults to max(arg1)
anytype history(anytype expr_name, scalar index)

Returns the value of an expression from index evaluations ago. expr_name should be the name of an expression that was evaluated in the past and index should be an integer less than the number of past evaluations.

Clone this wiki locally