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.
Syntax Conventions
Block keywords are prefixed with & (e.g., & tf1p)
State names (inputs/outputs) are plain identifiers: do not enclose them in brackets
Parameters (data values) are enclosed in braces: {T}, {Kp}, {1/{omegac}}
Square brackets [v], [p], [q], [if], [vf] denote system variables provided by the simulator (bus voltage, active power, reactive power, field current, field voltage)
For example, a time constant can be specified as: 2. (a literal value), {'{'}T{'}'} (a data name), or 1/{'{'}omegac{'}'} (a mathematical expression involving data).
Output computed directly from the inputs, with no internal dynamics.
Block Description 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.
Block Description tf1pFirst-order: G / ( 1 + s T ) G/(1 + sT) G / ( 1 + s T ) 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 + s T z ) / ( 1 + s T p ) G(1 + sT_z)/(1 + sT_p) G ( 1 + s T z ) / ( 1 + s T p ) tf2p2zTwo zeros, two poles tfder1pDerivative (washout): s T / ( 1 + s T ) sT/(1 + sT) s T / ( 1 + s T )
Block Description intIntegrator with time constant inlimIntegrator with non-windup limits invlimIntegrator with variable non-windup limits
Block Description 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.
Block Description limLimiter with constant bounds limvbLimiter with variable bounds dbDeadband hystHysteresis switchSelect one of n n n inputs swsignSwitch based on sign of input
Block Description f_injFrequency at bus of injector f_twop_bus1Frequency at first bus of two-port f_twop_bus2Frequency at second bus of two-port
Block Description fsaFinite State Automaton tsaTwo-state automaton timerTimer with piecewise-linear delay timerscTimer with staircase delay
Helper functions available inside any model, without declaration.
Function Model types Description equalall 1.0 if two reals differ by less than 10 − 6 10^{-6} 1 0 − 6 equalstrall 1.0 if two strings matchppowerinjActive power injected into the network qpowerinjReactive power injected into the network vrectifexcRectifier voltage drop vinrectifexcInverse of vrectif vcompexcLoad-compensated voltage magnitude saturexcExciter saturation characteristic