Skip to content

Commit

Permalink
Improve usage of imports and delete unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tobolar committed Mar 21, 2024
1 parent 440c55f commit 8ce9333
Show file tree
Hide file tree
Showing 31 changed files with 251 additions and 421 deletions.
11 changes: 5 additions & 6 deletions Modelica_LinearSystems2/Controller/TransferFunction.mo
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
within Modelica_LinearSystems2.Controller;
block TransferFunction
"Continuous or discrete, single input single output transfer function"
import Modelica_LinearSystems2.TransferFunction;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.Controller.Types.Init;

extends Modelica_LinearSystems2.Controller.Interfaces.PartialSISO2(
discretePart(
x_start=x_start,
y_start={y_start},
ABCD=TransferFunction.Conversion.toMatrices(system)));
ABCD=Modelica_LinearSystems2.TransferFunction.Conversion.toMatrices(system)));

parameter Modelica_LinearSystems2.TransferFunction system "Transfer function";
parameter Real x_start[nx]=zeros(nx) "Initial or guess values of states"
Expand Down Expand Up @@ -46,11 +45,11 @@ equation
connect(x, discretePart.x);
initial equation
if continuous and nx>0 then
if init ==Modelica_LinearSystems2.Controller.Types.Init.SteadyState then
if init == Init.SteadyState then
der(x_scaled) = zeros(nx);
elseif init ==Modelica_LinearSystems2.Controller.Types.Init.InitialState then
elseif init == Init.InitialState then
x_scaled = x_start*a_end;
elseif init ==Modelica_LinearSystems2.Controller.Types.Init.InitialOutput then
elseif init == Init.InitialOutput then
y = y_start;
// der(x_scaled[1:nx-1]) = zeros(nx -1);
der(x_scaled[1:nx-(if nx>1 then 2 else 1)]) = zeros(nx -( if nx>1 then 2 else 1));
Expand Down
7 changes: 3 additions & 4 deletions Modelica_LinearSystems2/Controller/ZerosAndPoles.mo
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
within Modelica_LinearSystems2.Controller;
block ZerosAndPoles
"Continuous or discretized, single input single output block described by a ZerosAndPoles object"
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.ZerosAndPoles;
import Modelica_LinearSystems2.Controller.Internal;

extends Modelica_LinearSystems2.Controller.Interfaces.PartialSISO2(
discretePart(
x_start=x_start,
y_start={y_start},
ABCD=ZerosAndPoles.Conversion.toMatrices(system)));
parameter ZerosAndPoles system "Data defining the ZerosAndPoles object";
ABCD=Modelica_LinearSystems2.ZerosAndPoles.Conversion.toMatrices(system)));

parameter Modelica_LinearSystems2.ZerosAndPoles system "Data defining the ZerosAndPoles object";
final parameter Integer nx=size(system.d1,1) + 2*size(system.d2,1)
"Number of states";
parameter Real x_start[nx] = zeros(nx) "Initial or guess values of states"
Expand Down
38 changes: 14 additions & 24 deletions Modelica_LinearSystems2/DiscreteStateSpace.mo
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public
input Modelica_LinearSystems2.StateSpace ss
"Continuous linear state space system";
input Modelica.Units.SI.Time Ts "Sample time";
input Modelica_LinearSystems2.Utilities.Types.Method method=Modelica_LinearSystems2.Utilities.Types.Method.Trapezoidal "Discretization method";
input Method method = Method.Trapezoidal "Discretization method";
output Modelica_LinearSystems2.DiscreteStateSpace dss(
redeclare Real A[size(ss.A, 1),size(ss.A, 2)],
redeclare Real B[size(ss.B, 1),size(ss.B, 2)],
Expand Down Expand Up @@ -409,7 +409,7 @@ public
input Real C[:,size(A, 1)] "Matrix C of continuous state space system" annotation(Dialog(group="der(x) = A*x + B*u; y = C*x + D*u"));
input Real D[size(C, 1),size(B, 2)] "Matrix D of continuous state space system" annotation(Dialog(group="der(x) = A*x + B*u; y = C*x + D*u"));
input Modelica.Units.SI.Time Ts "Sample time";
input Modelica_LinearSystems2.Utilities.Types.Method method=Modelica_LinearSystems2.Utilities.Types.Method.Trapezoidal "Discretization method";
input Method method = Method.Trapezoidal "Discretization method";
// input Modelica_LinearSystems2.Types method=Modelica_LinearSystems2.Types.Method.Trapezoidal
output Modelica_LinearSystems2.DiscreteStateSpace dss(
redeclare Real A[size(A, 1),size(A, 2)],
Expand Down Expand Up @@ -1302,7 +1302,6 @@ The eigenvalues <strong>ev</strong>_d of the discrete system are related to the
encapsulated function timeResponse
"Calculate the time response of a discrete state space system"

import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteStateSpace;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;
Expand Down Expand Up @@ -1358,7 +1357,7 @@ The eigenvalues <strong>ev</strong>_d of the discrete system are related to the

if response == TimeResponse.Initial then
(y[:, :, 1],x_discrete[:, :, 1]) :=
Modelica_LinearSystems2.DiscreteStateSpace.Internal.initialResponse1(
DiscreteStateSpace.Internal.initialResponse1(
dss,
x0,
samples);
Expand Down Expand Up @@ -2416,7 +2415,6 @@ vector <strong>u</strong> to the iy'th element of the output vector <strong>y</s
encapsulated function timeResponse
"Plot the time response of a discrete state space system. The response type is selectable"

import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteStateSpace;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;
Expand Down Expand Up @@ -2457,7 +2455,7 @@ vector <strong>u</strong> to the iy'th element of the output vector <strong>y</s
Integer loops=if response == TimeResponse.Initial then 1 else size(dss.B,2);

algorithm
(y,t,x) := Modelica_LinearSystems2.DiscreteStateSpace.Analysis.timeResponse(
(y,t,x) := DiscreteStateSpace.Analysis.timeResponse(
dss=dss,
tSpan=tSpan,
response=response,
Expand Down Expand Up @@ -2566,11 +2564,9 @@ This function plots the time response of a discrete state space system. The char
encapsulated function impulse
"Impulse response plot of a discrete state space system"

import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteStateSpace;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;
import Modelica_LinearSystems2.Utilities.Plot;

input DiscreteStateSpace dss;
input Real tSpan=0 "Simulation time span [s]";
Expand All @@ -2585,7 +2581,7 @@ This function plots the time response of a discrete state space system. The char
heading="Impulse response"));

protected
Modelica_LinearSystems2.Utilities.Types.TimeResponse response=Modelica_LinearSystems2.Utilities.Types.TimeResponse.Impulse
TimeResponse response = TimeResponse.Impulse
"Type of time response";
Real tSpanVar;

Expand All @@ -2597,7 +2593,7 @@ This function plots the time response of a discrete state space system. The char
tSpanVar := tSpan;
end if;

Modelica_LinearSystems2.DiscreteStateSpace.Plot.timeResponse(
DiscreteStateSpace.Plot.timeResponse(
dss=dss,
tSpan=tSpanVar,
response=response,
Expand Down Expand Up @@ -2651,11 +2647,9 @@ This function plots the impulse responses of a state space system for each syste
encapsulated function step
"Step response plot of a discrete state space system"

import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteStateSpace;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;
import Modelica_LinearSystems2.Utilities.Plot;

input DiscreteStateSpace dss;
input Real tSpan=0 "Simulation time span [s]";
Expand All @@ -2668,7 +2662,7 @@ This function plots the impulse responses of a state space system for each syste
heading="Step response"));

protected
Modelica_LinearSystems2.Utilities.Types.TimeResponse response=Modelica_LinearSystems2.Utilities.Types.TimeResponse.Step
TimeResponse response = TimeResponse.Step
"Type of time response";

Real x0[size(dss.A, 1)]=zeros(size(dss.A, 1)) "Initial state vector";
Expand All @@ -2683,7 +2677,7 @@ This function plots the impulse responses of a state space system for each syste
tSpanVar := tSpan;
end if;

Modelica_LinearSystems2.DiscreteStateSpace.Plot.timeResponse(
DiscreteStateSpace.Plot.timeResponse(
dss=dss,
tSpan=tSpanVar,
response=response,
Expand Down Expand Up @@ -2737,11 +2731,9 @@ This function plots the discrete step responses of a state space system for each
encapsulated function ramp
"Ramp response plot of a discrete state space system"

import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteStateSpace;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;
import Modelica_LinearSystems2.Utilities.Plot;

input DiscreteStateSpace dss;
input Real tSpan=0 "Simulation time span [s]";
Expand All @@ -2754,7 +2746,7 @@ This function plots the discrete step responses of a state space system for each
defaultDiagram=Modelica_LinearSystems2.Internal.DefaultDiagramTimeResponse(
heading="Ramp response"));
protected
Modelica_LinearSystems2.Utilities.Types.TimeResponse response=Modelica_LinearSystems2.Utilities.Types.TimeResponse.Ramp "type of time response";
TimeResponse response = TimeResponse.Ramp "type of time response";

Real x0[size(dss.A, 1)]=zeros(size(dss.A, 1)) "Initial state vector";

Expand Down Expand Up @@ -2817,13 +2809,10 @@ This function plots the ramp responses of a discrete state space system for each

encapsulated function initialResponse
"Initial condition response plot of a discrete state space system"
import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteStateSpace;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;

import Modelica_LinearSystems2.Utilities.Plot;

input DiscreteStateSpace dss;
input Real tSpan=0 "Simulation time span [s]";
input Real x0[size(dss.A, 1)]=zeros(size(dss.A, 1)) "Initial state vector";
Expand All @@ -2832,10 +2821,11 @@ This function plots the ramp responses of a discrete state space system for each
"True, if all subsystem time responses are plotted in one window with subplots"
annotation(choices(checkBox=true));

extends Modelica_LinearSystems2.Internal.PartialPlotFunctionMIMO(defaultDiagram=Modelica_LinearSystems2.Internal.DefaultDiagramTimeResponse(
heading="Initial response"));
extends Modelica_LinearSystems2.Internal.PartialPlotFunctionMIMO(
defaultDiagram=Modelica_LinearSystems2.Internal.DefaultDiagramTimeResponse(
heading="Initial response"));
protected
Modelica_LinearSystems2.Utilities.Types.TimeResponse response=Modelica_LinearSystems2.Utilities.Types.TimeResponse.Initial "type of time response";
TimeResponse response = TimeResponse.Initial "type of time response";

Real tSpanVar;

Expand All @@ -2846,7 +2836,7 @@ This function plots the ramp responses of a discrete state space system for each
else
tSpanVar := tSpan;
end if;
Modelica_LinearSystems2.DiscreteStateSpace.Plot.timeResponse(
DiscreteStateSpace.Plot.timeResponse(
dss=dss,
tSpan=tSpanVar,
response=response,
Expand Down
36 changes: 12 additions & 24 deletions Modelica_LinearSystems2/DiscreteTransferFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ operator record DiscreteTransferFunction

encapsulated function z "Generate the discrete transfer function z"
import Modelica;
import Modelica_LinearSystems2.Math.Polynomial;
import Modelica_LinearSystems2.DiscreteTransferFunction;
input Modelica.Units.SI.Time Ts=0;
output DiscreteTransferFunction dtf(n={1,0}, d={1},Ts=Ts) "z";
Expand Down Expand Up @@ -430,14 +429,13 @@ DiscreteTransferFunction dtf = z/(3*z^2 + 2*z +2)
encapsulated function timeResponse
"Calculate the time response of a discrete transfer function"

import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteStateSpace;
import Modelica_LinearSystems2.DiscreteTransferFunction;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;

extends Modelica_LinearSystems2.Internal.timeResponseMask_tf_discrete;// Input/Output declarations of discrete time response functions
input Modelica_LinearSystems2.Utilities.Types.TimeResponse response=Modelica_LinearSystems2.Utilities.Types.TimeResponse.Step;
input TimeResponse response = TimeResponse.Step;
input Real x0[DiscreteTransferFunction.Analysis.denominatorDegree(dtf)]=zeros(DiscreteTransferFunction.Analysis.denominatorDegree(dtf))
"Initial state vector";

Expand Down Expand Up @@ -774,8 +772,6 @@ The outputs y and x of the discrete state space systrem are calculated for each

encapsulated function denominatorDegree
"Return denominator degree of a discrete transfer function"
import Modelica;
import Modelica_LinearSystems2.Math.Polynomial;
import Modelica_LinearSystems2.DiscreteTransferFunction;

input DiscreteTransferFunction dtf
Expand Down Expand Up @@ -967,18 +963,17 @@ Function Analysis.<strong>denominatorDegree</strong> calculates the degree of th
encapsulated function timeResponse
"Plot the time response of a system represented by a discrete transfer function. The response type is selectable"
import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteTransferFunction;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;
import Modelica_LinearSystems2.Utilities.Plot;
input Modelica_LinearSystems2.DiscreteTransferFunction dtf;
// input Real dt=0 "Sample time [s]";
input Real tSpan=0 "Simulation time span [s]";
input Modelica_LinearSystems2.Utilities.Types.TimeResponse response=Modelica_LinearSystems2.Utilities.Types.TimeResponse.Step "Type of time response";
input TimeResponse response = TimeResponse.Step "Type of time response";
input Real x0[DiscreteTransferFunction.Analysis.denominatorDegree(dtf)]=zeros(
DiscreteTransferFunction.Analysis.denominatorDegree(dtf))
"Initial state vector";
Expand Down Expand Up @@ -1030,10 +1025,9 @@ Function Analysis.<strong>denominatorDegree</strong> calculates the degree of th
encapsulated function impulse
"Impulse response plot of a discrete transfer function"
import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteTransferFunction;
import Modelica_LinearSystems2.Utilities.Plot;
input DiscreteTransferFunction dtf "zeros-and-poles transfer function";
input Real tSpan=0 "Simulation time span [s]";
Expand All @@ -1050,7 +1044,7 @@ Function Analysis.<strong>denominatorDegree</strong> calculates the degree of th
"Initial state vector";
algorithm
// set sample time
Modelica_LinearSystems2.DiscreteTransferFunction.Plot.timeResponse(
DiscreteTransferFunction.Plot.timeResponse(
dtf=dtf,
tSpan=tSpan,
response=response,
Expand All @@ -1064,11 +1058,10 @@ Function Analysis.<strong>denominatorDegree</strong> calculates the degree of th
encapsulated function step
"Step response plot of a discrete transfer function"
import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.DiscreteTransferFunction;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;
import Modelica_LinearSystems2.Utilities.Plot;
input DiscreteTransferFunction dtf;
input Real tSpan=0 "Simulation time span [s]";
Expand All @@ -1078,7 +1071,7 @@ Function Analysis.<strong>denominatorDegree</strong> calculates the degree of th
heading="Step response of dtf = " + String(dtf)));
protected
Modelica_LinearSystems2.Utilities.Types.TimeResponse response=Modelica_LinearSystems2.Utilities.Types.TimeResponse.Step "type of time response";
TimeResponse response = TimeResponse.Step "type of time response";
Real x0[DiscreteTransferFunction.Analysis.denominatorDegree(dtf)]=zeros(
DiscreteTransferFunction.Analysis.denominatorDegree(dtf))
"Initial state vector";
Expand All @@ -1103,8 +1096,6 @@ Function Analysis.<strong>denominatorDegree</strong> calculates the degree of th
import Modelica_LinearSystems2.DiscreteTransferFunction;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;
import Modelica_LinearSystems2.Utilities.Plot;
input DiscreteTransferFunction dtf;
input Real tSpan=0 "Simulation time span [s]";
Expand All @@ -1113,12 +1104,12 @@ Function Analysis.<strong>denominatorDegree</strong> calculates the degree of th
heading="Ramp response of dtf = " + String(dtf)));
protected
Modelica_LinearSystems2.Utilities.Types.TimeResponse response=Modelica_LinearSystems2.Utilities.Types.TimeResponse.Ramp "type of time response";
TimeResponse response = TimeResponse.Ramp "type of time response";
Real x0[DiscreteTransferFunction.Analysis.denominatorDegree(dtf)]=zeros(
DiscreteTransferFunction.Analysis.denominatorDegree(dtf))
"Initial state vector";
algorithm
Modelica_LinearSystems2.DiscreteTransferFunction.Plot.timeResponse(
DiscreteTransferFunction.Plot.timeResponse(
dtf=dtf,
tSpan=tSpan,
response=response,
Expand All @@ -1137,12 +1128,10 @@ Function Analysis.<strong>denominatorDegree</strong> calculates the degree of th
import Modelica_LinearSystems2.DiscreteTransferFunction;
import Modelica_LinearSystems2.Utilities.Types.TimeResponse;
import Modelica_LinearSystems2.Utilities.Plot;
input Modelica_LinearSystems2.DiscreteTransferFunction dtf;
input DiscreteTransferFunction dtf;
input Real tSpan=0 "Simulation time span [s]";
input Modelica_LinearSystems2.Utilities.Types.TimeResponse response=Modelica_LinearSystems2.Utilities.Types.TimeResponse.Initial "type of time response";
input TimeResponse response = TimeResponse.Initial "type of time response";
input Real y0 "Initial output (for initial condition plot)";
extends Modelica_LinearSystems2.Internal.PartialPlotFunction(
Expand All @@ -1158,7 +1147,7 @@ Function Analysis.<strong>denominatorDegree</strong> calculates the degree of th
dss.C,
vector(y0)) "Initial state vector (for initial condition plot)";
algorithm
Modelica_LinearSystems2.DiscreteTransferFunction.Plot.timeResponse(
DiscreteTransferFunction.Plot.timeResponse(
dtf=dtf,
tSpan=tSpan,
response=response,
Expand Down Expand Up @@ -1356,7 +1345,6 @@ with

import Modelica.Utilities.Streams;
import Modelica_LinearSystems2.DiscreteTransferFunction;
import Modelica_LinearSystems2.Math.Polynomial;

input String fileName="dtf.mat" "Name of the transfer function data file" annotation(Dialog(loadSelector(filter="MAT files (*.mat);; All files (*.*)",
caption="transfer function data file")));
Expand Down
Loading

0 comments on commit 8ce9333

Please sign in to comment.