Algebraic & Mathematical Blocks
Blocks that compute an output directly from their inputs, with no internal dynamics.
Absolute value of input.
Syntax
& absx_ix_jx_i is the input state; x_j is the output state (the absolute value of x_i).
Internal states: none
Discrete variable:
Equations
Discrete transitions
if z = 1: if x_i < 0: z ← -1else: # z = -1 if x_i > 0: z ← 1Initialization
if x_i > 0: z ← 1else: z ← 0Notes
The model has a discontinuous derivative at . It is implemented internally with a small hysteresis; see the hyst block with , , , , , , where is the absolute accuracy used to solve the algebraic equations in RAMSES.
Algebraic equation.
Syntax
& algeqmath expressionInternal states: none
Discrete variables: none
Description
This block forces an algebraic constraint (or equation) involving one or several states:
where is the number of states ().
Notes
This block does not have distinct “inputs” and “outputs”. Those roles emerge from the rest of the model that incorporates the algebraic constraint.
max1v1c
Section titled “max1v1c”Maximum between a state and a constant.
Syntax
& max1v1cx_ix_j{C}x_i is the input state, x_j is the output (), and C is a constant (data name, parameter name, or math expression).
Internal states: none
Discrete variable:
Equations
When the output is clamped to ; when the output tracks .
Discrete transitions
if z = 1: if x_i > C: z ← 2else: # z = 2 if x_i <= C: z ← 1Initialization
if x_i < C: z ← 1else: z ← 2Maximum between two states.
Syntax
& max2vx_ix_jx_kx_i and x_j are the two input states; x_k is the output ().
Internal states: none
Discrete variable:
Equations
When the output follows ; when the output follows .
Discrete transitions
if z = 1: if x_i < x_j: z ← 2else: # z = 2 if x_j <= x_i: z ← 1Initialization
if x_i > x_j: z ← 1else: z ← 2min1v1c
Section titled “min1v1c”Minimum between a state and a constant.
Syntax
& min1v1cx_ix_j{C}x_i is the input state, x_j is the output (), and C is a constant (data name, parameter name, or math expression).
Internal states: none
Discrete variable:
Equations
When the output tracks ; when the output is clamped to .
Discrete transitions
if z = 1: if x_i > C: z ← 2else: # z = 2 if x_i <= C: z ← 1Initialization
if x_i < C: z ← 1else: z ← 2Minimum between two states.
Syntax
& min2vx_ix_jx_kx_i and x_j are the two input states; x_k is the output ().
Internal states: none
Discrete variable:
Equations
When the output follows ; when the output follows .
Discrete transitions
if z = 1: if x_i > x_j: z ← 2else: # z = 2 if x_j >= x_i: z ← 1Initialization
if x_i < x_j: z ← 1else: z ← 2Integer nearest to the input shifted by a constant .
Syntax
& nintx_ix_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: (the integers)
Equations
Discrete transitions
if nint(x_i + c) ≠ z: z ← nint(x_i + c)where returns the nearest integer.
Initialization
Notes, particular cases
- With : the output is the integer nearest to .
- With : the output is the floor of (largest integer ).
- With : the output is the ceiling of (smallest integer ).
Piece-wise linear function of input, defined by points. Separate blocks exist for and .
Syntax
& pwlin3name of variable x_iname of variable x_jdata/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 pairs up to , , or respectively.
Internal States
None.
Discrete Variables
Equations
Discrete Transitions
if x_i < v_x(1): z ← 1else if x_i >= v_x(n): z ← n-1else: for k = 1 to n-1: if v_x(k) <= x_i < v_x(k+1): z ← kInitialization
Same logic as discrete transitions.
Notes
- The values must be strictly increasing at the endpoints: and ; intermediate values may be equal: .
- For or , is obtained by linear extrapolation from the first or last two points respectively.
See Also
Section titled “See Also”- Block Index, all CODEGEN blocks by category
- CODEGEN Model Examples, complete models built from these blocks
- User-Defined Models, the DSL file format