Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 3e8df38

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
[NF] Treat vectorized connectors with flow variables
- split array connectors into variables and keep dimensions - enhanced generation of for equations - add unconnected flow variables after connections to sets to get the right dimensions of connections Belonging to [master]: - #2768 - OpenModelica/OpenModelica-testsuite#1070
1 parent 023c904 commit 3e8df38

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

Compiler/NFFrontEnd/NFConnectionSets.mo

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,19 @@ package ConnectionSets
7171
listLength(connections.connections) + listLength(connections.flows));
7272

7373
// Add flow variable to the sets, unless disabled by flag.
74-
if not Flags.isSet(Flags.DISABLE_SINGLE_FLOW_EQ) then
74+
// Do this here if NF_SCALARIZE to use fast addList for scalarized flows.
75+
if not Flags.isSet(Flags.DISABLE_SINGLE_FLOW_EQ) and Flags.isSet(Flags.NF_SCALARIZE) then
7576
sets := List.fold(connections.flows, addConnector, sets);
7677
end if;
7778

7879
// Add the connections.
7980
sets := List.fold1(connections.connections, addConnection, connections.broken, sets);
81+
82+
// Add remaining flow variables to the sets, unless disabled by flag.
83+
// Do this after addConnection if not NF_SCALARIZE to get array dims right.
84+
if not Flags.isSet(Flags.DISABLE_SINGLE_FLOW_EQ) and not Flags.isSet(Flags.NF_SCALARIZE) then
85+
sets := List.fold(connections.flows, addSingleConnector, sets);
86+
end if;
8087
end fromConnections;
8188

8289
function addScalarConnector
@@ -94,6 +101,16 @@ package ConnectionSets
94101
sets := addList(Connector.split(conn), sets);
95102
end addConnector;
96103

104+
function addSingleConnector
105+
"Adds a connector to the sets if it does not already exist"
106+
input Connector conn;
107+
input output ConnectionSets.Sets sets;
108+
algorithm
109+
for c in Connector.split(conn) loop
110+
sets := find(c, sets);
111+
end for;
112+
end addSingleConnector;
113+
97114
function addConnection
98115
"Adds a connection to the sets, which means merging the two sets that the
99116
connectors belong to, unless they already belong to the same set."

Compiler/NFFrontEnd/NFConnector.mo

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected
4848
import NFClass.Class;
4949
import Restriction = NFRestriction;
5050
import ComplexType = NFComplexType;
51+
import Dimension = NFDimension;
5152

5253
public
5354
type Face = enumeration(INSIDE, OUTSIDE);
@@ -205,6 +206,7 @@ protected
205206
input DAE.ElementSource source;
206207
input ConnectorType cty;
207208
input output list<Connector> conns = {};
209+
input list<Dimension> dims = {} "accumulated dimensions if not NF_SCALARIZE";
208210
algorithm
209211
conns := match ty
210212
local
@@ -214,36 +216,37 @@ protected
214216

215217
case Type.COMPLEX(complexTy = ct as ComplexType.CONNECTOR())
216218
algorithm
217-
conns := splitImpl2(name, face, source, ct.potentials, conns);
218-
conns := splitImpl2(name, face, source, ct.flows, conns);
219-
conns := splitImpl2(name, face, source, ct.streams, conns);
219+
conns := splitImpl2(name, face, source, ct.potentials, conns, dims);
220+
conns := splitImpl2(name, face, source, ct.flows, conns, dims);
221+
conns := splitImpl2(name, face, source, ct.streams, conns, dims);
220222
then
221223
conns;
222224

223225
case Type.COMPLEX()
224226
algorithm
225227
tree := Class.classTree(InstNode.getClass(ty.cls));
226228
conns := splitImpl2(name, face, source,
227-
arrayList(ClassTree.getComponents(tree)), conns);
229+
arrayList(ClassTree.getComponents(tree)), conns, dims);
228230
then
229231
conns;
230232

231233
case Type.ARRAY()
232234
algorithm
235+
t := Type.arrayElementType(ty);
233236
if Flags.isSet(Flags.NF_SCALARIZE) then
234-
t := Type.arrayElementType(ty);
235237
for c in ComponentRef.scalarize(name) loop
236-
conns := splitImpl(c, t, face, source, cty, conns);
238+
conns := splitImpl(c, t, face, source, cty, conns, dims);
237239
end for;
238240
else
239241
if not Type.isEmptyArray(ty) then
240-
conns := CONNECTOR(name, ty, face, cty, source) :: conns;
242+
conns := splitImpl(name, t, face, source, cty, conns,
243+
listAppend(dims, ty.dimensions));
241244
end if;
242245
end if;
243246
then
244247
conns;
245248

246-
else CONNECTOR(name, ty, face, cty, source) :: conns;
249+
else CONNECTOR(name, Type.liftArrayLeftList(ty, dims), face, cty, source) :: conns;
247250
end match;
248251
end splitImpl;
249252

@@ -253,6 +256,7 @@ protected
253256
input DAE.ElementSource source;
254257
input list<InstNode> comps;
255258
input output list<Connector> conns;
259+
input list<Dimension> dims;
256260
protected
257261
Component c;
258262
ComponentRef cref;
@@ -264,7 +268,7 @@ protected
264268
ty := Component.getType(c);
265269
cty := Component.connectorType(c);
266270
cref := ComponentRef.append(ComponentRef.fromNode(comp, ty), name);
267-
conns := splitImpl(cref, ty, face, source, cty, conns);
271+
conns := splitImpl(cref, ty, face, source, cty, conns, dims);
268272
end for;
269273
end splitImpl2;
270274

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,14 +694,18 @@ function addIterator_traverse
694694
input output Expression exp;
695695
input ComponentRef prefix;
696696
input Subscript subscript;
697+
protected
698+
String restString, prefixString = ComponentRef.toString(prefix);
699+
Integer prefixLength = stringLength(prefixString);
697700
algorithm
698701
exp := match exp
699702
local
700703
ComponentRef restCref;
701704
case Expression.CREF(cref = ComponentRef.CREF(restCref = restCref))
702705
algorithm
703-
if ComponentRef.isEqual(restCref, prefix) then
704-
exp.cref := ComponentRef.addSubscript(subscript, exp.cref);
706+
restString := ComponentRef.toString(restCref);
707+
if prefixLength <= stringLength(restString) and prefixString == substring(restString, 1, prefixLength) then
708+
exp.cref := ComponentRef.setSubscripts(subscript :: ComponentRef.getSubscripts(exp.cref), exp.cref);
705709
end if;
706710
then
707711
exp;

0 commit comments

Comments
 (0)