Skip to content

Commit

Permalink
Dump connections in for-loops for getModelInstance (#11491)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Nov 2, 2023
1 parent f0d7b74 commit 437041e
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
6 changes: 6 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -3082,6 +3082,12 @@ algorithm
guard name == "transition" or name == "initialState"
then eq :: outEql;

case SCode.Equation.EQ_FOR()
algorithm
eq.eEquationLst := filterInstanceAPIEquations(eq.eEquationLst);
then
if listEmpty(eq.eEquationLst) then outEql else eq :: outEql;

case SCode.Equation.EQ_IF()
algorithm
eq.thenBranch := list(filterInstanceAPIEquations(eql) for eql in eq.thenBranch);
Expand Down
7 changes: 7 additions & 0 deletions OMCompiler/Compiler/Script/NFApi.mo
Expand Up @@ -1951,6 +1951,13 @@ algorithm
then
();

case Equation.FOR()
algorithm
(connections, transitions, initialStates) :=
sortEquations(eq.body, connections, transitions, initialStates);
then
();

case Equation.IF()
algorithm
for b in eq.branches loop
Expand Down
169 changes: 169 additions & 0 deletions testsuite/openmodelica/instance-API/GetModelInstanceConnection5.mos
@@ -0,0 +1,169 @@
// name: GetModelInstanceConnection4
// keywords:
// status: correct
// cflags: -d=newInst
//
//

loadString("
model M
connector C
Real e;
flow Real f;
end C;

parameter Integer N = 3;
C c1[N], c2[N];
equation
for i loop
connect(c1[i], c2[i]);
end for;
end M;
");

getModelInstance(M, prettyPrint = true);

// Result:
// true
// "{
// \"name\": \"M\",
// \"restriction\": \"model\",
// \"elements\": [
// {
// \"$kind\": \"component\",
// \"name\": \"N\",
// \"type\": \"Integer\",
// \"modifiers\": \"3\",
// \"value\": {
// \"binding\": 3
// },
// \"prefixes\": {
// \"variability\": \"parameter\"
// }
// },
// {
// \"$kind\": \"component\",
// \"name\": \"c1\",
// \"type\": {
// \"name\": \"C\",
// \"restriction\": \"connector\",
// \"elements\": [
// {
// \"$kind\": \"component\",
// \"name\": \"e\",
// \"type\": \"Real\"
// },
// {
// \"$kind\": \"component\",
// \"name\": \"f\",
// \"type\": \"Real\",
// \"prefixes\": {
// \"connector\": \"flow\"
// }
// }
// ],
// \"source\": {
// \"filename\": \"<interactive>\",
// \"lineStart\": 3,
// \"columnStart\": 3,
// \"lineEnd\": 6,
// \"columnEnd\": 8
// }
// },
// \"dims\": {
// \"absyn\": [
// \"N\"
// ],
// \"typed\": [
// \"3\"
// ]
// }
// },
// {
// \"$kind\": \"component\",
// \"name\": \"c2\",
// \"type\": {
// \"name\": \"C\",
// \"restriction\": \"connector\",
// \"elements\": [
// {
// \"$kind\": \"component\",
// \"name\": \"e\",
// \"type\": \"Real\"
// },
// {
// \"$kind\": \"component\",
// \"name\": \"f\",
// \"type\": \"Real\",
// \"prefixes\": {
// \"connector\": \"flow\"
// }
// }
// ],
// \"source\": {
// \"filename\": \"<interactive>\",
// \"lineStart\": 3,
// \"columnStart\": 3,
// \"lineEnd\": 6,
// \"columnEnd\": 8
// }
// },
// \"dims\": {
// \"absyn\": [
// \"N\"
// ],
// \"typed\": [
// \"3\"
// ]
// }
// }
// ],
// \"connections\": [
// {
// \"lhs\": {
// \"$kind\": \"cref\",
// \"parts\": [
// {
// \"name\": \"c1\",
// \"subscripts\": [
// {
// \"$kind\": \"cref\",
// \"parts\": [
// {
// \"name\": \"i\"
// }
// ]
// }
// ]
// }
// ]
// },
// \"rhs\": {
// \"$kind\": \"cref\",
// \"parts\": [
// {
// \"name\": \"c2\",
// \"subscripts\": [
// {
// \"$kind\": \"cref\",
// \"parts\": [
// {
// \"name\": \"i\"
// }
// ]
// }
// ]
// }
// ]
// }
// }
// ],
// \"source\": {
// \"filename\": \"<interactive>\",
// \"lineStart\": 2,
// \"columnStart\": 1,
// \"lineEnd\": 14,
// \"columnEnd\": 6
// }
// }"
// endResult
1 change: 1 addition & 0 deletions testsuite/openmodelica/instance-API/Makefile
Expand Up @@ -30,6 +30,7 @@ GetModelInstanceConnection1.mos \
GetModelInstanceConnection2.mos \
GetModelInstanceConnection3.mos \
GetModelInstanceConnection4.mos \
GetModelInstanceConnection5.mos \
GetModelInstanceDerived1.mos \
GetModelInstanceDerived2.mos \
GetModelInstanceDerived3.mos \
Expand Down

0 comments on commit 437041e

Please sign in to comment.