Skip to content

Commit

Permalink
Return empty matrices when system has no states
Browse files Browse the repository at this point in the history
  • Loading branch information
tobolar committed Oct 23, 2024
1 parent 59a60bd commit fad99a9
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Modelica_LinearSystems2/StateSpace.mo
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,12 @@ ss;
// Modelica_LinearSystems2.StateSpace.Analysis.analysis(Modelica_LinearSystems2.StateSpace(A=[2, 1.43, 12, 3; 1, 1, 1, 43; 1, 3, 2, 2; 1, 1, 4.2, 1.2], B=[1, 2; 2.2, 3; 3, 1; 4, 0], C=[25, 1.4, 6.3, 1; 0.3, 8, 5, 1; 1, 3, 2, 2], D=[6, 4; 4, 2; 6, 5], yNames={"y1_test","y2_te","y3_"}, xNames={"xx1","x2","xxx3","xx4"}, uNames={"u1_test","u2_test"}));
// ---------------------------------------------------------------------------------------------------

if nx < 1 then
filePath := "";
print("The system has no continuous states. No analysis performed.");
break;
end if;

filePath := Modelica.Utilities.Files.fullPathName(fileName);
(filePathOnly,fileNameOnly,fileExtOnly) :=
Modelica.Utilities.Files.splitPathName(filePath);
Expand Down Expand Up @@ -13154,15 +13160,8 @@ k = ---------- * ----------------------
Integer nx = xuy[1];
Integer nu = xuy[2];
Integer ny = xuy[3];
Real ABCD[nx + ny, nx + nu]=Modelica.Utilities.Streams.readRealMatrix(
fileName2,
"ABCD",
nx + ny,
nx + nu);
String xuyName[nx + nu + ny]=DymolaCommands.MatrixIO.readStringMatrix(
fileName2,
"xuyName",
nx + nu + ny);
Real ABCD[nx + ny, nx + nu];
String xuyName[nx + nu + ny];
public
output StateSpace result(
redeclare Real A[nx, nx],
Expand All @@ -13171,13 +13170,17 @@ k = ---------- * ----------------------
redeclare Real D[ny, nu]) "Outputs model linearized at initial point";

algorithm
result.A := ABCD[1:nx, 1:nx];
result.B := ABCD[1:nx, nx + 1:nx + nu];
result.C := ABCD[nx + 1:nx + ny, 1:nx];
result.D := ABCD[nx + 1:nx + ny, nx + 1:nx + nu];
result.uNames := xuyName[nx + 1:nx + nu];
result.yNames := xuyName[nx + nu + 1:nx + nu + ny];
result.xNames := xuyName[1:nx];
if nx > 0 then
ABCD := Modelica.Utilities.Streams.readRealMatrix(fileName2, "ABCD", nx+ny, nx+nu);
xuyName := DymolaCommands.MatrixIO.readStringMatrix(fileName2, "xuyName", nx+nu+ny);
result.A := ABCD[1:nx, 1:nx];
result.B := ABCD[1:nx, nx+1:nx+nu];
result.C := ABCD[nx+1:nx+ny, 1:nx];
result.D := ABCD[nx+1:nx+ny, nx+1:nx+nu];
result.uNames := xuyName[nx+1:nx+nu];
result.yNames := xuyName[nx+nu+1:nx+nu+ny];
result.xNames := xuyName[1:nx];
end if;

annotation (__Dymola_interactive=true, Documentation(info="<html>
<h4>Syntax</h4>
Expand Down

0 comments on commit fad99a9

Please sign in to comment.