LinearAnalysis package
Requirements.LinearAnalysis
ยท source
Eigenvalue predicates over the state matrix of a linearization, or over a mode table, read from a file
Extends Modelica.Icons.Package
Requirements on the eigenvalues of a linearized plant: stability margins, damping, natural frequencies, time constants, pole regions. A linearization is a tool operation, not a simulation, so no check model can compute a plant's eigenvalues inside the run that produces them. The workflow therefore has two steps:
- Linearize the plant at its operating point in your Modelica tool (or on its FMU) and write the state
matrix
Ato a MATLAB v4 file. - Check it in a small Modelica model:
readStateMatrix reads the matrix,
modes takes its eigenvalues (LAPACK's
dgeev, asModelica.Math.Matrices.eigenValuesdoes) and folds them into modes, and the blocks evaluate the predicates as constants over a short nominal run: EigenvalueCheck (a real-part, damping, frequency or time-constant bound over every mode, optionally in a frequency band) and EigenvaluesWithinRegion (a polygon of the (Re, Im) plane), each withPropertyandmarginoutputs. Connect them to Verify.Requirement blocks and a PrintViolations as in any other check model.
Step 1: linearizing in different tools
Linearization is available in every Modelica tool, but it is not standardized: the command, the operating
point it linearizes at, the state selection and the output format all differ. This library does not depend on any of
them; it only needs a MATLAB v4 file with the state matrix as a matrix named A (or another name passed
as matrixName). Some common routes (consult your tool's manual for the exact syntax of your version):
- Any tool that runs Modelica functions in its scripting: once you have
Aas a Real matrix,Modelica.Utilities.Streams.writeRealMatrix("lin.mat", "A", A, format="4")writes it in the required format. - Dymola: the
linearizeModelcommand writes the linearization todslin.mat, where the state matrix is the upper-leftnx×nxblock of the matrixABCD; extract that block and write it asA. The Modelica_LinearSystems2 library returnsAdirectly. - OpenModelica: the
linearizescripting command (orModelicaSystem.linearize()in OMPython) givesA,B,C,D. - Tools with a linearization feature in their GUI or API (e.g. a linearize custom function in Modelon
Impact, SimulationX, MapleSim, Wolfram System Modeler): export
Aand convert it as below. - An FMU, from any exporting tool: FMI 2.0 and 3.0 provide the directional derivatives from which
Afollows (for instance PyFMI'sget_state_space_representation()), or difference the state derivatives numerically. - Python, whatever produced
A:scipy.io.savemat("lin.mat", {"A": A}, format="4").
Two things to keep consistent between the linearization and the check: the operating point (linearize where
the requirement is stated, e.g. after initialization or at a settled time, not at whatever instant the tool defaults
to), and the number of states nx given to the check model, which must be the size of the file's
A. Tools may choose different states for the same model, but the eigenvalues of A do not
depend on that choice.
Step 2: a check model
model CheckPlantEigenvalues
parameter String file = Modelica.Utilities.Files.loadResource("modelica://MyLib/Resources/lin.mat");
parameter Integer nx = 4;
parameter Real A[nx, nx](each fixed=false);
inner Requirements.Verify.PrintViolations printViolations(evaluationTime=1);
Requirements.LinearAnalysis.EigenvalueCheck damping(nx=nx, A=A,
metric=Requirements.Types.EigenMetric.Damping, bound=0.3);
Requirements.Verify.Requirement R1(text="Every mode shall be damped at least 0.3",
property=damping.y);
initial equation
A = Requirements.LinearAnalysis.readStateMatrix(file, nx);
annotation(experiment(StopTime=1));
end CheckPlantEigenvalues;
Examples.Elementary.LinearAnalysis.SecondOrder is a complete example on a shipped file.
A mode table instead of a state matrix
A finite-element modal run or an experimental modal analysis gives the modes themselves: per mode a frequency, often a damping ratio, and the effective-mass fractions. Read them with readModeColumn and check them with ModeTableCheck and ModesWithinRegion, with no state matrix. These blocks give the same margins as the state-matrix blocks on the same modes, and can also select the modes by effective mass. Examples.Elementary.LinearAnalysis.ModeTable is a complete example.
Not covered
The frequency-response family of linear requirements (gain and phase margin, bandwidth, resonance peak, dc and envelope gain, sensitivity peak, delay margin) has no blocks here, by decision: it needs the complex evaluation of the transfer function over a frequency grid and a crossover search, which no MSL function provides. Evaluate those on the linearization outside Modelica.
Copyright © 2026 Model Based Innovation LLC. All rights reserved.
Contents
| Name | Kind | Description | |
|---|---|---|---|
| readStateMatrix | impure function | The A matrix of a linearization from a MATLAB v4 file | |
| modes | function | The modes of a state matrix: its eigenvalues with conjugate pairs folded into their Im >= 0 member, the integrator rule and the parasitic cut applied, sorted by magnitude | |
| EigenvalueCheck | block | One eigenvalue predicate over every mode of a state matrix (optionally in a frequency band): Property and margin, constant over the run | |
| EigenvaluesWithinRegion | block | Every mode of a state matrix inside a polygon of the (Re, Im) plane: Property and margin, constant over the run | |
| readModeColumn | impure function | One column of a mode table (MA-HS-CSV: mode, f, zeta, meff_x, ...) by its header name | |
| hasModeColumn | impure function | Whether a mode table has a column of this name | |
| columnIndex | function | The 1-based index of a name in a comma-separated header (quotes and blanks ignored: a name holds neither), 0 when it is not there | |
| eigenvaluesOfModes | function | The eigenvalue (Im >= 0 member of the pair) of each mode of a table: (-zeta w, w sqrt(1 - zeta^2)), w = 2 pi f | |
| stateMatrixOfModes | function | The block-diagonal state matrix of a mode table: one block [0, 1; -w^2, -2 zeta w] per mode | |
| ModeTableCheck | block | One eigenvalue predicate over every mode of a mode table (optionally in a frequency band, optionally above an effective-mass fraction): Property and margin, constant over the run | |
| ModesWithinRegion | block | Every mode of a mode table inside a polygon of the (Re, Im) plane: Property and margin, constant over the run | |
| propertyPerMode | function | The property of one eigenvalue predicate per mode (Undefined outside the band) | |
| marginPerMode | function | The raw margin of one eigenvalue predicate per mode (0 outside the band, -inf for a non-decaying mode against a time constant) | |
| regionMargins | function | The signed distance of every mode (and its conjugate) to a polygon, positive inside | |
| worstMargin | function | The least margin over the decided modes (-inf where a violated mode has none, 0 when no mode is decided) |