Functions

TTiP allows the creation of functions in the config file using either one of the built in function builders, or by writing expressions.

The simplest functions can be defined as:

<name>: <expression>

e.g.:

radial: 1/sqrt(x^2 + y^2)

Functions can also be interim functions. An interim function is one that is used as a component in other functions but is not used directly by the section. To define an interim function, start the function name with an ‘_’:

_<name>: <expression>

Interim functions can then be used by name:

_foo: 10 + x*y
bar: foo^2

TTiP also offers predefined function builders which offer some useful functionality. Function builders are used to create specific functions in the TTiP configuration file and are defined by setting the various properties with respect to a name, using the form:

<name>.<property>: <value>

Each function builder must define the type property, along with the relevent properties for the selected type. e.g.:

foo.type: gaussian
foo.mean: 0.5
foo.sd: 0.1
foo.scale: 10

Available function builders are:

Condition

The condition function allows the user to create a stepped function using an operator alongside a left and right hand side (lhs and rhs respectively).

Args:
  • operator (str): The operator to use.
  • lhs (str): An expression for the left hand side.
  • rhs (str): An expression for the right hand side.

The exact formula is:

\text{Condition}(x, \text{operator}, \text{lhs}, \text{rhs}) =
\begin{cases}
1, &\text{lhs} \text{ operator } \text{rhs}\\
0, &\text{otherwise}
\end{cases}

Where:

  • operator is an operator (‘<’, ‘>’, ‘<=’, ‘==’, …)
  • lhs is an expression for the left hand side
  • rhs is an expression for the right hand side

e.g.

\text{Condition}(\vec{x}, <, x^2 + y^2, 10) =
\begin{cases}
1, & x_1^2 + x_2^2 < 10\\
0, &\text{otherwise}
\end{cases}

Constant

The Constant function creates a uniform function of value across the whole domain.

Args:
  • value (numerical): The constant value.

The exact formula is:

\text{constant}(x, \text{value}) = \text{value}

Where:

  • value is a scalar

File

The File function creates an function interpolated from data in a file.

Args:
  • path (str): The path to the file to interpolate.

The file must be a csv (optionally with a commented header row), where the first n columns represent the coords and the final column is the value at the coordinate.

e.g. For a 2D problem:

# x, y, val
0.0, 0.0, 10.0
0.1, 0.0, 9.0
0.2, 0.0, 8.0
0.3, 0.0, 7.0
...

Cubic interpolation is used for 1-D or 2-D problems, while linear interpolation is used for higher dimensional problems.

Gaussian

The Gaussian function creates a symmetric function with a peak equal to the scale at the location defined by mean. As the distance from this peak increases, the function decays exponentially. This decay is controlled by sd.

Args:
  • mean (numerical): The mean for the function.
  • sd (numerical): The standard deviation of the function.
  • scale (numerical): The amount to scale the function by.

The exact formula is:

\text{gaussian}(x, \text{mean}, \text{sd}, \text{scale}) =
    \text{scale}\times
    e^{-\frac{1}{2}\left(\frac{x-\text{mean}}{\text{sd}}\right)
    \cdot\left(\frac{x-\text{mean}}{\text{sd}}\right)}

Where:

  • mean is a vector (comma seperated list) of length dim(x), or a scalar value that will be broadcast to a vector.
  • sd is a vector (comma seperated list) of length dim(x), or a scalar value that will be broadcast to a vector.
  • scale is a scalar value