Skip to content

CODEGEN Blocks

CODEGEN provides a library of reusable modeling blocks for constructing user-defined dynamic models. Each block is specified by a keyword (prefixed with &), followed by input/output state names and parameters. Parameters can be literal values, named data enclosed in braces {T}, or arithmetic expressions.


Output computed directly from the inputs, with no internal dynamics.

BlockDescription
absAbsolute value of input
algeqAlgebraic equation
max1v1cMaximum of a state and a constant
max2vMaximum of two states
min1v1cMinimum of a state and a constant
min2vMinimum of two states
nintNearest integer
pwlinPiecewise linear function

Linear transfer functions, several with non-windup output or rate limits.

BlockDescription
tf1pFirst-order: G/(1+sT)G/(1 + sT)
tf1plimFirst-order with non-windup output limits
tf1pvlimFirst-order with variable non-windup limits
tf1p2limFirst-order with rate limits and output limits
tf1p2limrAs tf1p2lim, with integrator reset driven by CHGPRM
tf1p1zOne zero, one pole: G(1+sTz)/(1+sTp)G(1 + sT_z)/(1 + sT_p)
tf2p2zTwo zeros, two poles
tfder1pDerivative (washout): sT/(1+sT)sT/(1 + sT)
BlockDescription
intIntegrator with time constant
inlimIntegrator with non-windup limits
invlimIntegrator with variable non-windup limits
BlockDescription
pictlProportional-Integral controller
pictllimPI with non-windup limit on integral
pictl2limPI with limits on integral and total output
pictlieeePI with non-windup limit (IEEE formulation)

Blocks that bound a signal or select between signals. Several carry discrete state.

BlockDescription
limLimiter with constant bounds
limvbLimiter with variable bounds
dbDeadband
hystHysteresis
switchSelect one of nn inputs
swsignSwitch based on sign of input
BlockDescription
f_injFrequency at bus of injector
f_twop_bus1Frequency at first bus of two-port
f_twop_bus2Frequency at second bus of two-port
BlockDescription
fsaFinite State Automaton
tsaTwo-state automaton
timerTimer with piecewise-linear delay
timerscTimer with staircase delay

Helper functions available inside any model, without declaration.

FunctionModel typesDescription
equalall1.0 if two reals differ by less than 10610^{-6}
equalstrall1.0 if two strings match
ppowerinjActive power injected into the network
qpowerinjReactive power injected into the network
vrectifexcRectifier voltage drop
vinrectifexcInverse of vrectif
vcompexcLoad-compensated voltage magnitude
saturexcExciter saturation characteristic