Skip to content

Commit 4862560

Browse files
authored
Evaluate subscripts in actualStream/inStream (#8278)
- Evaluate the subscripts in the connector reference used as argument to actualStream/inStream, to ensure we can look up e.g. the matching stream variable for a flow correctly. We already check that the subscripts can be evaluated, with this change we also actually evaluate them as intended.
1 parent 49552c6 commit 4862560

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

OMCompiler/Compiler/NFFrontEnd/NFConnectEquations.mo

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,10 @@ protected
723723
Connector c;
724724
list<Connector> sl;
725725
Integer set;
726+
ComponentRef cr;
726727
algorithm
727-
c := Connector.CONNECTOR(cref, Type.UNKNOWN(), Face.INSIDE,
728+
cr := ComponentRef.evaluateSubscripts(cref);
729+
c := Connector.CONNECTOR(cr, Type.UNKNOWN(), Face.INSIDE,
728730
ConnectorType.STREAM, DAE.emptyElementSource);
729731

730732
try
@@ -734,7 +736,7 @@ algorithm
734736
sl := {c};
735737
end try;
736738

737-
exp := generateInStreamExp(cref, sl, sets, setsArray, variables, ctable,
739+
exp := generateInStreamExp(cr, sl, sets, setsArray, variables, ctable,
738740
Flags.getConfigReal(Flags.FLOW_THRESHOLD));
739741
end evaluateInStream;
740742

@@ -851,24 +853,26 @@ protected function evaluateActualStream
851853
output Expression exp;
852854
output ComponentRef flowCref;
853855
protected
856+
ComponentRef stream_cref;
854857
Integer flow_dir;
855858
Expression flow_exp, stream_exp, instream_exp;
856859
Operator op;
857860
algorithm
858-
flowCref := associatedFlowCref(streamCref);
861+
stream_cref := ComponentRef.evaluateSubscripts(streamCref);
862+
flowCref := associatedFlowCref(stream_cref);
859863
flow_dir := evaluateFlowDirection(flowCref, variables);
860864

861865
// Select a branch if we know the flow direction, otherwise generate the whole
862866
// if-equation.
863867
if flow_dir == 1 then
864-
exp := evaluateInStream(streamCref, sets, setsArray, variables, ctable);
868+
exp := evaluateInStream(stream_cref, sets, setsArray, variables, ctable);
865869
elseif flow_dir == -1 then
866-
exp := Expression.fromCref(streamCref);
870+
exp := Expression.fromCref(stream_cref);
867871
else
868872
// actualStream(stream_var) = if flow_var > 0 then inStream(stream_var) else stream_var);
869873
flow_exp := Expression.fromCref(flowCref);
870-
stream_exp := Expression.fromCref(streamCref);
871-
instream_exp := evaluateInStream(streamCref, sets, setsArray, variables, ctable);
874+
stream_exp := Expression.fromCref(stream_cref);
875+
instream_exp := evaluateInStream(stream_cref, sets, setsArray, variables, ctable);
872876
op := Operator.makeGreater(ComponentRef.nodeType(flowCref));
873877

874878
exp := Expression.IF(
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// name: ActualStreamVariability2
2+
// keywords: stream actualStream connector
3+
// status: correct
4+
// cflags: -d=newInst
5+
//
6+
7+
connector C
8+
Real r;
9+
flow Real f;
10+
stream Real s;
11+
end C;
12+
13+
model ActualStreamVariability2
14+
C c[2];
15+
parameter Integer n = 1;
16+
Real as = actualStream(c[n].s);
17+
end ActualStreamVariability2;
18+
19+
// Result:
20+
// class ActualStreamVariability2
21+
// Real c[1].r;
22+
// Real c[1].f;
23+
// Real c[1].s;
24+
// Real c[2].r;
25+
// Real c[2].f;
26+
// Real c[2].s;
27+
// final parameter Integer n = 1;
28+
// Real as = c[1].s;
29+
// equation
30+
// c[1].f = 0.0;
31+
// c[2].f = 0.0;
32+
// end ActualStreamVariability2;
33+
// endResult

testsuite/flattening/modelica/scodeinst/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ActualStream.mo \
66
ActualStreamNonCref1.mo \
77
ActualStreamNoStream1.mo \
88
ActualStreamVariability1.mo \
9+
ActualStreamVariability2.mo \
910
Algorithm1.mo \
1011
Algorithm2.mo \
1112
Algorithm3.mo \

0 commit comments

Comments
 (0)