Skip to content

Algebraic & Mathematical Blocks

Blocks that compute an output directly from their inputs, with no internal dynamics.


Absolute value of input.

abs block diagram

Syntax

& abs
x_i
x_j

x_i is the input state; x_j is the output state (the absolute value of x_i).

Internal states: none

Discrete variable: z∈{−1,1}z \in \{-1, 1\}

Equations

0={xj−xiif z=1xj+xiif z=−10 = \begin{cases} x_j - x_i & \text{if } z = 1 \\ x_j + x_i & \text{if } z = -1 \end{cases}

Discrete transitions

if z = 1:
if x_i < 0:
z ← -1
else: # z = -1
if x_i > 0:
z ← 1

Initialization

if x_i > 0:
z ← 1
else:
z ← 0

Notes

The model has a discontinuous derivative at xi=0x_i = 0. It is implemented internally with a small hysteresis; see the hyst block with xI=ϵx_I = \epsilon, yIB=−ϵy_{IB} = -\epsilon, yIA=ϵy_{IA} = \epsilon, xD=−ϵx_D = -\epsilon, yDB=−ϵy_{DB} = -\epsilon, yDA=ϵy_{DA} = \epsilon, where ϵ\epsilon is the absolute accuracy used to solve the algebraic equations in RAMSES.


Algebraic equation.

Syntax

& algeq
math expression

Internal states: none

Discrete variables: none

Description

This block forces an algebraic constraint (or equation) involving one or several states:

f(x1,x2,…,xn)=0f(x_1, x_2, \ldots, x_n) = 0

where nn is the number of states (n≥1n \ge 1).

Notes

This block does not have distinct “inputs” and “outputs”. Those roles emerge from the rest of the model that incorporates the algebraic constraint.


Maximum between a state and a constant.

max1v1c block diagram

Syntax

& max1v1c
x_i
x_j
{C}

x_i is the input state, x_j is the output (max⁡(xi,C)\max(x_i, C)), and C is a constant (data name, parameter name, or math expression).

Internal states: none

Discrete variable: z∈{1,2}z \in \{1, 2\}

Equations

0={xj−Cif z=1xj−xiif z=20 = \begin{cases} x_j - C & \text{if } z = 1 \\ x_j - x_i & \text{if } z = 2 \end{cases}

When z=1z = 1 the output is clamped to CC; when z=2z = 2 the output tracks xix_i.

Discrete transitions

if z = 1:
if x_i > C:
z ← 2
else: # z = 2
if x_i <= C:
z ← 1

Initialization

if x_i < C:
z ← 1
else:
z ← 2

Maximum between two states.

max2v block diagram

Syntax

& max2v
x_i
x_j
x_k

x_i and x_j are the two input states; x_k is the output (max⁡(xi,xj)\max(x_i, x_j)).

Internal states: none

Discrete variable: z∈{1,2}z \in \{1, 2\}

Equations

0={xi−xkif z=1xj−xkif z=20 = \begin{cases} x_i - x_k & \text{if } z = 1 \\ x_j - x_k & \text{if } z = 2 \end{cases}

When z=1z = 1 the output follows xix_i; when z=2z = 2 the output follows xjx_j.

Discrete transitions

if z = 1:
if x_i < x_j:
z ← 2
else: # z = 2
if x_j <= x_i:
z ← 1

Initialization

if x_i > x_j:
z ← 1
else:
z ← 2

Minimum between a state and a constant.

min1v1c block diagram

Syntax

& min1v1c
x_i
x_j
{C}

x_i is the input state, x_j is the output (min⁡(xi,C)\min(x_i, C)), and C is a constant (data name, parameter name, or math expression).

Internal states: none

Discrete variable: z∈{1,2}z \in \{1, 2\}

Equations

0={xj−xiif z=1xj−Cif z=20 = \begin{cases} x_j - x_i & \text{if } z = 1 \\ x_j - C & \text{if } z = 2 \end{cases}

When z=1z = 1 the output tracks xix_i; when z=2z = 2 the output is clamped to CC.

Discrete transitions

if z = 1:
if x_i > C:
z ← 2
else: # z = 2
if x_i <= C:
z ← 1

Initialization

if x_i < C:
z ← 1
else:
z ← 2

Minimum between two states.

min2v block diagram

Syntax

& min2v
x_i
x_j
x_k

x_i and x_j are the two input states; x_k is the output (min⁡(xi,xj)\min(x_i, x_j)).

Internal states: none

Discrete variable: z∈{1,2}z \in \{1, 2\}

Equations

0={xi−xkif z=1xj−xkif z=20 = \begin{cases} x_i - x_k & \text{if } z = 1 \\ x_j - x_k & \text{if } z = 2 \end{cases}

When z=1z = 1 the output follows xix_i; when z=2z = 2 the output follows xjx_j.

Discrete transitions

if z = 1:
if x_i > x_j:
z ← 2
else: # z = 2
if x_j >= x_i:
z ← 1

Initialization

if x_i < x_j:
z ← 1
else:
z ← 2

Integer nearest to the input shifted by a constant cc.

nint block diagram

Syntax

& nint
x_i
x_j
{c}

x_i is the input state, x_j is the output (nearest integer), and c is a shift constant (data name, parameter name, or math expression).

Internal states: none

Discrete variable: z∈Iz \in \mathcal{I} (the integers)

Equations

0=xj−z0 = x_j - z

Discrete transitions

if nint(x_i + c) ≠ z:
z ← nint(x_i + c)

where nint(⋅)\text{nint}(\cdot) returns the nearest integer.

Initialization

z←nint(xi+c)z \leftarrow \text{nint}(x_i + c)

Notes, particular cases

  • With c=0c = 0: the output is the integer nearest to xix_i.
  • With c=−0.5c = -0.5: the output is the floor of xix_i (largest integer ≤xi\le x_i).
  • With c=0.5c = 0.5: the output is the ceiling of xix_i (smallest integer ≥xi\ge x_i).

Piece-wise linear function of input, defined by nn points. Separate blocks exist for n=3,4,5n = 3, 4, 5 and 66.

pwlin block diagram

Syntax

& pwlin3
name of variable x_i
name of variable x_j
data/parameter/expression for v_x(1)
data/parameter/expression for v_y(1)
data/parameter/expression for v_x(2)
data/parameter/expression for v_y(2)
data/parameter/expression for v_x(3)
data/parameter/expression for v_y(3)

For pwlin4, pwlin5, and pwlin6, append additional (vx(k),vy(k))(v_x(k), v_y(k)) pairs up to k=4k = 4, 55, or 66 respectively.

Internal States

None.

Discrete Variables

z∈{1,…,n−1}z \in \{1, \ldots, n-1\}

Equations

0=vy(z)+vy(z+1)−vy(z)vx(z+1)−vx(z)(xi−vx(z))−xj0 = v_y(z) + \frac{v_y(z+1) - v_y(z)}{v_x(z+1) - v_x(z)} \left( x_i - v_x(z) \right) - x_j

Discrete Transitions

if x_i < v_x(1):
z ← 1
else if x_i >= v_x(n):
z ← n-1
else:
for k = 1 to n-1:
if v_x(k) <= x_i < v_x(k+1):
z ← k

Initialization

Same logic as discrete transitions.

Notes

  • The vxv_x values must be strictly increasing at the endpoints: vx(1)<vx(2)v_x(1) < v_x(2) and vx(n−1)<vx(n)v_x(n-1) < v_x(n); intermediate values may be equal: vx(1)<vx(2)≤⋯≤vx(n−1)<vx(n)v_x(1) < v_x(2) \le \cdots \le v_x(n-1) < v_x(n).
  • For xi<vx(1)x_i < v_x(1) or xi>vx(n)x_i > v_x(n), xjx_j is obtained by linear extrapolation from the first or last two points respectively.