Load, analyze, and plot the result of linearizing a Modelica model.
This module contains one class: LinRes. It relies on python-control, which is included in the distribution.
Bases: object
Class for Modelica-based linearization results and methods to analyze those results
This class contains two user-accessible methods:
On initialization, load and preprocess a linearized Modelica model (MATLAB® format).
The model is in state space:
der(x) = A*x + B*u;
y = C*x + D*u;
The linear system is stored as sys within this class. It is an instance of control.StateSpace, which emulates the structure of a continuous-time model in MATLAB® (e.g., the output of ss() in MATLAB®). It contains:
- A, B, C, D: Matrices of the linear system
- stateName: List of name(s) of the states (x)
- inputName: List of name(s) of the inputs (u)
- outputName: List of name(s) of the outputs (y)
Arguments:
fname: Name of the file (may include the path)
The file extension (‘.mat’) is optional. The file must contain four matrices: Aclass (specifies the class name, which must be “AlinearSystem”), nx, xuyName, and ABCD.
Example:
>>> from modelicares import LinRes
>>> lin = LinRes('examples/PID')
Return a formal description of the LinRes instance.
Example:
>>> from modelicares import LinRes
>>> lin = LinRes('examples/PID.mat')
>>> lin
LinRes('...PID.mat')
Return an informal description of the LinRes instance.
Example:
>>> from modelicares import LinRes
>>> lin = LinRes('examples/PID.mat')
>>> print(lin)
Modelica linearization results from "...PID.mat"
Create a Bode plot of the system’s response.
The Bode plots of a MIMO system are overlayed. This is different than MATLAB®, which creates an array of subplots.
Arguments:
axes: Tuple (pair) of axes for the magnitude and phase plots
If axes is not provided, then axes will be created in a new figure.
pairs: List of (input index, output index) tuples of each transfer function to be evaluated
If not provided, all of the transfer functions will be plotted.
label: Label for the figure (ignored if axes is provided)
This will be used as the base filename if the figure is saved.
title: Title for the figure
If title is None (default), then the title will be “Bode Plot of fbase”, where fbase is the base filename of the data. Use ‘’ for no title.
colors: Color or list of colors that will be used sequentially
Each may be a character, grayscale, or rgb value.
styles: Line/dash style or list of line/dash styles that will be used sequentially
Each style is a string representing a linestyle (e.g., “–”) or a tuple of on/off lengths representing dashes. Use “” for no line and “-” for a solid line.
**kwargs: Additional arguments for control.freqplot.bode()
Returns:
Example:
>>> from modelicares import LinRes, save
>>> from numpy import pi, logspace
>>> lin = LinRes('examples/PID.mat')
>>> lin.bode(label='examples/PID-bode', omega=2*pi*logspace(-2, 3),
... title="Bode Plot of Modelica.Blocks.Continuous.PID")
(<matplotlib.axes...AxesSubplot object at 0x...>, <matplotlib.axes...AxesSubplot object at 0x...>)
>>> save()
Saved examples/PID-bode.pdf
Saved examples/PID-bode.png
Create a Nyquist plot of the system’s response.
The Nyquist plots of a MIMO system are overlayed. This is different than MATLAB®, which creates an array of subplots.
Arguments:
ax: Axes onto which the Nyquist diagram should be plotted
If ax is not provided, then axes will be created in a new figure.
pairs: List of (input index, output index) tuples of each transfer function to be evaluated
If not provided, all of the transfer functions will be plotted.
label: Label for the figure (ignored if ax is provided)
This will be used as the base filename if the figure is saved.
title: Title for the figure
If title is None (default), then the title will be “Nyquist Plot of fbase”, where fbase is the base filename of the data. Use ‘’ for no title.
xlabel: x-axis label
ylabel: y-axis label
colors: Color or list of colors that will be used sequentially
Each may be a character, grayscale, or rgb value.
**kwargs: Additional arguments for control.freqplot.nyquist()
Returns:
Example:
>>> from modelicares import LinRes, save
>>> from numpy import pi, logspace
>>> lin = LinRes('examples/PID.mat')
>>> lin.nyquist(label='examples/PID-nyquist',
... omega=2*pi*logspace(0, 3, 61), labelFreq=20,
... title="Nyquist Plot of Modelica.Blocks.Continuous.PID")
<matplotlib.axes...AxesSubplot object at 0x...>
>>> save()
Saved examples/PID-nyquist.pdf
Saved examples/PID-nyquist.png